server icon indicating copy to clipboard operation
server copied to clipboard

Update Message for ongoing tasks

Open newhinton opened this issue 4 years ago • 10 comments

Is your feature request related to a problem? Please describe. My backup-program creates multiple notifications. Currently each time a new state is reached, a new notification is created. This creates many single entries that can get quiet cluttered.

Describe the solution you'd like If an app creates a message, it should return the messageid. This messageid can then be used to update said message. The client simply acts as if a new message arrived, and removes the old one.

newhinton avatar Apr 20 '20 15:04 newhinton

This could be achieved by deleting the previous message before sending the new one. Adding a message already returns the message id.

http POST "https://p.example.org/message?token=Axxxxxxxxx&message=test" | jq .
{
  "id": 195,
  "appid": 3,
  "message": "test",
  "title": "title",
  "priority": 0,
  "date": "2020-04-20T18:36:51.08118495+02:00"
}

I don't think that many users need this, therefore I'm waiting for more user feedback for this feature.

jmattheis avatar Apr 20 '20 16:04 jmattheis

Oh yeah, i could have checked that.

I experimented with the delete command, but it does not work. I always get a 401 code. I have created the curl command with your swagger documentation (inclusive tokens and so on)

curl -X DELETE "https://domain.com/gotify/message/134" -H "accept: application/json" -H "X-Gotify-Key: cooltoken"

Do you know why this is wrong?

(i can send using the token, so the url and token should be valid)

newhinton avatar Apr 20 '20 17:04 newhinton

You need a client token to delete messages, application tokens are only allowed to send messages.

jmattheis avatar Apr 20 '20 17:04 jmattheis

Ah that was the error, now it works

newhinton avatar Apr 20 '20 17:04 newhinton

I wrote a small script that generally archieves what i want, with one (two) drawbacks.

The "problem" is that the clients do not get notified about deleted messages, they need to refresh before the deleted messages (and their notifications) vanish. This basically results in a cleaned history, but does not fix the problem i am facing.

The second thing is, and this is not really important but to keep in mind, you need an app token and a client token

The script if anyone is interested: https://gist.github.com/newhinton/a53541611f181863384652726ee049eb

newhinton avatar Apr 20 '20 18:04 newhinton

See https://github.com/gotify/server/issues/266

jmattheis avatar Apr 20 '20 19:04 jmattheis

I like this idea. I have very similar use cases.

sik0vny avatar May 07 '20 10:05 sik0vny

I think it would make sense if applications could delete their own messages:

  • To me it was quite surprising that they can't: I spend quite a while figuring out why DELETE returned 401 before discovering it needs a client token.
  • If you want to give a script delete access, it needs a client token. But that gives it access to all messages. With application tokens the server could check that the message actually belongs to the application that wants to modify it.

(Being able to update messages using PUT seems neater than DELETE+POST, but I'm having a hard time coming up with actual scenarios where deleting+posting a new message wouldn't work. I guess you could use it to show that some alarm has been resolved without having it pop back to the top of al messages?)

rigrig avatar Apr 12 '21 15:04 rigrig

i would not like my applications to be able to delete sent notifications

najtin avatar Apr 12 '21 21:04 najtin

This could be achieved by deleting the previous message before sending the new one. Adding a message already returns the message id.

http POST "https://p.example.org/message?token=Axxxxxxxxx&message=test" | jq .
{
  "id": 195,
  "appid": 3,
  "message": "test",
  "title": "title",
  "priority": 0,
  "date": "2020-04-20T18:36:51.08118495+02:00"
}

I don't think that many users need this, therefore I'm waiting for more user feedback for this feature.

Such update API exists in Telegram which is quite handy, example of the use case is Frigate NVR event:

  1. When object is detected - initial notification sent with snapshot
  2. Frigate detection processing is finished and final snapshot created with detected object
  3. Previous notification message (with saved ID) is updated with new snapshot

lezruk avatar Mar 25 '24 22:03 lezruk