@sendable-dev/sdk
v0.1.0
Published
TypeScript SDK for Sendable.
Downloads
11
Readme
@sendable-dev/sdk
TypeScript SDK for Sendable.
Install
npm install @sendable-dev/sdkRequirements
This SDK is intended for trusted Node.js or Bun backends.
- Use the raw request body when verifying webhooks
- Media decrypt helpers require a valid WhatsApp media
urlandmediaKey webhookSecretshould be the Svixwhsec_...signing secret from Sendable
Quick Start
import { Sendable } from '@sendable-dev/sdk'
const sendable = new Sendable({
apiKey: process.env.SENDABLE_API_KEY!,
apiKeyScope: 'session',
baseUrl: process.env.SENDABLE_API_URL,
})
const message = await sendable.messages.send({
chatId: '[email protected]',
text: { content: 'Hello from Sendable' },
})Verify Webhooks
import express from 'express'
import { Sendable } from '@sendable-dev/sdk'
const sendable = new Sendable({
apiKey: process.env.SENDABLE_API_KEY!,
apiKeyScope: 'session',
webhookSecret: process.env.SENDABLE_WEBHOOK_SECRET,
})
const app = express()
app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
const payload = req.body.toString()
try {
const event = await sendable.webhooks.verifyAndParse(payload, req.headers)
console.log(event.type, event.data)
return res.sendStatus(200)
} catch {
return res.status(401).send('Invalid signature')
}
})Decrypt Media
The SDK also includes local media decrypt helpers for trusted Node/Bun backends:
import { decryptWhatsAppMedia, decryptWebhookMedia } from '@sendable-dev/sdk'decryptWhatsAppMedia(...)for direct media metadata inputdecryptWebhookMedia(...)for full Sendable webhook events orevent.data
Example from a verified webhook event:
import { decryptWebhookMedia } from '@sendable-dev/sdk'
const media = await decryptWebhookMedia(event)
await Bun.write(media.fileName, media.data)Supported media types:
imagevideoaudiodocumentsticker
Documentation
- SDK Quickstart: https://sendable.dev/docs/quickstart/nodejs/sdk
- Webhooks: https://sendable.dev/docs/webhooks
- Webhook Events: https://sendable.dev/docs/webhook-events
- API Reference: https://sendable.dev/docs/api-reference
