platforms.matrix module
Matrix platform adapter using matrix-nio.
Wraps the matrix-nio AsyncClient and converts Matrix events into
IncomingMessage instances for the shared
MessageProcessor.
- async platforms.matrix.download_matrix_media(client, event)[source]
Download (and optionally decrypt) a media attachment from Matrix.
- Return type:
tuple[bytes, str, str]
- Parameters:
client (AsyncClient)
event (RoomMessageMedia | RoomEncryptedMedia)
- async platforms.matrix.save_matrix_credentials(credentials_file, homeserver, client)[source]
Persist Matrix login credentials (preserving extra keys like seeds).
- async platforms.matrix.load_matrix_credentials(credentials_file)[source]
Load previously saved Matrix credentials, or return
None.
- platforms.matrix.trust_all_devices(client)[source]
Mark every known device of every tracked user as trusted.
- Return type:
- Parameters:
client (nio.AsyncClient)
- async platforms.matrix.setup_cross_signing(client, password, credentials_file, saved_seeds=None)[source]
Generate cross-signing keys, upload them, and self-sign the device.
If saved_seeds is provided the keys are re-derived from persisted seeds instead of generating new ones. Seeds are persisted to credentials_file for future restarts.
- class platforms.matrix.MatrixPlatform(message_handler, *, homeserver, user_id, password='', store_path='nio_store', credentials_file='matrix_credentials.json', media_cache=None, config=None)[source]
Bases:
PlatformAdapterPlatform adapter for Matrix via matrix-nio.
- Parameters:
message_handler (
Callable[[IncomingMessage,PlatformAdapter],Awaitable[None]]) – Async callback that receivesIncomingMessageinstances.homeserver (
str) – Matrix homeserver URL.user_id (
str) – Matrix user ID for the bot.password (
str) – Password (only needed for first login).store_path (
str) – Path to the nio E2EE key store.credentials_file (
str) – Path to the JSON file for persisting login credentials.media_cache (MediaCache | None)
config (Config | None)
- __init__(message_handler, *, homeserver, user_id, password='', store_path='nio_store', credentials_file='matrix_credentials.json', media_cache=None, config=None)[source]
Initialize the instance.
- Parameters:
message_handler (
Callable[[IncomingMessage,PlatformAdapter],Awaitable[None]]) – The message handler value.homeserver (str)
user_id (str)
password (str)
store_path (str)
credentials_file (str)
media_cache (MediaCache | None)
config (Config | None)
- Return type:
None
- property is_running: bool
Check whether is running.
- Returns:
True on success, False otherwise.
- Return type:
- 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 file.