Add exception handling to Telegram bot

This commit is contained in:
Jan Tuomi
2017-10-16 11:21:16 +03:00
parent e358ff35ad
commit 41d4c4f2e4
+10 -3
View File
@@ -37,8 +37,15 @@ class KaehmyHandler:
for id in channels_started:
bot.sendMessage(id, 'Uusi kaehmy/New kaehmy! {} -> {}'.format(name, url))
kaehmy_handler = KaehmyHandler()
bot.message_loop(kaehmy_handler.handle)
logging.debug('Telepot listening...')
def main():
bot.message_loop(kaehmy_handler.handle)
logging.debug('Telepot listening...')
try:
bot.getMe()
main()
except Exception as ex:
logging.exception('Failed to create Telegram bot with token "{}"'.format(TOKEN))