sdr-enthusiasts / docker-planefence

GNU General Public License v3.0
96 stars 17 forks source link

[Enhancement] Send alert to push notification aggregator service #140

Open SingingDwarf opened 2 years ago

SingingDwarf commented 2 years ago

Suggestion for enhancement - send notifications to a self hosted push aggregator service, such as Apprise (https://github.com/caronc/apprise) which would allow users to send notifications to services of their choice, but with only a single integration point for this project to maintain.

kx1t commented 2 years ago

hey @SingingDwarf , thanks for the suggestion. In reality, we are working on changing the notification architecture for Planefence. PF and PA will call into a separate container that would do notifications.

At first sight, apprise may be interesting to use as the underlying notification engine, although I'd need to think a bit on the best way for the end user to switch notification methods on/off, and to provide the credentials needed for this.

As a MVP, we'd be looking to implement Twitter and Discord notifications. People have asked for MQTT as well, and it'd be interesting to enable some of the other ones.

Feel free to join a bunch of us at the #planefence channel on this Discord server where we discuss these things: https://discord.gg/VDT25xNZzV

kx1t commented 2 years ago

@SingingDwarf I have been playing with apprise, and it was easy to figure out how to send tweets. However, I'm struggling to find out how to upload images to be used with the tweet.

Currently, using twurl, you first upload the image and you get a json object that contains an Image ID that you subsequently reference in your tweet:

# upload the image and get a Media ID:
TW_MEDIA_ID=$(twurl -X POST -H upload.twitter.com "/1.1/media/upload.json" -f /tmp/snapshot.png -F media | sed -n 's/.*\"media_id\":\([0-9]*\).*/\1/p')
# Send a tweet and reference the Media ID to be used
LINK=$(echo `twurl -r "status=$TWEET&media_ids=$TW_MEDIA_ID" /1.1/statuses/update.json` | tee -a /tmp/tweets.log | jq '.entities."urls" | .[] | .url' | tr -d '\"')
# LINK now contains the URL of the tweet

I successfully sent a tweet with apprise like this:

apprise -b "#PlaneAlert ...insert body text here" twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet

I tried adding the media ID in the same request, didn't work. I tried to send the file attachment without body, and apprise complained of not having any text in the body:

apprise -a file:///run/notifier/screenshot/screenshot.png -b "#PlaneAlert ...insert body text here" twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet 

apprise -a file:///run/notifier/screenshot/screenshot.png twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet 

Do you have any idea how to get this done, or who I can ask?

kx1t commented 2 years ago

As a follow-up, I have been making progress implementing a separate notification-container that will use apprise. The author of that package has been very helpful making some minor additions to the package that, among other things, will show the result object from sending tweets, etc.

Progress is slow but forthcoming.

SingingDwarf commented 2 years ago

@kx1t Sorry for the radio silence on this, unfortunately 'life' has been in the way recently.

Is the work you refer to above using the NOTIFICATION_SERVER setting in the config file? I cannot find any documentation relating to this setting, so assume that it is new/undocumented feature currently?

Did you still require help on sending the attachement? It's a while since I looked into Apprise, but can take another look if it would be helpeful.

kimfr commented 1 year ago

@kx1t - is there any update on using Apprise? I'm looking to implement Telegram - currently using it in some scripts - rather easy as you just issue a curl command with token,api and message.

I would like plane-alert to send me a Telegram message whenever a new plane from the alert file is registered.

beercity commented 2 months ago

adding Ntfy (ntfy.sh) as an option would be great as well.