npm package: @sendapi/node
Description: Official SendAPI Node.js SDK — SMS, Email, WhatsApp, and OTP APIs
Author: SendAPI
Latest version: 1.0.0

# @sendapi/node

Official Node.js SDK for [SendAPI](https://sendapi.co) — send SMS, Email, WhatsApp messages, and OTP verification through one API.

[![npm version](https://img.shields.io/npm/v/@sendapi/node.svg)](https://www.npmjs.com/package/@sendapi/node)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

## Installation

```bash
npm install @sendapi/node
```

## Quick Start

```javascript
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

```javascript
await client.sms.send({
  to: '+14155552671',
  content: 'Your verification code is 847291',
})
```

### Email

```javascript
await client.email.send({
  to: 'alice@example.com',
  from: 'noreply@myapp.com',
  subject: 'Welcome!',
  html: '<h1>Welcome to MyApp!</h1>',
})
```

### WhatsApp

```javascript
await client.whatsapp.send({
  session_id: 'your-session-id',
  to: '14155552671',
  type: 'text',
  text: 'Hello from SendAPI!',
})
```

### OTP Verification

```javascript
// 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

```javascript
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

```javascript
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

```javascript
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](https://sendapi.co/docs)

## License

MIT — see [LICENSE](./LICENSE)