From 5554360ad0b7d627dbfc8b1b441eaa8998bac76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sun, 9 Mar 2025 14:50:32 +0100 Subject: [PATCH] Extend options for plugin Seven (#1301) --- apprise/plugins/seven.py | 52 ++++++++++++++++++++++++++++++++++++--- test/test_plugin_seven.py | 16 ++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/apprise/plugins/seven.py b/apprise/plugins/seven.py index 2536647f..c6174b48 100644 --- a/apprise/plugins/seven.py +++ b/apprise/plugins/seven.py @@ -34,7 +34,7 @@ import requests import json from .base import NotifyBase 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 _ @@ -88,7 +88,7 @@ class NotifySeven(NotifyBase): 'targets': { 'name': _('Targets'), 'type': 'list:string', - } + }, }) # Define our template arguments @@ -96,9 +96,27 @@ class NotifySeven(NotifyBase): 'to': { '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 """ @@ -111,6 +129,11 @@ class NotifySeven(NotifyBase): self.logger.warning(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 self.targets = list() @@ -162,6 +185,10 @@ class NotifySeven(NotifyBase): 'to': None, 'text': body, } + if self.source: + payload['from'] = self.source + if self.flash: + payload['flash'] = self.flash # Create a copy of the targets list targets = list(self.targets) while len(targets): @@ -246,8 +273,15 @@ class NotifySeven(NotifyBase): 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 params = self.url_parameters(privacy=privacy, *args, **kwargs) + return '{schema}://{apikey}/{targets}/?{params}'.format( schema=self.secure_protocol, apikey=self.pprint(self.apikey, privacy, safe=''), @@ -287,4 +321,16 @@ class NotifySeven(NotifyBase): results['targets'] += \ 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 diff --git a/test/test_plugin_seven.py b/test/test_plugin_seven.py index 4298bfc8..6f742a23 100644 --- a/test/test_plugin_seven.py +++ b/test/test_plugin_seven.py @@ -77,6 +77,22 @@ apprise_url_tests = ( # Our call to notify() under the hood will fail '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, + }), )