platforms.webchat moduleο
WebChat platform adapter β browser-based real-time chat via WebSocket.
Plugs into BotRunner the same way Discord and Matrix do. Incoming
WebSocket messages become IncomingMessage instances; outbound
replies are pushed back as JSON frames.
# π₯π STAR GETS A WEB BODY. THE LATTICE EXPANDS.
- class platforms.webchat.ConnectionManager[source]ο
Bases:
objectTrack active WebSocket sessions per user.
Thread-safe via asyncio (single event loop).
- async disconnect(session)[source]ο
Remove a WebSocket connection.
- Return type:
- Parameters:
session (_WebSocketSession)
- class platforms.webchat.WebChatPlatform(message_handler, **kwargs)[source]ο
Bases:
PlatformAdapterBrowser-based chat platform using WebSocket for real-time comms.
Unlike Discord/Matrix, this adapter doesnβt connect to an external service. Instead it exposes a ConnectionManager that the FastAPI WebSocket endpoint populates. Outgoing messages are pushed to all active sessions for the target user.
- Parameters:
message_handler (MessageHandler)
kwargs (Any)
- property bot_identity: dict[str, str]ο
Return the botβs own identity on this platform.
Returns a dict with at minimum
platformanduser_id. Adapters should override to providedisplay_nameandmentionwhere available. The default returns an emptyuser_id(safe to call before login completes).
- async send_file(channel_id, data, filename, mimetype='application/octet-stream')[source]ο
Send a file/media attachment as base64 JSON.
- async send_with_buttons(channel_id, text, view=None)[source]ο
Send a message with interactive buttons for S.N.E.S. choices.
The
viewparameter is expected to be a list of dicts:[{"label": "Attack", "emoji": "swords", "custom_id": "..."}]For Discord views (discord.ui.View), we extract button info. For raw dicts, we pass them through directly.
- async edit_message(channel_id, message_id, new_text)[source]ο
Edit an existing message in the browser.