|
| 1 | +# Receiving Discord Events Locally |
| 2 | + |
| 3 | +`trogon-source-discord` is the inbound pipe for Discord events into NATS |
| 4 | +JetStream. It runs in one of two mutually exclusive modes, controlled by |
| 5 | +`DISCORD_MODE`: |
| 6 | + |
| 7 | +| Mode | Transport | Events | Requires | |
| 8 | +|---|---|---|---| |
| 9 | +| `gateway` | WebSocket (you connect to Discord) | Everything — messages, reactions, members, voice, interactions, etc. | `DISCORD_BOT_TOKEN` | |
| 10 | +| `webhook` | HTTP POST (Discord connects to you) | Interactions only — slash commands, buttons, modals, autocomplete | `DISCORD_PUBLIC_KEY` | |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Docker Compose |
| 15 | +- A [Discord Application](https://discord.com/developers/applications) |
| 16 | +- An [ngrok](https://ngrok.com) account (free tier, only needed for `webhook` mode) |
| 17 | + |
| 18 | +## Gateway mode |
| 19 | + |
| 20 | +### 1. Get your bot token |
| 21 | + |
| 22 | +1. Go to **Discord Developer Portal → Applications → your app → Bot** |
| 23 | +2. Copy the **Token** |
| 24 | + |
| 25 | +### 2. Start the stack |
| 26 | + |
| 27 | +```bash |
| 28 | +DISCORD_MODE=gateway \ |
| 29 | +DISCORD_BOT_TOKEN=<your-bot-token> \ |
| 30 | +docker compose up |
| 31 | +``` |
| 32 | + |
| 33 | +This connects to the Discord Gateway and publishes every event to NATS on |
| 34 | +`discord.{event_name}` subjects (e.g. `discord.message_create`, |
| 35 | +`discord.guild_member_add`). |
| 36 | + |
| 37 | +## Webhook mode |
| 38 | + |
| 39 | +### 1. Get your public key |
| 40 | + |
| 41 | +1. Go to **Discord Developer Portal → Applications → your app → General Information** |
| 42 | +2. Copy the **Public Key** (hex string) |
| 43 | + |
| 44 | +### 2. Start the stack |
| 45 | + |
| 46 | +```bash |
| 47 | +DISCORD_MODE=webhook \ |
| 48 | +DISCORD_PUBLIC_KEY=<your-hex-public-key> \ |
| 49 | +docker compose --profile dev up |
| 50 | +``` |
| 51 | + |
| 52 | +This starts NATS, the webhook receiver, and ngrok. Find the public tunnel URL |
| 53 | +in the ngrok container logs: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker compose logs ngrok |
| 57 | +``` |
| 58 | + |
| 59 | +### 3. Configure your Discord Application |
| 60 | + |
| 61 | +1. Go to **Discord Developer Portal → Applications → your app → General Information** |
| 62 | +2. Set **Interactions Endpoint URL** to `https://<ngrok-url>/webhook` |
| 63 | +3. Discord will send a PING to verify the endpoint — the receiver handles this |
| 64 | + automatically |
| 65 | + |
| 66 | +## Verify |
| 67 | + |
| 68 | +Subscribe to NATS to see events flowing: |
| 69 | + |
| 70 | +```bash |
| 71 | +nats sub -s nats://nats.trogonai.orb.local:4222 "discord.>" |
| 72 | +``` |
| 73 | + |
| 74 | +Without `--profile dev`, ngrok is excluded and only the core services start. |
| 75 | + |
| 76 | +## Environment variables |
| 77 | + |
| 78 | +| Variable | Required | Default | Description | |
| 79 | +|---|---|---|---| |
| 80 | +| `DISCORD_MODE` | yes | — | `gateway` or `webhook` | |
| 81 | +| `DISCORD_BOT_TOKEN` | gateway mode | — | Bot token for Gateway WebSocket | |
| 82 | +| `DISCORD_PUBLIC_KEY` | webhook mode | — | Ed25519 public key (hex) for Interactions | |
| 83 | +| `DISCORD_GATEWAY_INTENTS` | no | see code | Comma-separated gateway intents | |
| 84 | +| `NGROK_AUTHTOKEN` | webhook + dev | — | ngrok auth token | |
| 85 | +| `DISCORD_WEBHOOK_PORT` | no | `8080` | HTTP port for the webhook receiver | |
| 86 | +| `DISCORD_SUBJECT_PREFIX` | no | `discord` | NATS subject prefix | |
| 87 | +| `DISCORD_STREAM_NAME` | no | `DISCORD` | JetStream stream name | |
| 88 | +| `DISCORD_STREAM_MAX_AGE_SECS` | no | `604800` | Max age in seconds for JetStream messages (7 days) | |
| 89 | +| `DISCORD_NATS_ACK_TIMEOUT_SECS` | no | `10` | NATS publish ack timeout in seconds | |
| 90 | +| `DISCORD_NATS_REQUEST_TIMEOUT_SECS` | no | `2` | NATS request-reply timeout for autocomplete in seconds | |
| 91 | +| `DISCORD_MAX_BODY_SIZE` | no | `4194304` | Max webhook body size in bytes (4 MB) | |
| 92 | +| `RUST_LOG` | no | `info` | Log level | |
0 commit comments