@sendapi/node
v1.0.0
Published
Official SendAPI Node.js SDK — SMS, Email, WhatsApp, and OTP APIs
Maintainers
Readme
@sendapi/node
Official Node.js SDK for SendAPI — send SMS, Email, WhatsApp messages, and OTP verification through one API.
Installation
npm install @sendapi/nodeQuick Start
import 'dotenv/config'
import SendAPI from '@sendapi/node'
const client = new SendAPI(process.env.SENDAPI_KEY)
// Send a WhatsApp message
const message = await client.whatsapp.send({
session_id: process.env.WHATSAPP_SESSION_ID,
to: '14155552671',
type: 'text',
text: 'Hello from SendAPI! 👋',
})
console.log('Sent:', message.message_id)Features
- WhatsApp — Send text, image, document, audio and video messages
- SMS — Send single or bulk SMS worldwide
- Email — Transactional email with HTML support
- OTP Verification — Send and verify one-time passwords
- Webhooks — Built-in signature verification
- TypeScript — Full type definitions included
- Zero dependencies — Uses native
fetch(Node 18+)
Usage
SMS
await client.sms.send({
to: '+14155552671',
content: 'Your verification code is 847291',
})await client.email.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome to MyApp!</h1>',
})await client.whatsapp.send({
session_id: 'your-session-id',
to: '14155552671',
type: 'text',
text: 'Hello from SendAPI!',
})OTP Verification
// Send OTP
const verification = await client.verify.send({
to: '+14155552671',
channel: 'sms',
brand_name: 'MyApp',
})
// Check OTP
const result = await client.verify.check({
id: verification.id,
code: '847291',
})
if (result.valid) {
// Authenticated
}Webhook Signature Verification
import { verifyWebhookSignature } from '@sendapi/node'
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-sendapi-signature']
if (!verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET)) {
return res.status(401).json({ error: 'Invalid signature' })
}
const event = JSON.parse(req.body.toString())
console.log('Event:', event.event)
res.json({ received: true })
})Error Handling
import { SendAPIError } from '@sendapi/node'
try {
await client.whatsapp.send({ /* ... */ })
} catch (err) {
if (err instanceof SendAPIError) {
console.log(err.status) // 429
console.log(err.code) // "rate_limit_exceeded"
console.log(err.message) // "Too many requests"
}
}Configuration
const client = new SendAPI('your-api-key', {
baseUrl: 'https://api.sendapi.co/api/v1', // default
timeout: 30000, // request timeout in ms
})Requirements
- Node.js 18 or later (uses native
fetch)
Documentation
Full API reference at sendapi.co/docs
License
MIT — see LICENSE
