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

Actionable notifications #119

Closed
webworxshop opened this issue Jan 23, 2019 · 19 comments
Closed

Actionable notifications #119

webworxshop opened this issue Jan 23, 2019 · 19 comments
Labels
question Further information is requested

Comments

@webworxshop
Copy link

This looks like a really cool project and something I've been looking for for a while.

Please correct me if I'm wrong on this but from the documentation it doesn't look like you support actionable notifications i.e. notifications containing one or two buttons underneath which perform the respective action when clicked.

An example use case of this is that my home automation system may send a notification telling me that I left my garage door open and provide a button to close the door.

I think the simplest/most flexible way to implement the action part would be via a webhook, so the sending application would need to specify both the label text and a callback URL for when the action is clicked.

Thanks again for the great project.

@jmattheis
Copy link
Member

Hey @webworxshop,

you're right, something like this doesn't exist. Currently links should already be clickable in the android app, so you could just add plain links to the message.

This could partly be fixed with adding markdown support to messages (#65 (comment)) then it would be possible to add links with labels to the message.

Do you think this is enough for your usecase?

@jmattheis jmattheis added the question Further information is requested label Jan 24, 2019
@webworxshop
Copy link
Author

Hi @jmattheis,

Thanks for your reply. Yes, having markdown support in messages, plus clickable links would give a mostly workable solution, but I foresee a couple of problems:

  1. Links in the text are likely to be less user friendly to users already familiar with the action buttons used in Android notifications
  2. Clicking the link would presumably open the URL in the default web browser. If the URL is a webhook to an existing system then either the user will see a blank page or (worse) a JSON response from the server. In either case they need to close the page to go back to what they were doing. Also, clicking the link would not dismiss the notification, which an action button would typically do.

For reference, I'm basically looking for something to replace the HTML5 Push Notifications in Home Assistant (https://www.home-assistant.io/components/notify.html5/), but without the dependency on Google Cloud Messaging.

Thanks again for getting back to me.

@mavaa
Copy link

mavaa commented Sep 1, 2019

Hello,

Not knowing very much about Android notifications, I wonder if this would make it possible to open links in other apps than the browser? I'm trying to set up my gotify server as a complete replacement of the one provided by google, IE. my server would be connected to my Discord account, and when I receive a message it would send a gotify notification to my phone.

What I would like is to have the notification open Discord on my phone when clicked (if it's installed). Would that be related to this issue, or should I open a new request for it?

@daniele-athome
Copy link

I agree with the downsides explained by @webworxshop. Link-based (i.e. directly in text) actions is a no-go, at least for this specific use case. Actions are designed to interact with the application owning the notification. This should be handled in a specialized way IMHO.

@sonicnkt
Copy link

stumbled upon this issue when i was looking into gotify to completely selfhost my notifications (mainly for home automation stuff but also other local events on my systems).


Actionable Notifications would be really nice to have like @webworxshop described.

Maybe a solution would be to use a websocket api for this, it seems a ws endoint for all messages is allready implemented (https://gotify.net/api-docs#/message/streamMessages).

How about creating an additional ws endpoint like /events with a json payload including appid, date and eventid.
Then you could configure nodered for example to listen to this ws endpoint for certain events.

Message could be created including actions (buttons) and appropriate eventid's in message extras:

http -f POST "https://push.example.de/message?token=<apptoken>" title="Radiator left on" message="Nobody is home but the radiator was left one, should it be turned off? " priority="5"

{
  "extras": {
    "actions": {
      "action": { "name": "Yes", "eventid": "turnoff_radiators" },
      "action": { "name": "No", dismiss-notification? }
    }
  }
}

This should then render buttons in the notification with with the specified name and underlying action

The action/button "No" will just dismiss the notification, but clicking on "Yes" will fire the event on the Websocket /events endpoint:

{
  "appid": 5,
  "date": "2018-02-27T19:36:10.5045044+01:00",
  "event-id": "turnoff_radiators"
}

Then in node-red you can listen for the specific turnoff_radiators eventid and take appropriate actions....


I have no idea how hard this would be to implement using gotify but it would be a good solution imo.

@jmattheis
Copy link
Member

How about creating an additional ws endpoint like /events with a json payload including appid, date and eventid.
Then you could configure nodered for example to listen to this ws endpoint for certain events.

I don't really see the benefit in this, you could also send a normal message with extra json data, no need for an extra endpoint for this. The existing https://gotify.net/docs/msgextras were added exactly for this.

The difficult part is to define the what and how it should be defined inside the extras

@sonicnkt
Copy link

I don't really see the benefit in this, you could also send a normal message with extra json data, no need for an extra endpoint for this. The existing https://gotify.net/docs/msgextras were added exactly for this.

Well you are correct, the proposed new api endpoint isnt really necessary and its only for the callbacks from the actions/buttons. This could be done through /stream as well with another payload name so you can easily filter normal messages and callbacks.

And yes, messages with actions/buttons/callbacks should be created like normal with those actions defined in using the messaging extras, maybe my description was a bit complicated.


I will try to summerize my idea again a bit better:

  1. Implement actions in messages using using msgextras, you specify a name and eventid.
{
  "extras": {
    "actions": {
      "action": { "name": "Yes", "eventid": "turnoff_radiators" },
      "action": { "name": "No", dismiss-notification? }
    }
  }
}
  1. These actions will be rendered as buttons in the push notifications on the device. Clicking on one of those buttons will fire a callback json-payload through /stream so you can easily filter between normal messages and callbacks
{
  "appid": 5,
  "date": "2018-02-27T19:36:10.5045044+01:00",
  ...
  "callback": {
    "eventid": "turnoff_radiators
    }
} 
  1. Using nodered for example you could then subscribe to this endpoint and filter for callbacks and based on the eventid take appropriate actions.

Something like this would be very versatile...

@jmattheis
Copy link
Member

Right, I'm okay, with action buttons inside actions, but I don't think they should send events itself but rather do http requests to the relevant services to do stuff. This would be a more direct approach to solve this.

@sonicnkt
Copy link

sonicnkt commented Jan 24, 2021

The idea of letting gotify sending those events and not talking to the relevant services directly comes from my personal situation that i have a quite a few services i dont want to open up to the public www and are only reachable through a vpn connection from outside my lan. But since im not using the vpn connection all the time i would need to establish the connection just to use those actions in the notifications.

Implementing something like i proposed would allow to communicate with those services on my private network, as gotify is the only public service and my local services are just listening for gotifys callback events.

Another solution would be to implement my own publicly available event service that i could talk to from the outside but this would then also need some kind of authentication system etc. Since gotify allready handels authentication it would be a single and versitile solution

Anyway, it is not my project and i just wanted to propose an idea how to handle actions. I can understand and respect if this is not the direction you prefer :)

@jmattheis
Copy link
Member

Alright, thanks for your explanation, I think it is too specialized to your use-case, I try to keep gotify as simple as possible (:.

@ktracer-isp
Copy link

Right, I'm okay, with action buttons inside actions, but I don't think they should send events itself but rather do http requests to the relevant services to do stuff. This would be a more direct approach to solve this.

Hey, @jmattheis , is there any status on adding this as a feature ot Gotify, or are you looking for someone to pick up this work? I'm looking to write a notification manager that uses Gotify as its last-mile provider, and I would love to be able to add callback buttons to notifications to indicate whether I did the thing or need another reminder, so for a notification like "Take out trash", I'd like to be able to add callbacks like, e.g.:

{
  "extras": {
    "actions": {
      "action": { "name": "Done", "uri": "https://example.com/myfeedback?eventId=foo&resp=complete" },
      "action": { "name": "Delay", "uri": "https://example.com/myfeedback?eventId=foo&resp=resend_1h"},
      "action": { "name": "Dismiss", "uri": "https://example.com/myfeedback?eventId=foo&resp=cancel"},
    }
  }
}

I don't expect Gotify to manage the contents of either name or uri, just to provide me a means to set those values so when I click the button, it sends the call and dismisses the notification. Also, I'm happy to help with the feature work if it'll make it get taken up faster. I just need to know where to start digging into the code.

@ktracer-isp
Copy link

Alternatively, is there documentation on how to put multiple links in a notification using current configuration?

@jmattheis
Copy link
Member

Sure, you can use markdown -> https://gotify.net/docs/msgextras#clientdisplay

@Literorrery
Copy link

I finally got around to attempting this, and I've got some success.

I have code that passes a link through successfully to a notification -- see https://github.com/Literorrery/autoforge/blob/main/autoforge.go#L24-L33 for example -- but what I've found is that though this creates a link on the notification on my phone, when I view the same notification on WearOS, it doesn't render the markdown as a link. I'm guessing that's because currently Gotify doesn't have a WearOS client, so any notification created will be shared as a RemoteView, not with a native client.

So I suppose the next question is whether there's any appetite for a WearOS Gotify client and whether you're looking for people to help with that effort.

@jmattheis
Copy link
Member

Feel free to write a WearOS client :P.

@xiaolei0125
Copy link

is there any status on adding actionable notifications to Gotify?

@jmattheis
Copy link
Member

Well, "adding actionable notifications" is a pretty broad topic. Some actions do already exist on the android client, see https://gotify.net/docs/msgextras#androidaction if you want something different / new, then you probably should create an issue for this.

@GHRoss
Copy link

GHRoss commented Feb 28, 2022

Does anyone have any API request examples using message extras? The docs aren't that clear (to me, at least).

@jmattheis
Copy link
Member

Close in favor of #494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

9 participants