Add Telegram callback

This commit is contained in:
Alex Kotov 2023-01-08 17:54:22 +04:00
parent f78baf0f68
commit e1177d388d
No known key found for this signature in database
GPG key ID: 553C0EBBEB5D5F08

View file

@ -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())