WhatsApp webhook API: get customer replies on your server
When a customer writes to your business, Koverage posts a message_received event to your server. Explore every field and all 14 event types below, then copy a handler to start.
Explore the WhatsApp webhook API payload
Pick an event type. The JSON shows the message_received event for it, and a ready cURL command lets you test your own server.
Sample values. The event field holds the normalised payload and its inner fields depend on event_type. Check a real event and the Webhooks reference in your dashboard docs.
event_typeThe kind of event. One of 14 values.eventThe normalised payload for that event.textReadable text. Empty when it does not apply.fromThe sender’s phone number (msisdn).msg_idThe platform’s message id.timestampAn ISO date for the event.Route each WhatsApp webhook API event to the right place
Fourteen event types fall into four groups. Decide once what your system does for each group, and your handler stays small.
textmedialocationcontactsreactionShow it in your inbox or support tool. text has the readable words. For media, location and contacts, read the event field.
template_buttonbutton_replylist_replynfm_replyTreat it as a choice. Move the lead, confirm the booking or save the Flow answer. Flow answers can also be read with the Flow completions endpoint.
orderreferralStart your order flow for an order. Tag the lead with its source for a referral.
systemunsupportederrorLog these. Alert your team on error. Never let an unsupported event crash your handler.
A small handler for the WhatsApp webhook API
Three steps. The sample reads the documented fields and routes by event_type.
- Receive the POST
Read the JSON body. The fields are event_type, event, text, from, msg_id and timestamp.
- Answer with 2xx
Reply quickly, then do the slower work. Ask Koverage support for the exact response and retry rules.
- Route by event_type
Send each event to the right part of your system. Keep a default branch.
From a customer message to your reply
The from value in the webhook is the msisdn you use to answer with the send message API.
The customer sends a message to your WhatsApp number.
Koverage posts the event to your server.
Your server calls the send message API.
message_received.from as msisdn.Five habits for a reliable WhatsApp webhook
These keep your handler safe when events are empty, new or repeated.
Answer with a 2xx first. Do slow work after.
Call your database or the send API before you answer.
Check event_type before you read event.
Assume every event has text. It is empty when it does not apply.
Keep a default branch for types you do not handle.
Crash on unsupported or on a type you have not seen.
Save msg_id and skip a message you already processed.
Process the same msg_id twice.
Store the raw body for a few days while you test.
Guess at the payload. Read a real one.
Test your WhatsApp webhook API before launch
Four steps take you from code to a real event on your own phone.
- 1Build the handler
A public HTTPS address on your server that accepts a POST with a JSON body. Use the code above as a start.
- 2Test it with cURL
Pick an event in the explorer, copy the test command and run it against your address. Check your logs.
- 3Give the address to Koverage
Add your webhook address in your Koverage setup. Ask support if you cannot find where.
- 4Send yourself a real message
Write to your business number from your own phone. Watch the event arrive and your handler route it.
WhatsApp webhook API: your questions answered
What is the WhatsApp webhook API?
It is how Koverage tells your server about customer activity. When a customer writes to you, Koverage sends a message_received event to your server as JSON. You do not need to keep asking for new messages.
Which fields does a message_received event have?
event_type, event, text, from, msg_id and timestamp. event_type names the kind of event, event holds the normalised payload, text holds readable text, from is the sender number, msg_id is the platform message id and timestamp is an ISO date.
Which event types can I receive?
text, media, location, contacts, reaction, template_button, button_reply, list_reply, nfm_reply, order, referral, system, unsupported and error. Always keep a default branch for any type you do not handle.
Is text always filled?
No. The text field holds readable text and is empty when it does not apply. Check event_type first, and read the event field for the full payload.
What should my server answer?
Answer quickly with a 2xx status, then do your slow work. This is good webhook practice. Ask Koverage support for the exact response and retry rules before you go live.
How do I avoid handling a message twice?
Save the msg_id of every message you process. If the same msg_id arrives again, skip it.
How do I reply after a webhook?
Use the send message API. Put the from value in contacts as the msisdn, and send your text or template.
Webhook or API call: which one do I use?
Use the webhook to learn what customers send you. Use the send message API to send. Use the delivery report endpoint to check one message you sent.
Start receiving replies with the WhatsApp webhook API
Build your handler, test it with cURL and connect it to Koverage. Need your key first? Start with the API key guide.