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',
    ],
    'idempotencyKey' => 'unique-key', // optional: prevent duplicates
]);

echo $result->message->id . "\n"; // msg_xxx
echo $result->message->status . "\n"; // 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',
    'messageType' => 'template',
    'content' => [
        'templateId' => 'tpl_abc123',
        'templateVariables' => [
            '1' => 'John',
            '2' => '12345',
        ],
    ],
]);

Send WhatsApp Media

Image

$result = $client->messages->send([
    'to' => '+14155551234',
    'messageType' => 'image',
    'text' => 'Check out this product!',
    'content' => [
        'mediaUrl' => 'https://example.com/image.jpg',
    ],
]);

Document

$result = $client->messages->send([
    'to' => '+14155551234',
    'messageType' => 'document',
    'content' => [
        'mediaUrl' => 'https://example.com/invoice.pdf',
        'filename' => 'invoice.pdf',
    ],
]);

Video

$result = $client->messages->send([
    'to' => '+14155551234',
    'messageType' => 'video',
    'text' => 'Watch this!',
    'content' => [
        'mediaUrl' => 'https://example.com/video.mp4',
    ],
]);

Send Interactive Messages

Buttons

$result = $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

$result = $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

$result = $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

$result = $client->messages->get([
    'messageId' => 'msg_abc123',
]);

echo $result->message->status . "\n"; // queued, sending, sent, delivered, failed

List Messages

// List all messages
$result = $client->messages->list([]);

// With filters
$result = $client->messages->list([
    'status' => 'delivered',
    'channel' => 'sms',
    'limit' => 100,
]);

// Pagination
$cursor = null;
do {
    $result = $client->messages->list(['cursor' => $cursor, 'limit' => 50]);
    foreach ($result->items as $message) {
        echo $message->id . "\n";
    }
    $cursor = $result->nextCursor;
} while ($cursor !== null);

Send Reaction

React to a WhatsApp message:
$result = $client->messages->react([
    'messageId' => 'msg_abc123',
    'emoji' => "\u{1F44D}", // thumbs up
]);