@dlandoncan you add notifications also for telegram?
Something like this
pip install python-telegram-bot
#############################
from telegram import Bot, InputFile
# Add the following function to send notifications to Telegram
def send_telegram_notification(token, chat_id, message, image_path=None):
bot = Bot(token)
# Check if an image is provided
if image_path:
# Send photo along with the message
with open(image_path, 'rb') as photo:
bot.send_photo(chat_id, photo, caption=message)
else:
# Send only the message
bot.send_message(chat_id, message)
# Modify the section where you read parameters from secrets or set them manually
if not param_dict['token'] or not param_dict['user']:
# read from secrets
secrets = read_secrets()
if not param_dict['token']:
param_dict['token'] = secrets.get('TELEGRAM_BOT_TOKEN') # Replace with your secret key
zmlog.Debug(1, "eid:{} Reading token from secrets".format(eid))
if not param_dict['user']:
param_dict['user'] = secrets.get('TELEGRAM_CHAT_ID') # Replace with your secret key
zmlog.Debug(1, "eid:{} Reading user from secrets".format(eid))
# Replace the Pushover-specific code with the Telegram notification code
param_dict['title'] = '{} Alarm ({})'.format(mname, eid)
param_dict['message'] = cause + datetime.now().strftime(' at %I:%M %p, %b-%d')
if event_type == 'event_end':
param_dict['title'] = 'Ended:' + param_dict['title']
disp_param_dict = param_dict.copy()
disp_param_dict['token'] = '<removed>'
disp_param_dict['user'] = '<removed>'
zmlog.Debug(1, "eid:{} Telegram payload: data={} files={}".format(eid, disp_param_dict, files))
send_telegram_notification(param_dict['token'], param_dict['user'], param_dict['message'], image_path)
zmlog.close()