1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/royalpack/events/telegram_message.py
2020-08-21 02:34:29 +02:00

28 lines
833 B
Python

import logging
import telegram
from typing import *
from royalnet.serf.telegram.telegramserf import TelegramSerf, escape
import royalnet.commands as rc
log = logging.getLogger(__name__)
class TelegramMessageEvent(rc.HeraldEvent):
name = "telegram_message"
async def run(self, chat_id, text, **kwargs) -> dict:
if not isinstance(self.parent, TelegramSerf):
raise rc.UnsupportedError()
# noinspection PyTypeChecker
serf: TelegramSerf = self.parent
log.debug("Forwarding message from Herald to Telegram.")
await serf.api_call(serf.client.send_message,
chat_id=chat_id,
text=escape(text),
parse_mode="HTML",
disable_web_page_preview=True)
return {}