feat: support shared-workspace file flow for matrix

This commit is contained in:
Mikhail Putilovskij 2026-04-21 00:26:21 +03:00
parent 323a6d3144
commit 6422c7db58
18 changed files with 871 additions and 80 deletions

View file

@ -13,7 +13,12 @@ from nio import (
InviteMemberEvent,
MatrixRoom,
RoomMemberEvent,
RoomMessage,
RoomMessageAudio,
RoomMessageFile,
RoomMessageImage,
RoomMessageText,
RoomMessageVideo,
)
from nio.responses import SyncResponse
@ -227,19 +232,6 @@ class MatrixBot:
incoming,
)
await self._stage_attachments(room.room_id, sender, materialized.attachments)
await self._send_all(
room.room_id,
[
OutgoingMessage(
chat_id=dispatch_chat_id,
text=await self._format_staged_attachments(
room.room_id,
sender,
include_hint=True,
),
)
],
)
return
if isinstance(incoming, IncomingMessage) and incoming.attachments:
incoming = await self._materialize_incoming_attachments(
@ -276,12 +268,12 @@ class MatrixBot:
await self._send_all(room.room_id, outgoing)
def _is_file_only_event(
self, event: RoomMessageText, incoming: IncomingMessage | IncomingCommand
self, event: RoomMessage, incoming: IncomingMessage | IncomingCommand
) -> bool:
return (
isinstance(incoming, IncomingMessage)
and bool(incoming.attachments)
and getattr(event, "msgtype", None) != "m.text"
and not isinstance(event, RoomMessageText)
)
async def _stage_attachments(
@ -669,7 +661,16 @@ async def main() -> None:
since_token = await prepare_live_sync(client)
bot = MatrixBot(client, runtime)
client.add_event_callback(bot.on_room_message, RoomMessageText)
client.add_event_callback(
bot.on_room_message,
(
RoomMessageText,
RoomMessageFile,
RoomMessageImage,
RoomMessageVideo,
RoomMessageAudio,
),
)
client.add_event_callback(bot.on_member, (InviteMemberEvent, RoomMemberEvent))
logger.info(