Add Telegram callback
This commit is contained in:
parent
f78baf0f68
commit
e1177d388d
|
@ -14,15 +14,18 @@ async def main():
|
||||||
try:
|
try:
|
||||||
matrix_client = \
|
matrix_client = \
|
||||||
matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID)
|
matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID)
|
||||||
|
|
||||||
matrix_client.add_event_callback(matrix_on_message,
|
matrix_client.add_event_callback(matrix_on_message,
|
||||||
matrix.RoomMessage)
|
matrix.RoomMessage)
|
||||||
|
|
||||||
await matrix_client.login(MATRIX_PASSWORD)
|
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:
|
finally:
|
||||||
if matrix_client:
|
if matrix_client:
|
||||||
await matrix_client.close()
|
await matrix_client.close()
|
||||||
|
@ -36,5 +39,8 @@ async def telegram_loop():
|
||||||
async def matrix_on_message(room, event):
|
async def matrix_on_message(room, event):
|
||||||
print(room, event, file=sys.stderr)
|
print(room, event, file=sys.stderr)
|
||||||
|
|
||||||
|
async def telegram_on_message(msg):
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
Reference in a new issue