Extend options for plugin Seven (#1301)

This commit is contained in:
André 2025-03-09 14:50:32 +01:00 committed by GitHub
parent 9bf45e415d
commit 5554360ad0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 3 deletions

View File

@ -34,7 +34,7 @@ import requests
import json import json
from .base import NotifyBase from .base import NotifyBase
from ..common import NotifyType from ..common import NotifyType
from ..utils.parse import is_phone_no, parse_phone_no from ..utils.parse import is_phone_no, parse_phone_no, parse_bool
from ..locale import gettext_lazy as _ from ..locale import gettext_lazy as _
@ -88,7 +88,7 @@ class NotifySeven(NotifyBase):
'targets': { 'targets': {
'name': _('Targets'), 'name': _('Targets'),
'type': 'list:string', 'type': 'list:string',
} },
}) })
# Define our template arguments # Define our template arguments
@ -96,9 +96,27 @@ class NotifySeven(NotifyBase):
'to': { 'to': {
'alias_of': 'targets', 'alias_of': 'targets',
}, },
'source': {
# Originating address,In cases where the rewriting of the sender's
# address is supported or permitted by the SMS-C. This is used to
# transmit the message, this number is transmitted as the
# originating address and is completely optional.
'name': _('Originating Address'),
'type': 'string',
'map_to': 'source',
},
'from': {
'alias_of': 'source',
},
'flash': {
'name': _('Flash'),
'type': 'bool',
'default': False,
},
}) })
def __init__(self, apikey, targets=None, **kwargs): def __init__(self, apikey, targets=None, source=None, flash=None,
**kwargs):
""" """
Initialize Seven Object Initialize Seven Object
""" """
@ -111,6 +129,11 @@ class NotifySeven(NotifyBase):
self.logger.warning(msg) self.logger.warning(msg)
raise TypeError(msg) raise TypeError(msg)
self.source = None \
if not isinstance(source, str) else source.strip()
self.flash = self.template_args['flash']['default'] \
if flash is None else bool(flash)
# Parse our targets # Parse our targets
self.targets = list() self.targets = list()
@ -162,6 +185,10 @@ class NotifySeven(NotifyBase):
'to': None, 'to': None,
'text': body, 'text': body,
} }
if self.source:
payload['from'] = self.source
if self.flash:
payload['flash'] = self.flash
# Create a copy of the targets list # Create a copy of the targets list
targets = list(self.targets) targets = list(self.targets)
while len(targets): while len(targets):
@ -246,8 +273,15 @@ class NotifySeven(NotifyBase):
Returns the URL built dynamically based on specified arguments. Returns the URL built dynamically based on specified arguments.
""" """
params = {
'flash': 'yes' if self.flash else 'no',
}
if self.source:
params['from'] = self.source
# Our URL parameters # Our URL parameters
params = self.url_parameters(privacy=privacy, *args, **kwargs) params = self.url_parameters(privacy=privacy, *args, **kwargs)
return '{schema}://{apikey}/{targets}/?{params}'.format( return '{schema}://{apikey}/{targets}/?{params}'.format(
schema=self.secure_protocol, schema=self.secure_protocol,
apikey=self.pprint(self.apikey, privacy, safe=''), apikey=self.pprint(self.apikey, privacy, safe=''),
@ -287,4 +321,16 @@ class NotifySeven(NotifyBase):
results['targets'] += \ results['targets'] += \
NotifySeven.parse_phone_no(results['qsd']['to']) NotifySeven.parse_phone_no(results['qsd']['to'])
# Support the 'from' and source variable
if 'from' in results['qsd'] and len(results['qsd']['from']):
results['source'] = \
NotifySeven.unquote(results['qsd']['from'])
elif 'source' in results['qsd'] and len(results['qsd']['source']):
results['source'] = \
NotifySeven.unquote(results['qsd']['source'])
results['flash'] = \
parse_bool(results['qsd'].get('flash', False))
return results return results

View File

@ -77,6 +77,22 @@ apprise_url_tests = (
# Our call to notify() under the hood will fail # Our call to notify() under the hood will fail
'notify_response': False, 'notify_response': False,
}), }),
('seven://{}/15551232000?from=apprise'.format('3' * 14), {
# valid number, utilizing the optional from= variable
'instance': NotifySeven,
}),
('seven://{}/15551232000?source=apprise'.format('3' * 14), {
# valid number, utilizing the optional source= variable (same as from)
'instance': NotifySeven,
}),
('seven://{}/15551232000?from=apprise&flash=true'.format('3' * 14), {
# valid number, utilizing the optional from= variable
'instance': NotifySeven,
}),
('seven://{}/15551232000?source=apprise&flash=true'.format('3' * 14), {
# valid number, utilizing the optional source= variable (same as from)
'instance': NotifySeven,
}),
) )