Platform Adapters
Responsibility
Each platform (Telegram, Discord, Slack, Signal, WhatsApp, WeChat, QQ...) has an adapter that translates native platform events into the unified MessageEvent and translates unified send actions back into platform API calls. Adapters inherit BasePlatformAdapter and implement a few abstract methods. Adapters can come from the built-in gateway/platforms/ or from plugins in plugins/platforms/; both register via PlatformRegistry.
Key Files
class BasePlatformAdapter(ABC):2317— abstract base class for adaptersabstract methods send / send_draft:2983-3015— send interface subclasses must implementMessageType / ProcessingOutcome / MessageEvent:1737-1759— unified event modelCachedMedia:1638-1737— media cache (avoids re-upload)SendResult / EphemeralReply:1898-2068— send result and ephemeral replycommon send helpers:3173-3326—send_slash_confirm/send_clarify/send_typing/send_multiple_imagesgateway/platforms/ directory— signal / whatsapp_cloud / weixin / bluebubbles / yuanbao / qqbot...plugins/platforms/ directory— Telegram / Discord / Slack (as plugins)ADDING_A_PLATFORM.md— guide for adding a platformPlatformRegistry:162— registry (register / register_deferred / unregister)
Data Flow
- At startup
GatewayRunner(gateway/run.py:3029) brings up adapters via_start_one_profile_adapter:9389. - Adapters are looked up by name from
PlatformRegistry(gateway/platform_registry.py:162), supporting deferred loading (a cheap placeholder first; real import only when used). - Adapters listen for platform events, translate them into
MessageEvent:1759s, and hand them to_handle_message:9947. - When the agent produces streaming output, the adapter delivers it back to the platform via the unified interface (
send:3008/send_draft); media goes throughCachedMedia:1638. - Platform differences (message length, rich text, image limits) are absorbed inside the adapter; the gateway core is unaware.
Summary
Adapter = a translator between "platform dialect" and "unified event". Adding a platform only requires subclassing BasePlatformAdapter, implementing a few abstract methods, and registering — see gateway/platforms/ADDING_A_PLATFORM.md. Telegram/Discord/Slack go through the plugin path and are treated the same as built-in adapters.