1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-22 07:42:24 +00:00

cleanup of code

This commit is contained in:
Bart274 2020-01-31 14:38:38 +01:00 committed by evilhero
parent d96265d008
commit 7f44f4a278
No known key found for this signature in database
GPG key ID: 3E12C51E39D91142

View file

@ -340,25 +340,21 @@ class TELEGRAM:
else:
self.token = test_token
def notify(self, message, imageurl=None):
if imageurl:
def notify(self, message, imageUrl=None):
# Construct message
payload = {'chat_id': self.userid, 'text': message}
sendMethod = "sendMessage"
if imageUrl:
# Construct message
payload = {'chat_id': self.userid, 'caption': message, 'photo': imageurl}
payload = {'chat_id': self.userid, 'caption': message, 'photo': imageUrl}
sendMethod = "sendPhoto"
# Send message to user using Telegram's Bot API
try:
response = requests.post(self.TELEGRAM_API % (self.token, "sendPhoto"), json=payload, verify=True)
except Exception, e:
logger.info(u'Telegram notify failed: ' + str(e))
else:
# Construct message
payload = {'chat_id': self.userid, 'text': message}
# Send message to user using Telegram's Bot API
try:
response = requests.post(self.TELEGRAM_API % (self.token, "sendMessage"), json=payload, verify=True)
except Exception, e:
logger.info(u'Telegram notify failed: ' + str(e))
# Send message to user using Telegram's Bot API
try:
response = requests.post(self.TELEGRAM_API % (self.token, sendMethod), json=payload, verify=True)
except Exception as e:
logger.info('Telegram notify failed: ' + str(e))
# Error logging
sent_successfuly = True