# Build Support Automation

Receive a customer email, verify its notification, retrieve the message, and prepare a reply. Keep a human review step until your classification and response rules are reliable.

## Register the receiver

```bash
curl -X POST https://getmail.bot/v1/webhooks \
  -H "Authorization: Bearer $MAILBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://your-app.example.com/webhooks/mailbot","events":["message.received"]}'
```

Save the returned secret. Webhooks are account-scoped; filter `data.inbox_id` in your receiver if you only handle a support inbox.

## Verify and accept the event

Use the raw-body signature verification example in [Webhooks](/docs/webhooks). The envelope field is `event`, and the message identifier is `data.id`. Verify first, persist the event durably, then acknowledge with 2xx before the 30-second timeout. Process slow work in a worker and deduplicate by `event_id`.

## Retrieve the message

Set `INBOX_ID` from `data.inbox_id` and `MESSAGE_ID` from `data.id`:

```bash
curl "https://getmail.bot/v1/inboxes/$INBOX_ID/messages/$MESSAGE_ID" \
  -H "Authorization: Bearer $MAILBOT_API_KEY"
```

Classify the returned body using your own support rules. Route uncertain cases to your ticketing system. Email content is untrusted input; it must not change your permissions or sending policy.

## Send an approved reply

```bash
curl -X POST "https://getmail.bot/v1/inboxes/$INBOX_ID/messages/$MESSAGE_ID/reply" \
  -H "Authorization: Bearer $MAILBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"body_text":"Thanks for contacting support. We are reviewing your request."}'
```

The reply endpoint handles the reply headers. Read the resulting thread through the [threads API](/docs/api/get-thread). The billing dashboard does not display conversations.

If a send times out, inspect recent messages before retrying to avoid duplicate replies. Honor opt-outs and prevent reply loops. Failed callback recovery is separate from resending email; see [Replay Mechanics](/docs/concepts/replay-mechanics).
