Guias
Webhooks

Mensagens recebidas

Os payloads do webhook messages quando o cliente escreve, toca num botão, escolhe da lista, reage, manda mídia ou vem de um anúncio.

Mensagens do cliente chegam no field messages, em value.messages[], com o perfil em value.contacts[]. No Mimicr, o cliente é um número de teste e você o faz agir com POST /v1/whatsapp/{slug}/contacts/{wa_id}/reply. Cada resposta abre (ou renova) a janela de 24 horas, menos reações.

Texto

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" }
  }]
}

Os próximos exemplos mostram só messages[0].

Resposta a botões e listas

O clienteCorpo do replytype no webhook
Toca num quick reply de template{"type": "button", "message_id": "<wamid>", "title": "Quero o cupom"}button, com button.payload e button.text
Toca num botão de resposta{"type": "button", "message_id": "<wamid>", "index": 0}interactive, interactive.button_reply
Escolhe numa lista{"type": "list", "message_id": "<wamid>", "row_id": "P13"}interactive, interactive.list_reply
Conclui um 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 aponta para a mensagem que tinha o botão.

Texto citando uma mensagem

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

Mídia

{"type": "image", "data": "<base64>", "mime_type": "image/jpeg", "caption": "Foto do botijão"} (ou media_id de um upload) gera:

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

document traz filename, audio traz voice e sticker traz animated. Baixe o arquivo pelo id (veja Mídia).

Localização, contatos e reação

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

Vindo de um anúncio (Click-to-WhatsApp)

{"type": "text", "text": "Vi o anúncio", "referral": true} acrescenta um referral de exemplo; passe um objeto para controlar os campos:

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…" }
}

Parar e retomar o marketing

POST /v1/whatsapp/{slug}/contacts/{wa_id}/preferences com {"value": "stop"} (ou resume) gera o field user_preferences:

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 }]
}

Depois de stop, templates de marketing para esse número falham com 131050.

Qual número recebe

O cliente responde ao número da empresa informado em phone_number_id no corpo do reply; sem ele, ao número da mensagem citada, ou ao último que falou com ele, ou ao número padrão do sandbox.