mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 02:26:58 -07:00
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 <gianfry94@hotmail.it>
This commit is contained in:
parent
81ee44b60f
commit
21799116c5
1 changed files with 14 additions and 10 deletions
|
@ -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']),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue