-
Notifications
You must be signed in to change notification settings - Fork 1
feat(trogon-source-discord): add Discord source with Gateway and Interactions support #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
devops/docker/compose/services/trogon-source-discord/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # ── Stage 1: chef — generate dependency recipe ────────────────────────────── | ||
| FROM rust:1.93-slim AS chef | ||
|
|
||
| RUN cargo install cargo-chef --locked | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| # ── Stage 2: planner — capture dependency graph ───────────────────────────── | ||
| FROM chef AS planner | ||
|
|
||
| COPY Cargo.toml Cargo.lock ./ | ||
| COPY crates/ crates/ | ||
|
|
||
| RUN cargo chef prepare --recipe-path recipe.json | ||
|
|
||
| # ── Stage 3: builder — cached dependency build + final compile ────────────── | ||
| FROM chef AS builder | ||
|
|
||
| COPY --from=planner /build/recipe.json recipe.json | ||
| RUN cargo chef cook --release --recipe-path recipe.json -p trogon-source-discord | ||
|
|
||
| COPY Cargo.toml Cargo.lock ./ | ||
| COPY crates/ crates/ | ||
|
|
||
| RUN cargo build --release -p trogon-source-discord && \ | ||
| strip target/release/trogon-source-discord | ||
|
|
||
| # ── Stage 4: runtime ──────────────────────────────────────────────────────── | ||
| FROM debian:bookworm-20250317-slim AS runtime | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates curl \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN useradd --no-create-home --shell /usr/sbin/nologin trogon | ||
|
|
||
| COPY --from=builder /build/target/release/trogon-source-discord /usr/local/bin/trogon-source-discord | ||
|
|
||
| USER trogon | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| STOPSIGNAL SIGTERM | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/trogon-source-discord"] |
92 changes: 92 additions & 0 deletions
92
devops/docker/compose/services/trogon-source-discord/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Receiving Discord Events Locally | ||
|
|
||
| `trogon-source-discord` is the inbound pipe for Discord events into NATS | ||
| JetStream. It runs in one of two mutually exclusive modes, controlled by | ||
| `DISCORD_MODE`: | ||
|
|
||
| | Mode | Transport | Events | Requires | | ||
| |---|---|---|---| | ||
| | `gateway` | WebSocket (you connect to Discord) | Everything — messages, reactions, members, voice, interactions, etc. | `DISCORD_BOT_TOKEN` | | ||
| | `webhook` | HTTP POST (Discord connects to you) | Interactions only — slash commands, buttons, modals, autocomplete | `DISCORD_PUBLIC_KEY` | | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Docker Compose | ||
| - A [Discord Application](https://discord.com/developers/applications) | ||
| - An [ngrok](https://ngrok.com) account (free tier, only needed for `webhook` mode) | ||
|
|
||
| ## Gateway mode | ||
|
|
||
| ### 1. Get your bot token | ||
|
|
||
| 1. Go to **Discord Developer Portal → Applications → your app → Bot** | ||
| 2. Copy the **Token** | ||
|
|
||
| ### 2. Start the stack | ||
|
|
||
| ```bash | ||
| DISCORD_MODE=gateway \ | ||
| DISCORD_BOT_TOKEN=<your-bot-token> \ | ||
| docker compose up | ||
| ``` | ||
|
|
||
| This connects to the Discord Gateway and publishes every event to NATS on | ||
| `discord.{event_name}` subjects (e.g. `discord.message_create`, | ||
| `discord.guild_member_add`). | ||
|
|
||
| ## Webhook mode | ||
|
|
||
| ### 1. Get your public key | ||
|
|
||
| 1. Go to **Discord Developer Portal → Applications → your app → General Information** | ||
| 2. Copy the **Public Key** (hex string) | ||
|
|
||
| ### 2. Start the stack | ||
|
|
||
| ```bash | ||
| DISCORD_MODE=webhook \ | ||
| DISCORD_PUBLIC_KEY=<your-hex-public-key> \ | ||
| docker compose --profile dev up | ||
| ``` | ||
|
|
||
| This starts NATS, the webhook receiver, and ngrok. Find the public tunnel URL | ||
| in the ngrok container logs: | ||
|
|
||
| ```bash | ||
| docker compose logs ngrok | ||
| ``` | ||
|
|
||
| ### 3. Configure your Discord Application | ||
|
|
||
| 1. Go to **Discord Developer Portal → Applications → your app → General Information** | ||
| 2. Set **Interactions Endpoint URL** to `https://<ngrok-url>/webhook` | ||
| 3. Discord will send a PING to verify the endpoint — the receiver handles this | ||
| automatically | ||
|
|
||
| ## Verify | ||
|
|
||
| Subscribe to NATS to see events flowing: | ||
|
|
||
| ```bash | ||
| nats sub -s nats://nats.trogonai.orb.local:4222 "discord.>" | ||
| ``` | ||
|
|
||
| Without `--profile dev`, ngrok is excluded and only the core services start. | ||
|
|
||
| ## Environment variables | ||
|
|
||
| | Variable | Required | Default | Description | | ||
| |---|---|---|---| | ||
| | `DISCORD_MODE` | yes | — | `gateway` or `webhook` | | ||
| | `DISCORD_BOT_TOKEN` | gateway mode | — | Bot token for Gateway WebSocket | | ||
| | `DISCORD_PUBLIC_KEY` | webhook mode | — | Ed25519 public key (hex) for Interactions | | ||
| | `DISCORD_GATEWAY_INTENTS` | no | see code | Comma-separated gateway intents | | ||
| | `NGROK_AUTHTOKEN` | webhook + dev | — | ngrok auth token | | ||
| | `DISCORD_WEBHOOK_PORT` | no | `8080` | HTTP port for the webhook receiver | | ||
| | `DISCORD_SUBJECT_PREFIX` | no | `discord` | NATS subject prefix | | ||
| | `DISCORD_STREAM_NAME` | no | `DISCORD` | JetStream stream name | | ||
| | `DISCORD_STREAM_MAX_AGE_SECS` | no | `604800` | Max age in seconds for JetStream messages (7 days) | | ||
| | `DISCORD_NATS_ACK_TIMEOUT_SECS` | no | `10` | NATS publish ack timeout in seconds | | ||
| | `DISCORD_NATS_REQUEST_TIMEOUT_SECS` | no | `2` | NATS request-reply timeout for autocomplete in seconds | | ||
| | `DISCORD_MAX_BODY_SIZE` | no | `4194304` | Max webhook body size in bytes (4 MB) | | ||
| | `RUST_LOG` | no | `info` | Log level | | ||
|
yordis marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.