mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -07:00
Merge pull request #1377 from JohnnyKing94/master
Added Silent Notification option for Telegram Agent
This commit is contained in:
commit
a8e0502b41
1 changed files with 20 additions and 6 deletions
|
@ -3373,6 +3373,7 @@ class TELEGRAM(Notifier):
|
||||||
_DEFAULT_CONFIG = {'bot_token': '',
|
_DEFAULT_CONFIG = {'bot_token': '',
|
||||||
'chat_id': '',
|
'chat_id': '',
|
||||||
'disable_web_preview': 0,
|
'disable_web_preview': 0,
|
||||||
|
'silent_notification': 0,
|
||||||
'html_support': 1,
|
'html_support': 1,
|
||||||
'incl_subject': 1,
|
'incl_subject': 1,
|
||||||
'incl_poster': 0
|
'incl_poster': 0
|
||||||
|
@ -3405,22 +3406,29 @@ class TELEGRAM(Notifier):
|
||||||
poster_filename = 'poster_{}.png'.format(pretty_metadata.parameters['rating_key'])
|
poster_filename = 'poster_{}.png'.format(pretty_metadata.parameters['rating_key'])
|
||||||
files = {'photo': (poster_filename, poster_content, 'image/png')}
|
files = {'photo': (poster_filename, poster_content, 'image/png')}
|
||||||
|
|
||||||
if len(text) > 1024:
|
max_caption = len(text)
|
||||||
|
|
||||||
|
if max_caption > 1024:
|
||||||
data['disable_notification'] = True
|
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:
|
else:
|
||||||
data['caption'] = text.encode('utf-8')
|
data['caption'] = text.encode('utf-8')
|
||||||
|
if self.config['silent_notification']:
|
||||||
r = self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']),
|
data['disable_notification'] = True
|
||||||
|
self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']),
|
||||||
data=data, files=files)
|
data=data, files=files)
|
||||||
|
return
|
||||||
if not data.pop('disable_notification', None):
|
|
||||||
return r
|
|
||||||
|
|
||||||
data['text'] = (text[:4093] + (text[4093:] and '...')).encode('utf-8')
|
data['text'] = (text[:4093] + (text[4093:] and '...')).encode('utf-8')
|
||||||
|
|
||||||
if self.config['disable_web_preview']:
|
if self.config['disable_web_preview']:
|
||||||
data['disable_web_page_preview'] = True
|
data['disable_web_page_preview'] = True
|
||||||
|
|
||||||
|
if self.config['silent_notification']:
|
||||||
|
data['disable_notification'] = True
|
||||||
|
|
||||||
headers = {'Content-type': 'application/x-www-form-urlencoded'}
|
headers = {'Content-type': 'application/x-www-form-urlencoded'}
|
||||||
|
|
||||||
return self.make_request('https://api.telegram.org/bot{}/sendMessage'.format(self.config['bot_token']),
|
return self.make_request('https://api.telegram.org/bot{}/sendMessage'.format(self.config['bot_token']),
|
||||||
|
@ -3468,6 +3476,12 @@ class TELEGRAM(Notifier):
|
||||||
'name': 'telegram_disable_web_preview',
|
'name': 'telegram_disable_web_preview',
|
||||||
'description': 'Disables automatic link previews for links in the message',
|
'description': 'Disables automatic link previews for links in the message',
|
||||||
'input_type': 'checkbox'
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'Enable Silent Notifications',
|
||||||
|
'value': self.config['silent_notification'],
|
||||||
|
'name': 'telegram_silent_notification',
|
||||||
|
'description': 'Send notifications silently without any alert sounds.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue