# Discord recipes

> Post incoming texts to a Discord channel.

Two recipes for Discord. Each names its trigger and the BlueBot step, lists the fields to map and says how to test it with your own number before anyone else gets a text.

## How Discord connects

- **[Zapier](https://usebluebot.com/docs/zapier)**: BlueBot’s Zapier app has a Send Text action and instant triggers for incoming texts and every change of state.
- **[API](https://usebluebot.com/docs/api)**: Your own code calls BlueBot’s REST API and listens to its signed webhooks.

## Post incoming texts to a channel

| Part             | What it is                                                                    |
| ---------------- | ----------------------------------------------------------------------------- |
| Trigger          | BlueBot’s New Incoming Text trigger in Zapier                                 |
| Action           | BlueBot’s **New Incoming Text** trigger starts it, and Discord takes the text |
| Connects through | [Zapier](https://usebluebot.com/docs/zapier)                                                        |

### Steps

1. Start a Zap with BlueBot’s New Incoming Text trigger.
2. Add Discord’s Send Channel Message action and pick the channel.
3. Map the sender’s number and the words of the text into the message.

### Map the fields

| From BlueBot    | Into Discord                                                                                                                                           |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **From**        | The phone number to find the person by in Discord. It’s in E.164 (`+15555550123`); search by the last 10 digits if Discord stores numbers another way. |
| **Text**        | The words, for a note, a row or a message. Null when the person sent only a picture.                                                                   |
| **Received At** | When it came in, in UTC.                                                                                                                               |
| **Files**       | Pictures and voice memos. Each `url` works for an hour, so copy a file you want to keep.                                                               |
| **Chat ID**     | Set when the text came in a group chat; null for a one-to-one text.                                                                                    |

### Test it

Text your BlueBot number from another phone, one you’ve texted through BlueBot before, then press **Test trigger** in Zapier. It loads that text with its fields, ready to map. BlueBot copies texts from people you’ve texted through it, unless you set **Which chats to copy** to **Everything**.

## Post replies with a channel webhook

| Part             | What it is                                                             |
| ---------------- | ---------------------------------------------------------------------- |
| Trigger          | A text comes in (BlueBot’s message.received webhook)                   |
| Action           | A webhook for `message.received` starts it, and Discord takes the text |
| Connects through | [API](https://usebluebot.com/docs/api)                                                       |

### Steps

1. Create a webhook for the channel in Discord and copy its URL.
2. Point a BlueBot webhook for message.received at a small function of your own.
3. Have the function check BlueBot’s signature and post the sender and the words to the Discord webhook URL.

### Map the fields

| From BlueBot       | Into Discord                                                                                                                                           |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `data.from`        | The phone number to find the person by in Discord. It’s in E.164 (`+15555550123`); search by the last 10 digits if Discord stores numbers another way. |
| `data.text`        | The words, for a note, a row or a message. Null when the person sent only a picture.                                                                   |
| `data.received_at` | When it came in, in UTC.                                                                                                                               |
| `data.files`       | Pictures and voice memos. Each `url` works for an hour, so copy a file you want to keep.                                                               |
| `data.chat_id`     | Set when the text came in a group chat; null for a one-to-one text.                                                                                    |

### Test it

Run `bluebot listen --forward-to http://localhost:3000/webhooks`, then text your BlueBot number from another phone. The CLI forwards the event to your handler, signed. BlueBot copies texts from people you’ve texted through it, unless you set **Which chats to copy** to **Everything**.

## Before you turn it on

- Text only people who asked to hear from you. Anyone who replies STOP goes on your stop list, and BlueBot cancels texts to them. [Stop words](https://usebluebot.com/docs/concepts/stop-words)
- A text that can’t go yet waits with a hold rather than failing: quiet hours, your Mac away, a daily limit. [Holds](https://usebluebot.com/docs/concepts/holds)
- [Discord with BlueBot](https://usebluebot.com/integrations/discord) on the integrations page says what else the two do together.
