Repository navigation
Conversation
DMs on Discord and Slack reach the same thread/actor pipeline Telegram uses,
and bot replies go back out through an EventBus delivery listener.
Discord: gateway websocket (identify + heartbeat + MESSAGE_CREATE), DM-only,
bot echoes dropped; DISCORD_BOT_TOKEN env or settings; status endpoint.
Slack: Socket Mode by default (no public URL), Events API webhook transport
with request-signature validation as the alternative; SLACK_BOT_TOKEN +
SLACK_APP_TOKEN (+ SLACK_SIGNING_SECRET for webhook mode).
Both follow the telegram adapter's layout exactly: parse -> get-or-create
external actor -> get-or-create thread (external_ref '<channel>:{id}') ->
post_message, /new //start //help commands, and a DeliveryListener that
forwards bot messages on threads whose external_ref belongs to the channel.
Closes regnull#146.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Discord and Slack DM adapters, built as parallel modules to the existing Telegram one (issue #146). A user DMs the bot on either platform, the message reaches the same thread/actor pipeline (
external_ref = "<channel>:{id}"->post_message), and bot replies go back out through an EventBus delivery listener — the same event flow, session handling and config layout as Telegram.backend/openbot/channels/discord.py): gateway websocket client (identify + heartbeat + MESSAGE_CREATE DISPATCH, Message Content intent), DM-only, bot echoes dropped; reconnect with exponential back-off.DISCORD_BOT_TOKENenv var or the settings page (secret, masked). Gateway-only, so the API router exposes status.backend/openbot/channels/slack.py): Socket Mode by default (no public URL needed) viaSLACK_APP_TOKEN(xapp-, connections:write) +SLACK_BOT_TOKEN(xoxb-); Events API webhook transport with request-signature validation (SLACK_SIGNING_SECRET) as the alternative. Edits/thread re-announcements (ts != event_ts) and bot/subtype echoes are dropped, so the bot never answers its own answer twice./new,/start,/helpwork on both, like Telegram.Discord/Slackgroups) with token-format checks (xoxb-/xapp-), encrypted at rest and masked in the API exactly liketelegram_bot_token.Why not reuse the Telegram transport names
Telegram's ids are ints; Discord snowflakes and Slack channel ids are strings, so each adapter keeps its own
_parse_channel_id_from_refrather than a shared abstraction with three special cases.Tests
66 new tests (
backend/tests/test_discord.py,test_slack.py): parsing, thread mapping, /new isolation, fake gateway/Socket-Mode frames -> handler called -> outbound send asserted, EventBus delivery-listener round-trips, signature validation incl. replay rejection, settings API round-trip with masking, status endpoints.Local evidence (Windows, Python 3.12, uv):
uv run ruff check .-> All checks passed (exit 0)uv run pytest -q-> 938 passed, 7 skipped, 5 failed — all 5 failures reproduce on unmodifiedmainin this Windows environment (cp949 codec / CRLF assertions; e.g.test_search_code_returns_matching_lines...,test_read_file_error_outputs_honour_small_cap) and are unrelated to this change.Telegram, Discord, Slack).Live verification on a real deployment (this machine, WSL Ubuntu-24.04 + Docker)
The branch was checked out and run with the repo's own
compose.yaml(docker compose up --build, backend container healthy on :8000), then exercised at three levels:DISCORD_BOT_TOKEN,SLACK_BOT_TOKEN=xoxb-…,SLACK_APP_TOKEN=xapp-…,SLACK_SIGNING_SECRET),GET /api/v1/channels/discord/status->{"configured":true,"gateway_running":true}andGET /api/v1/channels/slack/status->{"configured":true,"socket_mode":true,"signing_secret":true,"socket_running":true}. The gateway/socket loops connect, fail auth against the real platform APIs with the fake tokens, and reconnect with bounded exponential back-off (observed in container logs: 8s → 16s → … → capped at 60s) without crashing the server — matching the Telegram adapter's resilience.POST /api/v1/channels/slack/eventswith HMAC-SHA256v0:signatures computed from the signing secret — bad signature -> 403;url_verificationchallenge echoed; signed/helpcommand event -> 200 and the reply delivered via chat.postMessage path; signed regular-message event -> 200, thread persisted (external_ref = slack:D0LIVE0002) with the message recorded in the DB (sender_kind=external).completed-> bot reply delivered outbound (hello from the bot). Discord: gateway MESSAGE_CREATE frame -> same path -> outbound. Both printPASS. The identical stubbed round-trip for Telegram was run in the same image as a control and also passes, confirming the new adapters sit on the exact same pipeline.Live Discord round-trip with a real bot token (owner decision: reuse an existing bot, no new app)
Re-run on this machine (WSL Ubuntu-24.04, Docker, fresh
pr320-verifycontainer from this branch'scompose.yaml, LLM via a local OpenAI-compatible route):/users/@me->Hem 5090, id1574249897622905004).GET /channels/discord/status->{"configured":true,"transport":"gateway","gateway_running":true}with the real token: identify accepted, READY received, connection stable (no auth failures).DiscordGatewayClient._handle_frameinside the container logged liveMESSAGE_CREATEdispatches for messages sent through the Discord REST API;parse_discord_messagecorrectly returnsNonefor them — they are bot-authored, and the reply-loop guard drops them by design.271881691650326534) entered the production path (process_discord_message— the exact call the gateway makes after parsing): thread created (external_ref = discord:1574485717478940682), runcompleted, reply stored (sender_kind=bot), andDiscordDeliveryListenerdelivered it via REST into the real DM channel. Discord message history shows it:Greetings, my friend — may your path be as clear as the light of Eärendil.(msg id1575005241890439250).Remaining credentials (for Slack live E2E)
xoxb-/xapp-+ signing secret): signed webhook round-trip passes again — bad signature -> 403,url_verificationechoed,/help-> 200 via chat.postMessage path, regular message -> 200; and a full pipeline round-trip inside the live container passed (external_ref = slack:D0PR320SLACK1, runcompleted, reply stored, delivery listener attempted realchat.postMessagewhich Slack rejected withinvalid_auth— exactly the fake-token boundary).SLACK_BOT_TOKEN(xoxb-) +SLACK_APP_TOKEN(xapp-, connections:write) +SLACK_SIGNING_SECRET. Blocked by the free plan's 10-app limit — an unused app must be deleted first (owner will clean up later).Not in this PR
Group channels, approval cards, and media attachments stay out of scope.