summaryrefslogtreecommitdiffhomepage
path: root/libs/apprise/plugins/NotifyMSG91.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/apprise/plugins/NotifyMSG91.py')
-rw-r--r--libs/apprise/plugins/NotifyMSG91.py47
1 files changed, 17 insertions, 30 deletions
diff --git a/libs/apprise/plugins/NotifyMSG91.py b/libs/apprise/plugins/NotifyMSG91.py
index 68176fb93..f32ad8181 100644
--- a/libs/apprise/plugins/NotifyMSG91.py
+++ b/libs/apprise/plugins/NotifyMSG91.py
@@ -31,18 +31,15 @@
# Get details on the API used in this plugin here:
# - https://world.msg91.com/apidoc/textsms/send-sms.php
-import re
import requests
from .NotifyBase import NotifyBase
from ..common import NotifyType
-from ..utils import parse_list
+from ..utils import is_phone_no
+from ..utils import parse_phone_no
from ..utils import validate_regex
from ..AppriseLocale import gettext_lazy as _
-# Some Phone Number Detection
-IS_PHONE_NO = re.compile(r'^\+?(?P<phone>[0-9\s)(+-]+)\s*$')
-
class MSG91Route(object):
"""
@@ -207,33 +204,18 @@ class NotifyMSG91(NotifyBase):
# Parse our targets
self.targets = list()
- for target in parse_list(targets):
+ for target in parse_phone_no(targets):
# Validate targets and drop bad ones:
- result = IS_PHONE_NO.match(target)
- if result:
- # Further check our phone # for it's digit count
- result = ''.join(re.findall(r'\d+', result.group('phone')))
- if len(result) < 11 or len(result) > 14:
- self.logger.warning(
- 'Dropped invalid phone # '
- '({}) specified.'.format(target),
- )
- continue
-
- # store valid phone number
- self.targets.append(result)
+ result = is_phone_no(target)
+ if not result:
+ self.logger.warning(
+ 'Dropped invalid phone # '
+ '({}) specified.'.format(target),
+ )
continue
- self.logger.warning(
- 'Dropped invalid phone # '
- '({}) specified.'.format(target),
- )
-
- if not self.targets:
- # We have a bot token and no target(s) to message
- msg = 'No MSG91 targets to notify.'
- self.logger.warning(msg)
- raise TypeError(msg)
+ # store valid phone number
+ self.targets.append(result['full'])
return
@@ -242,6 +224,11 @@ class NotifyMSG91(NotifyBase):
Perform MSG91 Notification
"""
+ if len(self.targets) == 0:
+ # There were no services to notify
+ self.logger.warning('There were no MSG91 targets to notify.')
+ return False
+
# Prepare our headers
headers = {
'User-Agent': self.app_id,
@@ -365,6 +352,6 @@ class NotifyMSG91(NotifyBase):
# The 'to' makes it easier to use yaml configuration
if 'to' in results['qsd'] and len(results['qsd']['to']):
results['targets'] += \
- NotifyMSG91.parse_list(results['qsd']['to'])
+ NotifyMSG91.parse_phone_no(results['qsd']['to'])
return results