def sendToTelegram(self):
session = SessionManager.get()
TELEGRAM_BASE_URL = "https://api.telegram.org/bot{token}/sendVenue".format(token=conf.TELEGRAM_BOT_TOKEN)
title = self.name
try:
minutes, seconds = divmod(self.tth, 60)
description = 'Expires at: {} ({:.0f}m{:.0f}s left)'.format(self.expire_time, minutes, seconds)
except AttributeError:
description = "It'll expire between {} & {}.".format(self.min_expire_time, self.max_expire_time)
try:
title += ' ({}/{}/{})'.format(self.attack, self.defense, self.stamina)
except AttributeError:
pass
payload = {
'chat_id': conf.TELEGRAM_CHAT_ID,
'latitude': self.coordinates[0],
'longitude': self.coordinates[1],
'title' : title,
'address' : description,
}
try:
async with session.post(TELEGRAM_BASE_URL, data=payload) as resp:
self.log.info('Sent a Telegram notification about {}.', self.name)
return True
except ClientResponseError as e:
self.log.error('Error {} from Telegram: {}', e.code, e.message)
except ClientError as e:
self.log.error('{} during Telegram notification.', e.__class__.__name__)
except CancelledError:
raise
except Exception:
self.log.exception('Exception caught in Telegram notification.')
return False
评论列表
文章目录