apprise-microservice icon indicating copy to clipboard operation
apprise-microservice copied to clipboard

Add deduplication feature by tracking id and state of notifications

Open 0x0aNL opened this issue 3 years ago • 0 comments

Signed-off-by: Roderik van Heijst [email protected]

I came across apprise-microservice through resticker (thank you very much for both!). For our use case, I wanted resticker to inform us when a backup failed, and then inform us later if the same host made a successful backup. In other words, notify on state change - with the additional requirement that failures should always result in notifications.

This small addition to app.py allows one to do so (if desired) by sending an id field along with body and title, and optionally a state field. When a notification with an id field is received, the current state (either sent along or comprised out of body and title) is compared to the last state for that id. If the state is identical and there is no forceSend field, the microservice will not send the notification and respond with deduplicated instead of ok.

If no id field is sent, the microservice works as usual.

Example without state field

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup successful", "body":"body"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup successful", "body":"body"}'
deduplicated

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup failed", "body":"body", "forceSend": "true"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup failed", "body":"body", "forceSend": "true"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup successful", "body":"body"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "title":"Backup successful", "body":"body"}'
deduplicated

Example with state field

curl -X POST notify:5000 --data '{"id":"backup", "state": "good", "title":"Backup successful at 01:00", "body":"body"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "state": "good", "title":"Backup successful at 02:00", "body":"body"}'
deduplicated

curl -X POST notify:5000 --data '{"id":"backup", "state": "bad", "title":"Backup failed at 03:00", "body":"body", "forceSend": "true"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "state": "bad", "title":"Backup failed at 04:00", "body":"body", "forceSend": "true"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "state": "good", "title":"Backup successful at 05:00", "body":"body"}'
ok

curl -X POST notify:5000 --data '{"id":"backup", "state": "good", "title":"Backup successful at 06:00", "body":"body"}'
deduplicated

0x0aNL avatar May 13 '21 11:05 0x0aNL