mirror of https://github.com/caronc/apprise
Added contributions file and docs for Matrix support; refs #28
parent
892a505b9c
commit
da902c228c
|
@ -0,0 +1,21 @@
|
||||||
|
# Contributions to the apprise project
|
||||||
|
|
||||||
|
## Creator & Maintainer
|
||||||
|
|
||||||
|
* Chris Caron <lead2gold@gmail.com>
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
The following users have contributed to this project and their deserved
|
||||||
|
recogition has been identified here. If you have contributed and wish
|
||||||
|
to be acknowledged for it, the syntax is as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
* [Your name or handle] <[email or website]>
|
||||||
|
* [Month Year] - [Brief summary of your contribution]
|
||||||
|
```
|
||||||
|
|
||||||
|
The contributors have been listed in alphabetical order:
|
||||||
|
|
||||||
|
* Wim de With <wf@dewith.io>
|
||||||
|
* Dec 2018 - Added Matrix Support
|
6
README
6
README
|
@ -62,6 +62,12 @@ The table below identifies the services this tool supports and some example serv
|
||||||
kodi://user@hostname
|
kodi://user@hostname
|
||||||
kodi://user:password@hostname:port
|
kodi://user:password@hostname:port
|
||||||
|
|
||||||
|
* Matrix
|
||||||
|
matrix://token
|
||||||
|
matrix://user@token
|
||||||
|
matrixs://token?mode=slack
|
||||||
|
matrixs://user@token?mode=matrix
|
||||||
|
|
||||||
* Mattermost
|
* Mattermost
|
||||||
mmost://hostname/authkey
|
mmost://hostname/authkey
|
||||||
mmost://hostname:80/authkey
|
mmost://hostname:80/authkey
|
||||||
|
|
|
@ -37,6 +37,7 @@ The table below identifies the services this tool supports and some example serv
|
||||||
| [IFTTT](https://github.com/caronc/apprise/wiki/Notify_ifttt) | ifttt:// | (TCP) 443 | ifttt://webhooksID/EventToTrigger<br />ifttt://webhooksID/EventToTrigger/Value1/Value2/Value3<br />ifttt://webhooksID/EventToTrigger/?Value3=NewEntry&Value2=AnotherValue
|
| [IFTTT](https://github.com/caronc/apprise/wiki/Notify_ifttt) | ifttt:// | (TCP) 443 | ifttt://webhooksID/EventToTrigger<br />ifttt://webhooksID/EventToTrigger/Value1/Value2/Value3<br />ifttt://webhooksID/EventToTrigger/?Value3=NewEntry&Value2=AnotherValue
|
||||||
| [Join](https://github.com/caronc/apprise/wiki/Notify_join) | join:// | (TCP) 443 | join://apikey/device<br />join://apikey/device1/device2/deviceN/<br />join://apikey/group<br />join://apikey/groupA/groupB/groupN<br />join://apikey/DeviceA/groupA/groupN/DeviceN/
|
| [Join](https://github.com/caronc/apprise/wiki/Notify_join) | join:// | (TCP) 443 | join://apikey/device<br />join://apikey/device1/device2/deviceN/<br />join://apikey/group<br />join://apikey/groupA/groupB/groupN<br />join://apikey/DeviceA/groupA/groupN/DeviceN/
|
||||||
| [KODI](https://github.com/caronc/apprise/wiki/Notify_kodi) | kodi:// or kodis:// | (TCP) 8080 or 443 | kodi://hostname<br />kodi://user@hostname<br />kodi://user:password@hostname:port
|
| [KODI](https://github.com/caronc/apprise/wiki/Notify_kodi) | kodi:// or kodis:// | (TCP) 8080 or 443 | kodi://hostname<br />kodi://user@hostname<br />kodi://user:password@hostname:port
|
||||||
|
| [Matrix](https://github.com/caronc/apprise/wiki/Notify_matrix) | matrix:// | (TCP) 443 | matrix://token<br />matrix://user@token<br />matrixs://token?mode=slack<br />matrixs://user@token
|
||||||
| [Mattermost](https://github.com/caronc/apprise/wiki/Notify_mattermost) | mmost:// | (TCP) 8065 | mmost://hostname/authkey<br />mmost://hostname:80/authkey<br />mmost://user@hostname:80/authkey<br />mmost://hostname/authkey?channel=channel<br />mmosts://hostname/authkey<br />mmosts://user@hostname/authkey<br />
|
| [Mattermost](https://github.com/caronc/apprise/wiki/Notify_mattermost) | mmost:// | (TCP) 8065 | mmost://hostname/authkey<br />mmost://hostname:80/authkey<br />mmost://user@hostname:80/authkey<br />mmost://hostname/authkey?channel=channel<br />mmosts://hostname/authkey<br />mmosts://user@hostname/authkey<br />
|
||||||
| [Prowl](https://github.com/caronc/apprise/wiki/Notify_prowl) | prowl:// | (TCP) 443 | prowl://apikey<br />prowl://apikey/providerkey
|
| [Prowl](https://github.com/caronc/apprise/wiki/Notify_prowl) | prowl:// | (TCP) 443 | prowl://apikey<br />prowl://apikey/providerkey
|
||||||
| [Pushalot](https://github.com/caronc/apprise/wiki/Notify_pushalot) | palot:// | (TCP) 443 | palot://authorizationtoken
|
| [Pushalot](https://github.com/caronc/apprise/wiki/Notify_pushalot) | palot:// | (TCP) 443 | palot://authorizationtoken
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# Matrix WebHook Notify Wrapper
|
# Matrix WebHook Notify Wrapper
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018 Chris Caron <lead2gold@gmail.com>, Wim de With <wf@dewith.io>
|
# Copyright (C) 2018-2019 Chris Caron <lead2gold@gmail.com>
|
||||||
#
|
#
|
||||||
# This file is part of apprise.
|
# This file is part of apprise.
|
||||||
#
|
#
|
||||||
|
@ -30,8 +30,6 @@ from time import time
|
||||||
|
|
||||||
from .NotifyBase import NotifyBase
|
from .NotifyBase import NotifyBase
|
||||||
from .NotifyBase import HTTP_ERROR_MAP
|
from .NotifyBase import HTTP_ERROR_MAP
|
||||||
from ..common import NotifyImageSize
|
|
||||||
from ..utils import compat_is_basestring
|
|
||||||
|
|
||||||
# Token required as part of the API request
|
# Token required as part of the API request
|
||||||
VALIDATE_TOKEN = re.compile(r'[A-Za-z0-9]{64}')
|
VALIDATE_TOKEN = re.compile(r'[A-Za-z0-9]{64}')
|
||||||
|
@ -45,15 +43,18 @@ MATRIX_HTTP_ERROR_MAP.update({
|
||||||
403: 'Unauthorized - Invalid Token.',
|
403: 'Unauthorized - Invalid Token.',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class MatrixNotificationMode(object):
|
class MatrixNotificationMode(object):
|
||||||
SLACK = 0
|
SLACK = "slack"
|
||||||
MATRIX = 1
|
MATRIX = "matrix"
|
||||||
|
|
||||||
|
|
||||||
MATRIX_NOTIFICATION_MODES = (
|
MATRIX_NOTIFICATION_MODES = (
|
||||||
MatrixNotificationMode.SLACK,
|
MatrixNotificationMode.SLACK,
|
||||||
MatrixNotificationMode.MATRIX,
|
MatrixNotificationMode.MATRIX,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NotifyMatrix(NotifyBase):
|
class NotifyMatrix(NotifyBase):
|
||||||
"""
|
"""
|
||||||
A wrapper for Matrix Notifications
|
A wrapper for Matrix Notifications
|
||||||
|
@ -77,7 +78,7 @@ class NotifyMatrix(NotifyBase):
|
||||||
# The maximum allowable characters allowed in the body per message
|
# The maximum allowable characters allowed in the body per message
|
||||||
body_maxlen = 1000
|
body_maxlen = 1000
|
||||||
|
|
||||||
def __init__(self, token, mode=None, **kwargs):
|
def __init__(self, token, mode=MatrixNotificationMode.MATRIX, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize Matrix Object
|
Initialize Matrix Object
|
||||||
"""
|
"""
|
||||||
|
@ -90,10 +91,12 @@ class NotifyMatrix(NotifyBase):
|
||||||
self.schema = 'http'
|
self.schema = 'http'
|
||||||
|
|
||||||
if not isinstance(self.port, int):
|
if not isinstance(self.port, int):
|
||||||
self.notify_url = '%s://%s/api/v1/matrix/hook' % (self.schema, self.host)
|
self.notify_url = '%s://%s/api/v1/matrix/hook' % (
|
||||||
|
self.schema, self.host)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.notify_url = '%s://%s:%d/api/v1/matrix/hook' % (self.schema, self.host, self.port)
|
self.notify_url = '%s://%s:%d/api/v1/matrix/hook' % (
|
||||||
|
self.schema, self.host, self.port)
|
||||||
|
|
||||||
if not VALIDATE_TOKEN.match(token.strip()):
|
if not VALIDATE_TOKEN.match(token.strip()):
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
|
@ -111,12 +114,10 @@ class NotifyMatrix(NotifyBase):
|
||||||
'No user was specified; using %s.' % MATRIX_DEFAULT_USER)
|
'No user was specified; using %s.' % MATRIX_DEFAULT_USER)
|
||||||
self.user = MATRIX_DEFAULT_USER
|
self.user = MATRIX_DEFAULT_USER
|
||||||
|
|
||||||
if not mode:
|
if mode not in MATRIX_NOTIFICATION_MODES:
|
||||||
self.logger.warning(
|
self.logger.warning('The mode specified (%s) is invalid.' % mode)
|
||||||
'No mode was specified, using Slack mode')
|
raise TypeError('The mode specified (%s) is invalid.' % mode)
|
||||||
self.mode = MatrixNotificationMode.SLACK
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
||||||
self._re_formatting_map = {
|
self._re_formatting_map = {
|
||||||
|
@ -159,7 +160,7 @@ class NotifyMatrix(NotifyBase):
|
||||||
self.token,
|
self.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.mode is MatrixNotificationMode.MATRIX:
|
if self.mode == MatrixNotificationMode.MATRIX:
|
||||||
payload = self.__matrix_mode_payload(title, body, notify_type)
|
payload = self.__matrix_mode_payload(title, body, notify_type)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -188,8 +189,7 @@ class NotifyMatrix(NotifyBase):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'Failed to send Matrix '
|
'Failed to send Matrix '
|
||||||
'notification (error=%s).' %
|
'notification (error=%s).' % r.status_code)
|
||||||
r.status_code)
|
|
||||||
|
|
||||||
# Return; we're done
|
# Return; we're done
|
||||||
notify_okay = False
|
notify_okay = False
|
||||||
|
@ -254,13 +254,7 @@ class NotifyMatrix(NotifyBase):
|
||||||
results['token'] = NotifyBase.unquote(results['query'])
|
results['token'] = NotifyBase.unquote(results['query'])
|
||||||
|
|
||||||
if 'mode' in results['qsd'] and len(results['qsd']['mode']):
|
if 'mode' in results['qsd'] and len(results['qsd']['mode']):
|
||||||
_map = {
|
results['mode'] = results['qsd']\
|
||||||
'slack': MatrixNotificationMode.SLACK,
|
.get('mode', MatrixNotificationMode.MATRIX).lower()
|
||||||
'matrix': MatrixNotificationMode.MATRIX,
|
|
||||||
}
|
|
||||||
try:
|
|
||||||
results['mode'] = _map[results['qsd']['mode'].lower()]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -579,7 +579,7 @@ TEST_URLS = (
|
||||||
}),
|
}),
|
||||||
# Name, port, token and invalid mode
|
# Name, port, token and invalid mode
|
||||||
('matrix://user@localhost:9000/%s?mode=foo' % ('a' * 64), {
|
('matrix://user@localhost:9000/%s?mode=foo' % ('a' * 64), {
|
||||||
'instance': plugins.NotifyMatrix,
|
'instance': TypeError,
|
||||||
}),
|
}),
|
||||||
('matrix://user@localhost:9000/%s?mode=slack' % ('a' * 64), {
|
('matrix://user@localhost:9000/%s?mode=slack' % ('a' * 64), {
|
||||||
'instance': plugins.NotifyMatrix,
|
'instance': plugins.NotifyMatrix,
|
||||||
|
|
Loading…
Reference in New Issue