Guides
Webhooks

Incoming messages

The messages webhook payloads when the customer writes, taps a button, picks from a list, reacts, sends media or comes from an ad.

Customer messages arrive in the messages field, in value.messages[], with the profile in value.contacts[]. In Mimicr, the customer is a test number and you make them act with POST /v1/whatsapp/{slug}/contacts/{wa_id}/reply. Every reply opens (or renews) the 24-hour window, except reactions.

Text

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/whatsapp/docs/contacts/5511987654321/reply \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "type": "text", "text": "Oi, quero saber do meu pedido" }'
json
{
  "messaging_product": "whatsapp",
  "metadata": { "display_phone_number": "555532704202", "phone_number_id": "424361664134261" },
  "contacts": [{ "profile": { "name": "Ana Ribeiro" }, "wa_id": "5511987654321" }],
  "messages": [{
    "from": "5511987654321",
    "id": "wamid.HBgNNTUxMTk4NzY1NDMyMRUCABEYEjY0M0JCNDQ5MzQyMEMxMjVGNQA=",
    "timestamp": "1793914184",
    "type": "text",
    "text": { "body": "Oi, quero saber do meu pedido" }
  }]
}

The next examples only show messages[0].

Button and list replies

The customerreply bodytype in the webhook
Taps a template quick reply{"type": "button", "message_id": "<wamid>", "title": "Quero o cupom"}button, with button.payload and button.text
Taps a reply button{"type": "button", "message_id": "<wamid>", "index": 0}interactive, interactive.button_reply
Picks from a list{"type": "list", "message_id": "<wamid>", "row_id": "P13"}interactive, interactive.list_reply
Completes a Flow{"type": "flow", "message_id": "<wamid>", "response_json": {...}}interactive, interactive.nfm_reply
json
{
  "context": { "from": "555532704202", "id": "wamid.HBgNNTUxMTk4NzY1NDMyMRUCABEYEjA0MTlCM0IzMDQ1QThFMjlENgA=" },
  "from": "5511987654321",
  "id": "wamid.HBgN…",
  "timestamp": "1793914190",
  "type": "interactive",
  "interactive": { "type": "button_reply", "button_reply": { "id": "RASTREIO", "title": "Rastrear pedido" } }
}

context.id points to the message that had the button.

Text quoting a message

{"type": "text", "text": "Esse aqui", "context": {"message_id": "<wamid>"}} produces context.from and context.id.

Media

{"type": "image", "data": "<base64>", "mime_type": "image/jpeg", "caption": "Foto do botijão"} (or the media_id of an upload) produces:

json
{ "from": "5511987654321", "id": "wamid.HBgN…", "timestamp": "1793914190", "type": "image",
  "image": { "mime_type": "image/jpeg", "sha256": "…", "id": "132404823835057", "caption": "Foto do botijão" } }

document carries filename, audio carries voice and sticker carries animated. Download the file by id (see Media).

Location, contacts and reaction

  • {"type": "location", "latitude": -23.56, "longitude": -46.65, "name": "Casa", "address": "Rua A, 10"} produces location.
  • {"type": "contacts", "contacts": [{"name": {"formatted_name": "João"}, "phones": [{"phone": "+5511999990000"}]}]} produces contacts.
  • {"type": "reaction", "message_id": "<wamid>", "emoji": "❤️"} produces reaction with message_id and emoji.

From an ad (Click-to-WhatsApp)

{"type": "text", "text": "Vi o anúncio", "referral": true} adds a sample referral; pass an object to control the fields:

json
{
  "from": "5511987654321",
  "type": "text",
  "text": { "body": "Vi o anúncio" },
  "referral": { "source_url": "https://fb.me/3cr4Wqqkq", "source_id": "120200000000000001", "source_type": "ad", "headline": "Oferta da semana", "body": "Fale com a gente pelo WhatsApp", "media_type": "image", "image_url": "https://…", "ctwa_clid": "Afd…" }
}

Stop and resume marketing

POST /v1/whatsapp/{slug}/contacts/{wa_id}/preferences with {"value": "stop"} (or resume) produces the user_preferences field:

json
{
  "messaging_product": "whatsapp",
  "metadata": { "display_phone_number": "555532704202", "phone_number_id": "424361664134261" },
  "contacts": [{ "wa_id": "5561996667788", "profile": { "name": "Fábio Lima" } }],
  "user_preferences": [{ "wa_id": "5561996667788", "detail": "User requested to stop marketing messages", "category": "marketing_messages", "value": "stop", "timestamp": 1792010650 }]
}

After stop, marketing templates to that number fail with 131050.

Which number receives it

The customer replies to the business number given in phone_number_id in the reply body; without it, to the number of the quoted message, or the last one that talked to them, or the sandbox's default number.