Send a Message
Copy
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:Copy
const result = await client.messages.send({
to: "+14155551234",
text: "Hello!",
'Zavu-Sender': "snd_abc123",
});
Send with Template
Send a WhatsApp template message:Copy
const result = await client.messages.send({
to: "+14155551234",
messageType: "template",
content: {
templateId: "tpl_abc123",
templateVariables: {
"1": "John",
"2": "12345",
},
},
});
Send WhatsApp Media
Image
Copy
const result = await client.messages.send({
to: "+14155551234",
messageType: "image",
text: "Check out this product!",
content: {
mediaUrl: "https://example.com/image.jpg",
},
});
Document
Copy
const result = await client.messages.send({
to: "+14155551234",
messageType: "document",
content: {
mediaUrl: "https://example.com/invoice.pdf",
filename: "invoice.pdf",
},
});
Video
Copy
const result = await client.messages.send({
to: "+14155551234",
messageType: "video",
text: "Watch this!",
content: {
mediaUrl: "https://example.com/video.mp4",
},
});
Send Interactive Messages
Buttons
Copy
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
Copy
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
Copy
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: "<h1>Order Shipped</h1><p>Your order #12345 has shipped.</p>",
replyTo: "support@example.com",
});
Get Message Status
Copy
const result = await client.messages.get({
messageId: "msg_abc123",
});
console.log(result.message.status); // queued, sending, delivered, failed
List Messages
Copy
// 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:Copy
const result = await client.messages.react({
messageId: "msg_abc123",
emoji: "👍",
});