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
1 changed files with 13 additions and 17 deletions

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