Skip to content

Send Messages with the TypeScript SDK

Send and manage SMS, WhatsApp, Email, and Voice messages with the Zavu TypeScript SDK.

View .md

Send a Message

TypeScript
const result = await client.messages.send({ to: "+14155551234", text: "Your verification code is 123456", channel: "sms", // optional: sms, whatsapp, email metadata: { userId: "user_123", }, idempotencyKey: "unique-key", // optional: prevent duplicates }); console.log(result.message.id); // msg_xxx console.log(result.message.status); // queued

Send with Sender

Specify which sender profile to use:

TypeScript
const result = await client.messages.send({ to: "+14155551234", text: "Hello!", 'Zavu-Sender': "snd_abc123", });

Send with Template

Send a WhatsApp template message:

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "template", content: { templateId: "tpl_abc123", templateVariables: { "1": "John", "2": "12345", }, }, });

Send WhatsApp Media

Image

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "image", text: "Check out this product!", content: { mediaUrl: "https://example.com/image.jpg", }, });

Document

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "document", content: { mediaUrl: "https://example.com/invoice.pdf", filename: "invoice.pdf", }, });

Video

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "video", text: "Watch this!", content: { mediaUrl: "https://example.com/video.mp4", }, });

Send Interactive Messages

Buttons

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "buttons", text: "How would you rate your experience?", content: { buttons: [ { id: "great", title: "Great!" }, { id: "okay", title: "It was okay" }, { id: "poor", title: "Not good" }, ], }, });

List

TypeScript
const result = await client.messages.send({ to: "+14155551234", messageType: "list", text: "Select an option:", content: { listButton: "View Options", sections: [ { title: "Products", rows: [ { id: "prod_1", title: "Product A", description: "$10.00" }, { id: "prod_2", title: "Product B", description: "$20.00" }, ], }, ], }, });

Send Email

TypeScript
const result = await client.messages.send({ to: "user@example.com", channel: "email", subject: "Your order has shipped", text: "Hi John, your order #12345 has shipped.", htmlBody: "<h2>Order Shipped</h2><p>Your order #12345 has shipped.</p>", replyTo: "support@example.com", });

Send Email with Attachments

TypeScript
import fs from "fs"; const result = await client.messages.send({ to: "user@example.com", channel: "email", subject: "Your invoice", text: "Please find your invoice attached.", attachments: [ { filename: "invoice.pdf", content: fs.readFileSync("invoice.pdf").toString("base64"), content_type: "application/pdf", }, ], });

Attachment from URL

TypeScript
const result = await client.messages.send({ to: "user@example.com", channel: "email", subject: "Your report", text: "Report attached.", attachments: [ { filename: "report.pdf", path: "https://your-server.com/reports/report.pdf", }, ], });

Inline Image

TypeScript
const result = await client.messages.send({ to: "user@example.com", channel: "email", subject: "Weekly report", text: "See your report.", htmlBody: '<h2>Report</h2><img src="cid:chart" />', attachments: [ { filename: "chart.png", path: "https://your-server.com/chart.png", content_type: "image/png", content_id: "chart", }, ], });

Get Message Status

TypeScript
const result = await client.messages.retrieve({ messageId: "msg_abc123", }); console.log(result.message.status); // queued, sending, sent, delivered, failed

List Messages

TypeScript
// List all messages const result = await client.messages.list({}); // With filters const result = await client.messages.list({ status: "delivered", channel: "sms", limit: 100, }); // Pagination let cursor: string | undefined; do { const result = await client.messages.list({ cursor, limit: 50 }); for (const message of result.items) { console.log(message.id); } cursor = result.nextCursor ?? undefined; } while (cursor);

Send Reaction

React to a WhatsApp message:

TypeScript
const result = await client.messages.react({ messageId: "msg_abc123", emoji: "👍", });