Files

35 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-12-25 19:42:32 +09:00
import time
2022-10-07 01:48:42 +09:00
import traceback
2025-12-25 19:42:32 +09:00
import requests
2022-10-07 01:48:42 +09:00
from telepot_mod import Bot
2022-10-06 14:39:25 +09:00
from . import logger
class SupportTelegram:
@classmethod
def send_telegram_message(cls, text, bot_token=None, chat_id=None, image_url=None, disable_notification=None):
try:
bot = Bot(bot_token)
if image_url is not None:
2025-12-25 19:42:32 +09:00
logger.debug(image_url)
for i in range(5):
if requests.get(image_url).status_code == 200:
break
else:
time.sleep(3)
try:
bot.sendPhoto(chat_id, image_url, disable_notification=disable_notification)
except Exception as e:
logger.error(f"Exception:{str(e)}")
logger.error(traceback.format_exc())
2022-10-06 14:39:25 +09:00
bot.sendMessage(chat_id, text, disable_web_page_preview=True, disable_notification=disable_notification)
return True
2025-12-25 19:42:32 +09:00
except Exception as e:
logger.error(f"Exception:{str(e)}")
2022-10-06 14:39:25 +09:00
logger.error(traceback.format_exc())
logger.debug('Chatid:%s', chat_id)
return False