From 21799116c5a895a7caeacd8afdfe437c4c2ef4f7 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Mon, 14 Sep 2020 12:46:45 +0200 Subject: [PATCH] Reworked the Telegram Agent code to include the "silent_message" option. Both cases are now managed and the alerts are being respected. Signed-off-by: Gianfranco --- plexpy/notifiers.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 74a7e8dc..89bbd18a 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # This file is part of Tautulli. # @@ -3398,25 +3398,29 @@ class TELEGRAM(Notifier): poster_filename = 'poster_{}.png'.format(pretty_metadata.parameters['rating_key']) files = {'photo': (poster_filename, poster_content, 'image/png')} - if len(text) > 1024: + max_caption = len(text) + + if max_caption > 1024: data['disable_notification'] = True + self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']), + data=data, files=files) + data.pop('disable_notification') #This prevents from alerting with 2 sounds Telegram when the Silent Message is OFF: one alert for the photo and the second one for the text else: data['caption'] = text.encode('utf-8') - - r = self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']), + if self.config['silent_message']: + data['disable_notification'] = True + self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']), data=data, files=files) - - if not data.pop('disable_notification', None): - return r + return data['text'] = (text[:4093] + (text[4093:] and '...')).encode('utf-8') - if self.config['silent_message']: - data['disable_notification'] = True - if self.config['disable_web_preview']: data['disable_web_page_preview'] = True + if self.config['silent_message']: + data['disable_notification'] = True + headers = {'Content-type': 'application/x-www-form-urlencoded'} return self.make_request('https://api.telegram.org/bot{}/sendMessage'.format(self.config['bot_token']),