log telegram error but don't fail
This commit is contained in:
parent
6018def64d
commit
ae238c90f8
1 changed files with 21 additions and 13 deletions
|
@ -1,12 +1,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
import telegram
|
import telegram
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def send(msg, to=None, channel=None, preview_url=None, preview_title=None, preview_description=None, preview_image=None):
|
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)
|
bot = telegram.Bot(token=settings.TELEGRAM_TOKEN)
|
||||||
|
try:
|
||||||
if preview_image:
|
if preview_image:
|
||||||
asyncio.run(bot.send_photo(
|
asyncio.run(bot.send_photo(
|
||||||
chat_id=channel,
|
chat_id=channel,
|
||||||
|
@ -20,6 +24,10 @@ def send(msg, to=None, channel=None, preview_url=None, preview_title=None, previ
|
||||||
text=msg,
|
text=msg,
|
||||||
parse_mode='html'
|
parse_mode='html'
|
||||||
))
|
))
|
||||||
|
except:
|
||||||
|
logger.error("failed to send message to telegram: %s", msg, exc_info=True)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
||||||
|
|
Loading…
Reference in a new issue