-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored handling of remapping (+completed test coverage)
- Loading branch information
Showing
6 changed files
with
189 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,7 +210,7 @@ curl -X POST \ | |
http://localhost:8000/notify | ||
``` | ||
|
||
### Persistent Storage Solution | ||
### Persistent (Stateful) Storage Solution | ||
|
||
You can pre-save all of your Apprise configuration and/or set of Apprise URLs and associate them with a `{KEY}` of your choosing. Once set, the configuration persists for retrieval by the `apprise` [CLI tool](https://github.com/caronc/apprise/wiki/CLI_Usage) or any other custom integration you've set up. The built in website with comes with a user interface that you can use to leverage these API calls as well. Those who wish to build their own application around this can use the following API end points: | ||
|
||
|
@@ -512,3 +512,47 @@ a.add(config) | |
a.notify('test message') | ||
``` | ||
|
||
## Third Party Webhook Support | ||
It can be understandable that third party applications can't always publish the format expected by this API tool. To work-around this, you can re-map the fields just before they're processed. For example; consider that we expect the follow minimum payload items for a stateful notification: | ||
```json | ||
{ | ||
"body": "Message body" | ||
} | ||
``` | ||
|
||
But what if your tool you're using is only capable of sending: | ||
```json | ||
{ | ||
"subject": "My Title", | ||
"payload": "My Body" | ||
} | ||
``` | ||
|
||
We would want to map `subject` to `title` in this case and `payload` to `body`. This can easily be done using the `:` (colon) argument when we prepare our payload: | ||
|
||
```bash | ||
# Note the keyword arguments prefixed with a `:` (colon). These | ||
# instruct the API to map the payload (which we may not have control over) | ||
# to align with what the Apprise API expects. | ||
# | ||
# We also convert `subject` to `title` too: | ||
curl -X POST \ | ||
-F "subject=Mesage Title" \ | ||
-F "payload=Message Body" \ | ||
"http://localhost:8000/notify/{KEY}?:subject=title&:payload=body" | ||
|
||
``` | ||
|
||
Here is the JSON Version and tests out the Stateless query (which requires at a minimum the `urls` and `body`: | ||
```bash | ||
# We also convert `subject` to `title` too: | ||
curl -X POST -d '{"href": "mailto://user:[email protected]", "subject":"My Title", "payload":"Body"}' \ | ||
-H "Content-Type: application/json" \ | ||
"http://localhost:8000/notify/{KEY}?:subject=title&:payload=body&:href=urls" | ||
``` | ||
|
||
The colon `:` prefix is the switch that starts the re-mapping rule engine. You can do 3 possible things with the rule engine: | ||
1. `:existing_key=expected_key`: Rename an existing (expected) payload key to one Apprise expects | ||
1. `:existing_key=`: By setting no value, the existing key is simply removed from the payload entirely | ||
1. `:expected_key=A value to give it`: You can also fix an expected apprise key to a pre-generated string value. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,39 @@ def test_notify(self, mock_notify): | |
# Reset our mock object | ||
mock_notify.reset_mock() | ||
|
||
form_data = { | ||
'payload': '## test notification', | ||
'fmt': apprise.NotifyFormat.MARKDOWN, | ||
'extra': 'mailto://user:[email protected]', | ||
} | ||
|
||
# We sent the notification successfully (use our rule mapping) | ||
# FORM | ||
response = self.client.post( | ||
f'/notify/?:payload=body&:fmt=format&:extra=urls', | ||
form_data) | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
mock_notify.reset_mock() | ||
|
||
form_data = { | ||
'payload': '## test notification', | ||
'fmt': apprise.NotifyFormat.MARKDOWN, | ||
'extra': 'mailto://user:[email protected]', | ||
} | ||
|
||
# We sent the notification successfully (use our rule mapping) | ||
# JSON | ||
response = self.client.post( | ||
'/notify/?:payload=body&:fmt=format&:extra=urls', | ||
json.dumps(form_data), | ||
content_type="application/json") | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
mock_notify.reset_mock() | ||
|
||
# Long Filename | ||
attach_data = { | ||
'attachment': SimpleUploadedFile( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters