platforms package
Platform adapters for the multi-platform LLM bot.
- class platforms.Attachment(data, mimetype, filename, source_url='')[source]
Bases:
objectA downloaded media attachment, already in raw bytes.
- class platforms.IncomingMessage(platform, channel_id, user_id, user_name, text, is_addressed, attachments=<factory>, channel_name='', timestamp=<factory>, message_id='', reply_to_id='', extra=<factory>, reactions='')[source]
Bases:
objectPlatform-agnostic representation of an incoming chat message.
Platform adapters construct one of these for every event and pass it to the
MessageProcessor.- Parameters:
- attachments: list[Attachment]
Media attachments that have already been downloaded.
- class platforms.PlatformAdapter(message_handler)[source]
Bases:
ABCInterface that every platform must implement.
Subclasses wire up their SDK’s event loop, convert native events to
IncomingMessage, and forward them to the message_handler callback supplied at construction time.- Parameters:
message_handler (MessageHandler)
- __init__(message_handler)[source]
Initialize the instance.
- Parameters:
message_handler (
Callable[[IncomingMessage,PlatformAdapter],Awaitable[None]]) – The message handler value.- Return type:
None
- 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).
- abstractmethod async start()[source]
Connect to the service, authenticate, and begin listening.
- Return type:
- abstractmethod async send(channel_id, text)[source]
Send a plain-text message to channel_id.
Returns the platform message ID of the sent message, or
""if the send failed or the platform does not expose one.
- abstractmethod async send_file(channel_id, data, filename, mimetype='application/octet-stream')[source]
Send a file/media attachment to channel_id.
- Parameters:
channel_id (
str) – Platform-specific channel / room identifier.data (
bytes) – Raw file bytes.filename (
str) – Suggested filename for the attachment.mimetype (
str) – MIME type of the file (used for determining how to present the attachment on platforms that distinguish images, audio, video, and generic files).
- Returns:
A platform-specific content URL for the uploaded file (
mxc://on Matrix, CDN URL on Discord), orNoneif the upload failed.- Return type:
- async send_with_buttons(channel_id, text, view=None)[source]
Send a message with interactive buttons attached.
- Parameters:
- Return type:
strignore this and send plain text.
:param The default implementation falls back to
send().:
- async edit_message(channel_id, message_id, new_text)[source]
Edit an existing message sent by the bot.
- Parameters:
channel_id (
str) – Platform-specific channel / room identifier.message_id (
str) – Platform-specific ID of the message to edit.new_text (
str) – Replacement text content.success (Returns True on)
not (False if the platform does)
default (support editing or the operation failed. The)
False. (implementation is a no-op that returns)
- Return type:
- async start_typing(channel_id)[source]
Begin showing a typing indicator in channel_id.
Implementations should spawn a background task that periodically refreshes the indicator until
stop_typing()is called. The default implementation is a no-op.
- async stop_typing(channel_id)[source]
Stop showing the typing indicator in channel_id.
Must be safe to call even if
start_typing()was never called for the given channel. The default is a no-op.
- async fetch_history(channel_id, limit=100)[source]
Fetch recent messages from the platform for channel_id.
Returns up to limit messages in chronological order (oldest first). The default implementation returns an empty list; platform adapters should override when the underlying SDK supports history retrieval.
- Return type:
- Parameters:
- async get_channel_webhooks(channel_id)[source]
Return webhooks configured for channel_id.
The default implementation returns an empty list. Platform adapters that support webhooks (e.g. Discord) should override.
- async list_servers_and_channels()[source]
Return all servers/guilds and their channels.
Each platform adapter should override this to return a list of dicts describing servers/guilds (or rooms) the bot is active in, along with their channels. The format is platform-specific but should include at minimum
server_name,server_id, andchannels(a list of channel dicts).The default implementation returns an empty list.
Submodules
- platforms.base module
AttachmentIncomingMessageIncomingMessage.platformIncomingMessage.channel_idIncomingMessage.user_idIncomingMessage.user_nameIncomingMessage.textIncomingMessage.is_addressedIncomingMessage.attachmentsIncomingMessage.channel_nameIncomingMessage.timestampIncomingMessage.message_idIncomingMessage.reply_to_idIncomingMessage.extraIncomingMessage.reactions
HistoricalMessagePlatformAdapterPlatformAdapter.__init__()PlatformAdapter.namePlatformAdapter.is_runningPlatformAdapter.bot_identityPlatformAdapter.start()PlatformAdapter.stop()PlatformAdapter.send()PlatformAdapter.send_file()PlatformAdapter.send_with_buttons()PlatformAdapter.edit_message()PlatformAdapter.start_typing()PlatformAdapter.stop_typing()PlatformAdapter.fetch_history()PlatformAdapter.get_channel_webhooks()PlatformAdapter.list_servers_and_channels()PlatformAdapter.get_guild_members()
- platforms.discord module
DiscordPlatformDiscordPlatform.__init__()DiscordPlatform.lyria_serviceDiscordPlatform.nameDiscordPlatform.is_runningDiscordPlatform.clientDiscordPlatform.bot_identityDiscordPlatform.start()DiscordPlatform.stop()DiscordPlatform.send()DiscordPlatform.send_file()DiscordPlatform.edit_message()DiscordPlatform.send_with_buttons()DiscordPlatform.start_typing()DiscordPlatform.stop_typing()DiscordPlatform.get_guild_members()DiscordPlatform.list_servers_and_channels()DiscordPlatform.get_channel_webhooks()DiscordPlatform.fetch_history()
- platforms.discord_self module
- platforms.emoji_resolver module
- platforms.matrix module
download_matrix_media()save_matrix_credentials()load_matrix_credentials()trust_all_devices()setup_cross_signing()MatrixPlatformMatrixPlatform.__init__()MatrixPlatform.nameMatrixPlatform.is_runningMatrixPlatform.bot_identityMatrixPlatform.start()MatrixPlatform.stop()MatrixPlatform.send()MatrixPlatform.send_file()MatrixPlatform.start_typing()MatrixPlatform.stop_typing()MatrixPlatform.list_servers_and_channels()MatrixPlatform.fetch_history()
- platforms.media_common module
- platforms.webchat module
ConnectionManagerWebChatPlatformWebChatPlatform.nameWebChatPlatform.is_runningWebChatPlatform.bot_identityWebChatPlatform.start()WebChatPlatform.stop()WebChatPlatform.send()WebChatPlatform.send_file()WebChatPlatform.send_with_buttons()WebChatPlatform.edit_message()WebChatPlatform.start_typing()WebChatPlatform.stop_typing()WebChatPlatform.create_sse_queue()WebChatPlatform.remove_sse_queue()WebChatPlatform.fetch_history()