1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/events/telegram_message.py

29 lines
833 B
Python
Raw Permalink Normal View History

2020-04-26 21:13:13 +00:00
import logging
import telegram
from typing import *
from royalnet.serf.telegram.telegramserf import TelegramSerf, escape
2020-08-21 00:34:29 +00:00
import royalnet.commands as rc
2020-04-26 21:13:13 +00:00
log = logging.getLogger(__name__)
2020-08-21 00:34:29 +00:00
class TelegramMessageEvent(rc.HeraldEvent):
2020-04-26 21:13:13 +00:00
name = "telegram_message"
async def run(self, chat_id, text, **kwargs) -> dict:
2020-08-21 00:34:29 +00:00
if not isinstance(self.parent, TelegramSerf):
raise rc.UnsupportedError()
2020-04-26 21:13:13 +00:00
# noinspection PyTypeChecker
2020-08-21 00:34:29 +00:00
serf: TelegramSerf = self.parent
2020-04-26 21:13:13 +00:00
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 {}