Send a Message
Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
text: "Your verification code is 123456",
channel: "sms", # optional: sms, whatsapp, email
metadata: {
"userId" => "user_123"
},
idempotency_key: "unique-key" # optional: prevent duplicates
)
puts result.message.id # msg_xxx
puts result.message.status # queued
Send with Sender
Specify which sender profile to use:Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
text: "Hello!",
zavu_sender: "snd_abc123"
)
Send with Template
Send a WhatsApp template message:Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "template",
content: {
"template_id" => "tpl_abc123",
"template_variables" => {
"1" => "John",
"2" => "12345"
}
}
)
Send WhatsApp Media
Image
Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "image",
text: "Check out this product!",
content: {
"media_url" => "https://example.com/image.jpg"
}
)
Document
Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "document",
content: {
"media_url" => "https://example.com/invoice.pdf",
"filename" => "invoice.pdf"
}
)
Video
Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "video",
text: "Watch this!",
content: {
"media_url" => "https://example.com/video.mp4"
}
)
Send Interactive Messages
Buttons
Copy
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "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
Ask AI
result = client.messages.send(
to: "+14155551234",
message_type: "list",
text: "Select an option:",
content: {
"list_button" => "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
Ask AI
result = client.messages.send(
to: "user@example.com",
channel: "email",
subject: "Your order has shipped",
text: "Hi John, your order #12345 has shipped.",
html_body: "<h1>Order Shipped</h1><p>Your order #12345 has shipped.</p>",
reply_to: "support@example.com"
)
Get Message Status
Copy
Ask AI
result = client.messages.get(message_id: "msg_abc123")
puts result.message.status # queued, sending, sent, delivered, failed
List Messages
Copy
Ask AI
# List all messages
result = client.messages.list
result.items.each { |message| puts message.id }
# With filters
result = client.messages.list(
status: "delivered",
channel: "sms",
limit: 100
)
# Pagination
cursor = nil
loop do
result = client.messages.list(cursor: cursor, limit: 50)
result.items.each { |message| puts message.id }
cursor = result.next_cursor
break if cursor.nil?
end
Send Reaction
React to a WhatsApp message:Copy
Ask AI
result = client.messages.react(
message_id: "msg_abc123",
emoji: "\u{1F44D}"
)
