WhatsApp Business Messenger Integration with Website
WhatsApp Business API allows sending transactional notifications, building chat bots, and conducting customer conversations. Available via official Cloud API from Meta or through partners (BSP): Twilio, 360dialog, Infobip, WATI.
Connection Methods
Meta Cloud API (Direct) — free access for business via Meta Business Suite. Requires verified Business Manager, phone number (cannot be used in WhatsApp simultaneously with other methods).
BSP (Business Solution Provider) — intermediary providing API keys without direct Meta work. Faster to connect, more convenient for small projects, but more expensive per message.
Sending Message via Cloud API
$response = Http::withToken(env('WHATSAPP_ACCESS_TOKEN'))
->post("https://graph.facebook.com/v19.0/{$phoneNumberId}/messages", [
'messaging_product' => 'whatsapp',
'to' => $phone, // international format: 79001234567
'type' => 'template',
'template' => [
'name' => 'order_confirmation',
'language' => ['code' => 'en'],
'components' => [
[
'type' => 'body',
'parameters' => [
['type' => 'text', 'text' => $orderId],
['type' => 'text', 'text' => $orderTotal . ' ₽']
]
]
]
]
]);
Message Templates
For outgoing notifications, pre-approved templates are mandatory. Template is created in Meta Business Manager and goes through review (usually 24–48 hours). Arbitrary text in outgoing messages cannot be sent — only within 24-hour session window.
24-Hour Window and Session Messages
If a user messaged the bot first or replied to a template message — a 24-hour window opens during which arbitrary messages can be sent. This is used for support and dialogs:
// Arbitrary message (only within 24h window)
Http::withToken($token)->post($url, [
'messaging_product' => 'whatsapp',
'to' => $phone,
'type' => 'text',
'text' => ['body' => "Your order shipped, tracking: {$trackNumber}"]
]);
Webhook for Incoming
// Webhook verification on registration
if ($request->has('hub_challenge')) {
if ($request->hub_verify_token === env('WHATSAPP_VERIFY_TOKEN')) {
return response($request->hub_challenge);
}
}
// Process incoming
$body = $request->json()->all();
foreach ($body['entry'] as $entry) {
foreach ($entry['changes'] as $change) {
$messages = $change['value']['messages'] ?? [];
foreach ($messages as $message) {
dispatch(new ProcessWhatsAppMessageJob($message));
}
}
}
Buttons and Interactive Messages
// Interactive buttons
[
'type' => 'interactive',
'interactive' => [
'type' => 'button',
'body' => ['text' => 'Your order is ready for pickup. Confirm receipt:'],
'action' => [
'buttons' => [
['type' => 'reply', 'reply' => ['id' => "confirm_{$orderId}", 'title' => 'Received ✓']],
['type' => 'reply', 'reply' => ['id' => "problem_{$orderId}", 'title' => 'Problem']]
]
]
]
]
Integration timeframe: 3–5 days for notifications with templates + incoming messages. Template verification time — separate (1–3 days).







