# Instagram

Answer Instagram DMs from your software. The shop keeps using the Instagram app; Relay passes each DM to your webhook and sends your replies.

## Connect

In the dashboard, **Connect Instagram** opens Instagram's login. The account must be a professional (business or creator) account. Relay stores a 60-day token, encrypted, and renews it automatically.

## Receive

DMs arrive at your webhook URL with the same signature headers as WhatsApp events. The body is Meta's entry, unchanged:

```json
{"object": "instagram", "entry": [{"id": "<instagram account id>", "time": 1760000000,
  "messaging": [{"sender": {"id": "<customer id>"}, "recipient": {"id": "<instagram account id>"},
                 "timestamp": 1760000000, "message": {"mid": "...", "text": "Termin?",
                 "quick_reply": {"payload": "SERVICE:haircut"}}}]}]}
```

- `message.quick_reply.payload` is set when the customer tapped one of your quick replies.
- `postback.payload` arrives when the customer tapped an ice breaker.
- `message.is_echo: true` is a message the shop typed in the Instagram app. Use it to let a person take over the chat.

## Reply

```bash
curl https://relay.vesperai.ch/api/v1/instagram/messages \
  -H "Authorization: Bearer $RELAY_KEY" -H "Content-Type: application/json" \
  -d '{"to": "<customer id>", "text": "Welche Leistung?",
       "quick_replies": [{"title": "Haarschnitt", "payload": "SERVICE:haircut"}]}'
```

- Up to 13 quick replies, titles up to 20 characters.
- Meta's rules: you can only answer, never write first, and only within 24 hours of the customer's last message. A person answering later (up to 7 days) sets `"human_agent": true`.
- Live keys only; Instagram has no test mode yet.

## Ice breakers

The questions shown before a customer writes, up to 4:

```bash
curl -X PUT https://relay.vesperai.ch/api/v1/instagram/accounts/<id>/ice-breakers \
  -H "Authorization: Bearer $RELAY_KEY" -H "Content-Type: application/json" \
  -d '{"items": [{"question": "Termin buchen", "payload": "BOOK"}]}'
```

An empty `items` list removes them. `GET /api/v1/instagram/accounts` lists account ids.

## Reminders

Because of the 24-hour rule, a reminder the day before an appointment cannot go out on Instagram. Ask for the phone number while booking and send the reminder on WhatsApp.
