mirror of
https://github.com/caronc/apprise.git
synced 2024-11-22 08:04:02 +01:00
Telegram Silent Notification and Web Page Preview Controls Added (#466)
This commit is contained in:
parent
e8add7b95a
commit
ac7eb86185
@ -205,13 +205,23 @@ class NotifyTelegram(NotifyBase):
|
||||
'default': True,
|
||||
'map_to': 'detect_owner',
|
||||
},
|
||||
'silent': {
|
||||
'name': _('Silent Notification'),
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
},
|
||||
'preview': {
|
||||
'name': _('Web Page Preview'),
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
},
|
||||
'to': {
|
||||
'alias_of': 'targets',
|
||||
},
|
||||
})
|
||||
|
||||
def __init__(self, bot_token, targets, detect_owner=True,
|
||||
include_image=False, **kwargs):
|
||||
include_image=False, silent=None, preview=None, **kwargs):
|
||||
"""
|
||||
Initialize Telegram Object
|
||||
"""
|
||||
@ -229,6 +239,14 @@ class NotifyTelegram(NotifyBase):
|
||||
# Parse our list
|
||||
self.targets = parse_list(targets)
|
||||
|
||||
# Define whether or not we should make audible alarms
|
||||
self.silent = self.template_args['silent']['default'] \
|
||||
if silent is None else bool(silent)
|
||||
|
||||
# Define whether or not we should display a web page preview
|
||||
self.preview = self.template_args['preview']['default'] \
|
||||
if preview is None else bool(preview)
|
||||
|
||||
# if detect_owner is set to True, we will attempt to determine who
|
||||
# the bot owner is based on the first person who messaged it. This
|
||||
# is not a fool proof way of doing things as over time Telegram removes
|
||||
@ -513,7 +531,12 @@ class NotifyTelegram(NotifyBase):
|
||||
'sendMessage'
|
||||
)
|
||||
|
||||
payload = {}
|
||||
payload = {
|
||||
# Notification Audible Control
|
||||
'disable_notification': self.silent,
|
||||
# Display Web Page Preview (if possible)
|
||||
'disable_web_page_preview': not self.preview,
|
||||
}
|
||||
|
||||
# Prepare Email Message
|
||||
if self.notify_format == NotifyFormat.MARKDOWN:
|
||||
@ -717,6 +740,8 @@ class NotifyTelegram(NotifyBase):
|
||||
params = {
|
||||
'image': self.include_image,
|
||||
'detect': 'yes' if self.detect_owner else 'no',
|
||||
'silent': 'yes' if self.silent else 'no',
|
||||
'preview': 'yes' if self.preview else 'no',
|
||||
}
|
||||
|
||||
# Extend our parameters
|
||||
@ -800,6 +825,15 @@ class NotifyTelegram(NotifyBase):
|
||||
# Store our bot token
|
||||
results['bot_token'] = bot_token
|
||||
|
||||
# Silent (Sends the message Silently); users will receive
|
||||
# notification with no sound.
|
||||
results['silent'] = \
|
||||
parse_bool(results['qsd'].get('silent', False))
|
||||
|
||||
# Show Web Page Preview
|
||||
results['preview'] = \
|
||||
parse_bool(results['qsd'].get('preview', False))
|
||||
|
||||
# Include images with our message
|
||||
results['include_image'] = \
|
||||
parse_bool(results['qsd'].get('image', False))
|
||||
|
@ -5039,6 +5039,20 @@ TEST_URLS = (
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/?format=text', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
}),
|
||||
# Test Silent Settings
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/?silent=yes', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
}),
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/?silent=no', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
}),
|
||||
# Test Web Page Preview Settings
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/?preview=yes', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
}),
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/?preview=no', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
}),
|
||||
# Simple Message without image
|
||||
('tgram://123456789:abcdefg_hijklmnop/lead2gold/', {
|
||||
'instance': plugins.NotifyTelegram,
|
||||
|
Loading…
Reference in New Issue
Block a user