@njiwa/sdk
v0.1.0
Published
Njiwa. Send a WhatsApp message with one HTTP call.
Readme
Njiwa for Node
npm install @njiwa/sdkimport { Njiwa } from '@njiwa/sdk'
const njiwa = new Njiwa('sk_live_...')
await njiwa.send('254712345678', { document: 'invoice.pdf', caption: 'Your invoice' })A local file path uploads automatically. A URL passes through. A med_ id
passes through.
await njiwa.send('0712345678', { text: 'Hello' })
await njiwa.send('254712345678', { image: 'https://example.com/photo.jpg' })
await njiwa.send('254712345678', { location: { lat: -1.29, lng: 36.82 } })
const result = await njiwa.send('254712345678', { text: 'Hi', wait: true })
console.log(result.status)Verifying a webhook in Express. Note express.raw, not express.json:
re-serialising the body changes it and the signature will not match.
app.post('/njiwa', express.raw({ type: 'application/json' }), (req, res) => {
if (!Njiwa.verifyWebhook(SECRET, req.body, req.get('X-Njiwa-Signature'))) {
return res.sendStatus(400)
}
const event = JSON.parse(req.body.toString())
res.sendStatus(200) // return fast, then do the work
})Docs at https://docs.njiwa.upeo.ai UPEO.AI. 0116888777 on WhatsApp. [email protected]
