From e1177d388d163c22b27b9467d180be5a636585d1 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 8 Jan 2023 17:54:22 +0400 Subject: [PATCH] Add Telegram callback --- mirrortea/__main__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mirrortea/__main__.py b/mirrortea/__main__.py index d332195..b7f5f6d 100644 --- a/mirrortea/__main__.py +++ b/mirrortea/__main__.py @@ -14,15 +14,18 @@ async def main(): try: matrix_client = \ matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID) - matrix_client.add_event_callback(matrix_on_message, matrix.RoomMessage) - await matrix_client.login(MATRIX_PASSWORD) - telegram_client = telegram.Bot(token=TELEGRAM_BOT_TOKEN) + telegram_bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN) + telegram_dispatcher = telegram.Dispatcher(bot=telegram_bot) + telegram_dispatcher.register_message_handler(telegram_on_message) - await asyncio.gather(matrix_loop(matrix_client), telegram_loop()) + await asyncio.gather( + matrix_loop(matrix_client), + telegram_loop(), + ) finally: if matrix_client: await matrix_client.close() @@ -36,5 +39,8 @@ async def telegram_loop(): async def matrix_on_message(room, event): print(room, event, file=sys.stderr) +async def telegram_on_message(msg): + print(msg, file=sys.stderr) + if __name__ == '__main__': asyncio.run(main())