Use Apprise for notifications

alextruppel2 years ago

(I know this has been mentioned before, but it was 4 years ago and there was no meaningful reply...)

Has apprise been considered for notification services? I have a Telegram bot set up, but ideally I'd use the Signal API. And I'm sure many other users of Traccar would like to use other notification services as well. So, would this be something to integrate into Traccar in the future?

Thank you!

Anton Tananaev2 years ago

Is there an API documentation on how to integrate it?

alextruppel2 years ago

Note: although Apprise supports many services, I believe an implementation ino Traccar could be actually quite simple. It would be one more notification channel (like Telegram, Web, etc) called Apprise and the configuration of this channel would contain just a single URL. So, for example, the config URL could be "signal://apprise-server:apprise-port/etc...". But since Apprise can also be configured beforehand (when running in a docker container for example), there is a way to have a single config URL call multiple services: for example "apprise://apprise-server:apprise-port/apprise?tags=all" calls all configured services. So, my point is, the full capability of Apprise (including sending notifications to multiple services at once) can be enabled with a single notification channel called Apprise in the user interface and a single URL in the config file.

alextruppel2 years ago

Let me see if I can find something about that.

alextruppel2 years ago

So after a cursory look, it seems there are a few options:

  1. the user has an Apprise server running already (my case, for example), in which case sending a notification from Traccar's perspective is as simple as a web request, for example: curl -X POST -d "tag=ABCD&body=test message" http://apprise-server:apprise-port/notify/key
    In this case, the Traccar's config file only needs to contain the info above, that is, ip and port of the Apprise server, the apprise "key" which indicates which Apprise config file to use, and the apprise tag "ABCD" which tells apprise which notifications from the config to send. Tag "all" for example, sends all notifications configured in the chosen config file. (see more)

  2. the user installs the apprise command line tool and Traccar calls the CLI. Similar to above, see more here. An apprise config file can be specified, in this case perhaps the path to the config file would be a good option for the traccar config.xml.

  3. the Apprise library is embedded in Traccar, in which case the user does not need to configure anything external because Traccar will have the functionality already. Perhaps a config file for apprise could be specified in Traccar's config.xml, but there would otherwise be no need for the user to install anything extra.

Anton Tananaev2 years ago

I think you should be able to use the option 1 as an SMS configuration.

alextruppel2 years ago

Hmm interesting. I see, sms also sends web requests directly. I'll try that and get back to you.

alextruppel2 years ago

I can confirm that running the following command inside the Traccar docker container works:

curl -X POST -d '{"tag": "all", "title": "Traccar", "body":"test message"}' -H "Content-Type: application/json" http://apprise:8000/notify/apprise

But the with the following in the config.xml file

<entry key='sms.http.url'>http://apprise:8000/notify/apprise</entry>
<entry key='sms.http.template'>
    {
        "tag": "all",
        "title": "Traccar"
        "body": "{message}"
    }
</entry>

(and pressing "Test Channels") the notification is not sent. Am I missing something?

Anton Tananaev2 years ago

At least the header is missing.

alextruppel2 years ago

Which header? Content-Type: application/json ?
I thought, looking at the code, that it was detected automatically and sent as json?

Anton Tananaev2 years ago

Actually I see a syntax error in your JSON. You're missing a comma after the title.

alextruppel2 years ago

Silly me, you're right. Unfortunately, it's still not working. This is what I have currently:

    <entry key='sms.http.url'>http://apprise:8000/notify/apprise</entry>
    <entry key='sms.http.template'>{"tag": "all", "title": "Traccar", "body":"test message"}</entry>

And Test Channels does not send a message.

alextruppel2 years ago

Also tried

    <entry key='sms.http.url'>http://apprise:8000/notify/apprise</entry>
    <entry key='sms.http.template'>tag=all&amp;title=Traccar&amp;body={message}</entry>

with no luck.

alextruppel2 years ago

(note: I wrote "& amp;" above but it's being wrongly formatted)

Anton Tananaev2 years ago

Two last ideas:

  1. Add content type
  2. Check Wireshark to see the request and response