Skip to main content

Send a Message

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:
result = client.messages.send(
  to: "+14155551234",
  text: "Hello!",
  zavu_sender: "snd_abc123"
)

Send with Template

Send a WhatsApp template message:
result = client.messages.send(
  to: "+14155551234",
  message_type: "template",
  content: {
    "template_id" => "tpl_abc123",
    "template_variables" => {
      "1" => "John",
      "2" => "12345"
    }
  }
)

Send WhatsApp Media

Image

result = client.messages.send(
  to: "+14155551234",
  message_type: "image",
  text: "Check out this product!",
  content: {
    "media_url" => "https://example.com/image.jpg"
  }
)

Document

result = client.messages.send(
  to: "+14155551234",
  message_type: "document",
  content: {
    "media_url" => "https://example.com/invoice.pdf",
    "filename" => "invoice.pdf"
  }
)

Video

result = client.messages.send(
  to: "+14155551234",
  message_type: "video",
  text: "Watch this!",
  content: {
    "media_url" => "https://example.com/video.mp4"
  }
)

Send Interactive Messages

Buttons

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

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

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

result = client.messages.get(message_id: "msg_abc123")

puts result.message.status # queued, sending, sent, delivered, failed

List Messages

# 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:
result = client.messages.react(
  message_id: "msg_abc123",
  emoji: "\u{1F44D}"
)