I am currently facing an issue with the Meta Cloud API and WhatsApp Business API and I'm seeking some guidance.
Issue Description:
I have a WhatsApp chatbot for customers, and to facilitate testing and development, I've set up three different environments (stages). Each stage has its own test number and is associated with a separate app using the Meta Cloud API and WhatsApp Business API. Every app is connected to its unique webhook and is subscribed to the 'messages' field.
However, I am encountering an unexpected behavior where every webhook is receiving events from all other numbers, not just its corresponding number.
Setup Details:
For each app, I have the following configuration in the meta developer web app:
Quickstart Configuration: To get alerted when you receive a message or when a message's status has changed, a Webhooks endpoint is set up for each app.
Callback URL: Each app has a different callback URL, something like https://.....com/webhook.
Verify token: Different for each app
What actually happens:
Despite having distinct endpoints and configurations for each app, messages intended for one stage are being received by the webhooks of the other stages as well.
Object received from Meta Cloud API when I send "hi" to the test number – gets delivered to all three webhooks:
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "id_1",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "test_stage_phone_no",
"phone_number_id": "test_stage_phone_no_id"
},
"contacts": [
{
"profile": {
"name": "Leon"
},
"wa_id": "my_phone_number"
}
],
"messages": [
{
"from": "my_phone_number",
"id": "wamid.HBgNNDk...",
"timestamp": "1704481181",
"text": {
"body": "hi"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
Object received from Meta Cloud API when I send "hi" to the production number – gets delivered to all three webhooks:
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "id_2",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "prod_stage_phone_no",
"phone_number_id": "prod_stage_phone_no_id"
},
"contacts": [
{
"profile": {
"name": "Leon"
},
"wa_id": "my_phone_number"
}
],
"messages": [
{
"from": "my_phone_number",
"id": "wamid.HBgNN...",
"timestamp": "1704482444",
"text": {
"body": "hi"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
As a temporary workaround, in my webhook, I am checking the WhatsApp Business ID from which the message originates and filtering out messages that don't match the Business ID associated with that stage. However, I believe there should be a way to ensure each webhook only receives messages for its specific app.
Questions:
Has anyone else experienced this issue with the Meta Cloud API and WhatsApp Business API?
Is there a configuration step I might be missing that would ensure each webhook only receives messages intended for its associated app? Are there any best practices or additional settings I should consider to isolate the webhook events to their respective apps?