📌 What is a Webhook?
A webhook is a URL where Meta sends real-time data when an event happens.
👉 Example events:
- Incoming message
- Message delivered
- Message read
📌 Step 1: Create Webhook URL
You need a public HTTPS URL.
👉 Example:
https://yourdomain.com/webhook.php
⚠️ Important:
- Must be HTTPS
- Must be publicly accessible
📌 Step 2: Verify Webhook (Meta Requirement)
Example PHP Verification Code:
<?php
$verify_token = "12345";
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if ($_GET['hub_verify_token'] === $verify_token) {
echo $_GET['hub_challenge'];
exit;
} else {
echo "Invalid token";
}
}
?>
👉 This step confirms your server is valid.
📌 Step 3: Add Webhook in Meta App
- Go to Meta Developers Dashboard
- Select your app
- Navigate to WhatsApp → Configuration
- Click Edit Webhook
Enter:
- Callback URL
- Verify Token
Click Verify and Save
📌 Step 4: Subscribe to Events
After verification, select events:
✅ messages → Incoming messages
✅ message_status → Sent, delivered, read
👉 Click Subscribe
📌 Step 5: Handle Incoming Data
Example Webhook Listener (PHP):
<?php
$data = json_decode(file_get_contents("php://input"), true);
file_put_contents("log.txt", print_r($data, true), FILE_APPEND);
?>
👉 This logs all incoming webhook data.
📌 Step 6: Understand Webhook Data
Incoming Message Example:
{
"messages": [
{
"from": "919876543210",
"text": {
"body": "Hello"
}
}
]
}
Status Update Example:
{
"statuses": [
{
"status": "delivered"
}
]
}
⚠️ Common Errors & Fixes
❌ Webhook verification failed
👉 Fix:
- Verify token mismatch
- URL not accessible
❌ 403 Forbidden
👉 Fix:
- Server blocking request
- Check firewall / permissions
❌ No webhook data received
👉 Fix:
- Events not subscribed
- Wrong callback URL
❌ SSL error
👉 Fix:
- Use valid HTTPS (no self-signed SSL)
💡 Pro Tips
- Always log webhook data
- Use queue system for processing
- Validate incoming requests
- Secure webhook with token check
🎯 Real Use Cases
- Chatbot automation
- Auto-reply system
- CRM integration
- Order tracking updates
🏁 Conclusion
Webhook setup is the most important part of WhatsApp Cloud API. Once configured, your system can receive messages and automate responses in real-time.