Expand description
Platform-agnostic messaging abstraction for COMP-004 (multi-platform gateway: Telegram, Slack, Matrix, plus the existing Discord/PWA).
Today the Discord adapter (src/discord.rs) and PWA web server
(src/web_server.rs) each speak directly to the agent loop with
platform-specific event types. Adding Telegram (COMP-004b) without
a trait would mean copying ~1400 lines of Discord handler glue and
diverging the per-platform behavior over time.
The MessagingAdapter trait is the contract Telegram + Slack +
Matrix adapters implement. The Discord/PWA adapters keep their
current implementations and ship a thin shim that exposes them
through this trait — see [DiscordShim] for an example.
§Design
-
IncomingMessage— platform-agnostic representation of a user-sent message. Capabilities (DM vs channel, attachments, thread context) carried as fields rather than per-platform enums so adapters with weaker features just leave fields empty. -
MessagingAdapter— the impl-this trait. Three core methods:start()spins up the platform’s event loop;send_reply()answers in the original channel/thread;send_dm()reaches the user privately for approval prompts / session events. The trait isSend + Syncso the agent loop can hand a shared reference to multiple tools. -
MessagingHub— owns N adapters and routes outbound traffic based on the channel-id namespacing (telegram:chat-123,discord:guild-456:channel-789, …). Wire-only piece — adapters don’t talk to each other.
§Out of scope for COMP-004a (this commit)
- Migrating
src/discord.rsinternals to use the trait.DiscordShimis sufficient for the COMP-004a acceptance (“Discord implements MessagingAdapter”) without rewriting 1400 lines. - The actual Telegram/Slack adapters — those are COMP-004b/c.
- Approval-flow surface (request_approval) — sketched as a TODO here so the API doesn’t churn when COMP-004b adds it.
Structs§
- Incoming
Message - A user-sent message, normalized across platforms.
- Messaging
Hub - Routes outbound messages to the right adapter based on channel_id prefix. Held as an Arc so it can be cloned across tasks.
- Outgoing
Message - What the agent needs to send back to the user. Same shape regardless of platform — the adapter does the format/layout.
Enums§
Traits§
- Messaging
Adapter - The trait every platform adapter implements.