From 435c5c9c36261a1f90c783b3f7cb015c79837919 Mon Sep 17 00:00:00 2001 From: flaskfarm Date: Thu, 6 Oct 2022 14:39:25 +0900 Subject: [PATCH] update --- lib/support/base/telegram.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/support/base/telegram.py diff --git a/lib/support/base/telegram.py b/lib/support/base/telegram.py new file mode 100644 index 0000000..70873c2 --- /dev/null +++ b/lib/support/base/telegram.py @@ -0,0 +1,31 @@ +from . import logger + + +class SupportTelegram: + + @classmethod + def send_telegram_message(cls, text, bot_token=None, chat_id=None, image_url=None, disable_notification=None): + from system.model import ModelSetting as SystemModelSetting + try: + if bot_token is None: + bot_token = SystemModelSetting.get('notify_telegram_token') + + if chat_id is None: + chat_id = SystemModelSetting.get('notify_telegram_chat_id') + + if disable_notification is None: + disable_notification = SystemModelSetting.get_bool('notify_telegram_disable_notification') + + bot = Bot(bot_token) + if image_url is not None: + #bot.sendPhoto(chat_id, text, caption=caption, disable_notification=disable_notification) + bot.sendPhoto(chat_id, image_url, disable_notification=disable_notification) + bot.sendMessage(chat_id, text, disable_web_page_preview=True, disable_notification=disable_notification) + #elif mime == 'video': + # bot.sendVideo(chat_id, text, disable_notification=disable_notification) + return True + except Exception as exception: + logger.error('Exception:%s', exception) + logger.error(traceback.format_exc()) + logger.debug('Chatid:%s', chat_id) + return False