more improvements

pull/1347/head
Chris Caron 2025-06-10 16:29:19 -04:00
parent d2753402a1
commit fa50113ac1
1 changed files with 56 additions and 24 deletions

View File

@ -44,11 +44,24 @@ class NotifyClickatell(NotifyBase):
A wrapper for Clickatell Notifications A wrapper for Clickatell Notifications
""" """
# The default descriptive name associated with the Notification
service_name = _('Clickatell') service_name = _('Clickatell')
# The services URL
service_url = 'https://www.clickatell.com/' service_url = 'https://www.clickatell.com/'
# All notification requests are secure
secure_protocol = 'clickatell' secure_protocol = 'clickatell'
# A URL that takes you to the setup/help of the specific protocol
setup_url = 'https://github.com/caronc/apprise/wiki/Notify_clickatell' setup_url = 'https://github.com/caronc/apprise/wiki/Notify_clickatell'
notify_url = 'https://platform.clickatell.com/messages/http/send?apiKey={}'
# Clickatell API Endpoint
notify_url = 'https://platform.clickatell.com/messages/http/send'
# A title can not be used for SMS Messages. Setting this to zero will
# cause any title (if defined) to get placed into the message body.
title_maxlen = 0
templates = ( templates = (
'{schema}://{apikey}/{targets}', '{schema}://{apikey}/{targets}',
@ -180,7 +193,9 @@ class NotifyClickatell(NotifyBase):
""" """
if not self.targets: if not self.targets:
self.logger.warning('There are no valid targets to notify.') # There were no targets to notify
self.logger.warning(
'There were no Clickatell targets to notify')
return False return False
headers = { headers = {
@ -189,21 +204,31 @@ class NotifyClickatell(NotifyBase):
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }
url = self.notify_url.format(self.apikey) params_base = {
if self.source: 'apiKey': self.apikey,
url += '&from={}'.format(self.source) 'from': self.source,
url += '&to={to}' 'content': body,
url += '&content={}'.format(' '.join([title, body])) }
# error tracking (used for function return)
has_error = False
for target in self.targets:
params = params_base.copy()
params['to'] = target
# Some Debug Logging
self.logger.debug('Clickatell GET URL: {} (cert_verify={})'.format(
self.notify_url, self.verify_certificate))
self.logger.debug('Clickatell Payload: {}' .format(params))
# Always call throttle before any remote server i/o is made # Always call throttle before any remote server i/o is made
self.throttle() self.throttle()
try: try:
for target in self.targets:
new_url = url.format(to=target)
self.logger.debug('Clickatell GET URL: %s', new_url)
r = requests.get( r = requests.get(
new_url, self.notify_url,
params=params,
headers=headers, headers=headers,
verify=self.verify_certificate, verify=self.verify_certificate,
timeout=self.request_timeout, timeout=self.request_timeout,
@ -223,17 +248,24 @@ class NotifyClickatell(NotifyBase):
self.logger.debug( self.logger.debug(
'Response Details:\r\n{}'.format(r.content)) 'Response Details:\r\n{}'.format(r.content))
return False # Mark our failure
has_error = True
continue
else: else:
self.logger.info('Sent Clickatell notification.') self.logger.info(
'Sent Clickatell notification to %s', target)
except requests.RequestException as e: except requests.RequestException as e:
self.logger.warning( self.logger.warning(
'A Connection error occurred sending Clickatell ' 'A Connection error occurred sending Clickatell: to %s ',
'notification to %s.' % self.host) target)
self.logger.debug('Socket Exception: %s' % str(e)) self.logger.debug('Socket Exception: %s' % str(e))
return False # Mark our failure
return True has_error = True
continue
return not has_error
@staticmethod @staticmethod
def parse_url(url): def parse_url(url):