2023-08-16 15:21:32 +00:00
|
|
|
import asyncio
|
2023-08-21 21:06:01 +00:00
|
|
|
import logging
|
2023-08-16 15:21:32 +00:00
|
|
|
|
|
|
|
import telegram
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
2023-08-21 21:06:01 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2023-08-16 15:21:32 +00:00
|
|
|
|
|
|
|
def send(msg, to=None, channel=None, preview_url=None, preview_title=None, preview_description=None, preview_image=None):
|
|
|
|
bot = telegram.Bot(token=settings.TELEGRAM_TOKEN)
|
2023-08-21 21:06:01 +00:00
|
|
|
try:
|
|
|
|
if preview_image:
|
|
|
|
asyncio.run(bot.send_photo(
|
|
|
|
chat_id=channel,
|
|
|
|
caption=msg,
|
|
|
|
photo=preview_image,
|
|
|
|
parse_mode='html'
|
|
|
|
))
|
|
|
|
else:
|
|
|
|
asyncio.run(bot.send_message(
|
|
|
|
chat_id=channel,
|
|
|
|
text=msg,
|
2023-09-02 10:08:26 +00:00
|
|
|
parse_mode='html',
|
|
|
|
disable_web_page_preview=True
|
2023-08-21 21:06:01 +00:00
|
|
|
))
|
|
|
|
except:
|
|
|
|
logger.error("failed to send message to telegram: %s", msg, exc_info=True)
|
|
|
|
return False
|
|
|
|
return True
|
2023-08-16 15:21:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
|
|
|
pass
|