> ## Documentation Index
> Fetch the complete documentation index at: https://developer.meetergo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Two-way WhatsApp messaging

> Receive inbound WhatsApp messages, run your own logic, and reply — within the rules of the WhatsApp Business Platform.

This recipe wires up a complete inbound→reply loop on a WhatsApp number
connected to meetergo. What you do *between* receiving and replying — routing,
automation, a business-scoped assistant, a human agent handoff — is up to you;
this shows the plumbing.

<Note>
  Requires the **WhatsApp add-on** + an **API Platform** subscription and a
  connected WhatsApp Business number. See [WhatsApp](/developer-docs/core-concepts/whatsapp).
</Note>

## 1. Receive inbound messages

Subscribe a webhook to the `whatsapp_message_received` event:

```bash theme={null}
curl https://api.meetergo.com/webhooks \
  -H "Authorization: Bearer ak_live:..." \
  -H "x-meetergo-api-user-id: <user-uuid>" \
  -H "Content-Type: application/json" \
  -d '{ "endpoint": "https://your-app.com/wa", "eventTypes": ["whatsapp_message_received"] }'
```

Now every inbound message is POSTed to your URL:

```json theme={null}
{
  "webhookType": "whatsapp_message_received",
  "conversationId": "conv-uuid-123",
  "from": "+491234567890",
  "text": "Do you have this in size M?",
  "type": "text",
  "windowReopened": true
}
```

## 2. Decide a reply

```js theme={null}
app.post('/wa', async (req, res) => {
  res.sendStatus(200) // ACK fast; do work async

  const { from, text } = req.body
  if (req.body.webhookType !== 'whatsapp_message_received') return

  // ── your logic here ──────────────────────────────────────────
  // Route to a team, look up an order, answer a business question,
  // hand off to an agent — whatever your product does.
  const reply = await decideReply(from, text)
  // ─────────────────────────────────────────────────────────────

  await sendWhatsApp({ to: from, type: 'text', text: reply })
})
```

## 3. Reply (mind the 24-hour window)

Because the contact just messaged you, the
[24-hour window](/developer-docs/core-concepts/whatsapp#the-24-hour-window-read-this-first)
is open, so a free-form `text` reply is allowed:

```js theme={null}
async function sendWhatsApp(body) {
  const r = await fetch('https://api.meetergo.com/v4/whatsapp/messages', {
    method: 'POST',
    headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  })
  if (r.status === 403) {
    // Window closed — fall back to an approved template.
    return sendWhatsApp({
      to: body.to,
      type: 'template',
      template: { name: 'follow_up', language: 'en_US' },
    })
  }
  return r.json()
}
```

To re-engage a contact *outside* the window (e.g. a scheduled follow-up), you
must use a pre-approved template — list yours via `GET /v4/whatsapp/templates`.

## 4. Track delivery (optional)

Subscribe to `whatsapp_message_status` to know when your replies are
`delivered`/`read`/`failed`, correlated by the `waMessageId` the send returned.

## Staying within WhatsApp's rules

* You need **opt-in** to message a contact; no unsolicited messaging.
* Free-form messages only inside the 24h window; **pre-approved templates** anytime.
* **General-purpose AI assistants are not allowed** on the WhatsApp Business
  Platform. Business-scoped automation (customer service, order/contract/logistics
  Q\&A) is fine — keep any automation scoped to your business process.
* WhatsApp message data must not be used to train third-party AI models.
