Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other notification platforms using plugins #1151

Closed
HellStorm666 opened this issue Oct 15, 2020 · 8 comments
Closed

Allow other notification platforms using plugins #1151

HellStorm666 opened this issue Oct 15, 2020 · 8 comments
Milestone

Comments

@HellStorm666
Copy link

HellStorm666 commented Oct 15, 2020

Please add Gotify as notification support.
Free, multi-platform and really easy to use notification system.

https://gotify.net/

with a simple HTTP post or curl messages are send.

$ curl "https://push.example.de/message?token=<apptoken>" -F "title=my title" -F "message=my message" -F "priority=5"
$ http -f POST "https://push.example.de/message?token=<apptoken>" title="my title" message="my message" priority="5"

For Powershell this method is working fine:
edit the url, api, prio from within the Notification page of DSMR.
fill the title and message with the DSRM message

> $url = "https://your.url"
> $api = "your_api"
> $prio = "5"
> $Data = @{
> 'title'= "Test";
> 'message'= "Dit is een test";
> 'priority'= $prio;
> }
> Invoke-WebRequest $url/message?token=$api -Method Post -Body $Data
@HellStorm666 HellStorm666 added the review Not sure yet whether to implement this label Oct 15, 2020
@dennissiemensma
Copy link
Member

Thanks for your suggestion. I might add other providers when enough users require it, but for now I'd suggest you'll just make it work by using a dedicated plugin for yourself: https://dsmr-reader.readthedocs.io/en/latest/plugins.html

@dennissiemensma
Copy link
Member

In order to easily allow you to do so I'll add a new hook/event in DSMR-reader 4.5 you can use. The plugin would then be a script such as:

dsmr_plugins/modules/relay_notification_to_gotify.py

import requests

from django.dispatch import receiver

from dsmr_notification.signals import notification_sent


@receiver(notification_sent)
def handle_notification_sent(sender, title, message, **kwargs):
    APP_TOKEN = '...'

    try:
        requests.post(
            'https://push.example.de/message?token={}'.format(APP_TOKEN),
            data=dict(
                title=title,
                message=message,
                priority=5,
            ),
            # A low timeout prevents DSMR-reader from hanging, when the remote server is unreachable.
            timeout=5
        )
    except Exception as error:
        print('handle_notification_sent:', error)

.env

DSMRREADER_PLUGINS=dsmr_plugins.modules.relay_notification_to_gotify

@dennissiemensma dennissiemensma removed the review Not sure yet whether to implement this label Oct 15, 2020
@dennissiemensma dennissiemensma added this to the 4.5 milestone Oct 15, 2020
@dennissiemensma dennissiemensma changed the title Gotify notification support Allow other notification platforms using plugins Oct 15, 2020
@dennissiemensma
Copy link
Member

You will also need to select a (new) Dummy-notification provider in the admin to ensure notifications are triggered without requiring another provider.

@dennissiemensma
Copy link
Member

Added to v4.5 release.

@HellStorm666
Copy link
Author

great thanks!

tried to make the dsmr_plugins/modules/relay_notification_to_gotify.py with the correct api and webaddress, and then add the DSMRREADER_PLUGINS=dsmr_plugins.modules.relay_notification_to_gotify in docker env.

But, DSMR_Reader doesn't start then, it crashes with an error in web-service.
Removing the env fixes it. But running the .py gives the error that notification service isnt know.
Enabling notification from the admin pannel and selecting just and, click save, doesnt save this.

@dennissiemensma
Copy link
Member

dennissiemensma commented Oct 15, 2020 via email

@dennissiemensma
Copy link
Member

Zojuist uitgebracht in v4.5

@HellStorm666
Copy link
Author

Tested it, and it works!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants