add source for telegram.py

This commit is contained in:
Jan Speller 2020-05-01 13:58:36 +02:00
parent c2aab648c8
commit ca81d86a1e
2 changed files with 19 additions and 0 deletions

BIN
plugin/.telegram.py.swp Normal file

Binary file not shown.

View file

@ -1,3 +1,4 @@
??? from here until ???END lines may have been inserted/deleted
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
@ -64,3 +65,21 @@ class BoswatchPlugin(PluginBase):
logging.exception("Error while sending Telegram Message")
except Exception as e:
logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance"""
msg = self.parseWildcards(self.config.get("message"))
for chatId in self.config.get("chatIds", default=[]):
try:
# Send Message via Telegram
logging.info("Sending message to " + chatId)
self.bot.send_message(chat_id=chatId, text=msg)
except Unauthorized:
logging.exception("Error while sending Telegram Message, please Check your api-key")
except (TimedOut, NetworkError):
logging.exception("Error while sending Telegram Message, please Check your connectivity")
except (BadRequest, TelegramError):
logging.exception("Error while sending Telegram Message")
except Exception as e:
logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))