gotify / server

A simple server for sending and receiving messages in real-time per WebSocket. (Includes a sleek web-ui)
https://gotify.net
Other
11.49k stars 639 forks source link

Ability to send notification using URL encoded string #740

Open GitStorageOne opened 2 days ago

GitStorageOne commented 2 days ago

Is your feature request related to a problem? Please describe. Some third party software does not provide option to configure request BODY.
I would like to bind a webhook event from UNIFI Protect 5 to Gotify.
Unfortunately, only headers are configurable.
So, Gotify returns HTTP 400.

Describe the solution you'd like Ability to specify message via URL parameters (with empty BODY) like so:
?msg="Some%20Url%20Encoded%20Message%2C%20like%20Doorbell%20RINGS%21"
(URL encoded string: Some Url Encoded Message, like Doorbell RINGS!)

Describe alternatives you've considered I deployed Graylog and configured UNIFI console to send Syslogs.
Unfortunately, Unifi Protect does not send events in a such way.

Additional context For simple static messages, URL parameter would be handy option.

eternal-flame-AD commented 2 days ago

You can write /message?token=xxx&message=test as a query parameter in an empty POST but the declared content type cannot be JSON otherwise how to interpret the request is not clear.

We cannot accept messages submitted via GET because that is a separate endpoint and semantically not HTTP compliant.

The easiest way is to write a plugin or some kind of proxy to translate the request. Here's a plugin I wrote myself for a similar requirement of translating webhooks.

On the long run to fully fix this issue (which seems to happen a lot) maybe I can write a plugin that provides gojq support on incoming messages to normalize it into gotify format?

GitStorageOne commented 2 days ago

You can write /message?token=xxx&message=test as a query parameter in an empty POST but the declared content type cannot be JSON otherwise how to interpret the request is not clear.

Thanks, I configured HTTP POST Request from the Unifi:
POST "/message?token=[masked]&message=RING", I get HTTP 400.
I suppose it happen because BODY is not empty, Unifi sends some json data.
One solution might be to ignore BODY if the message URL parameter is specified. Other options - intermediate web-server or Gotify plugin.

GitStorageOne commented 2 days ago

On the long run to fully fix this issue (which seems to happen a lot) maybe I can write a plugin that provides gojq support on incoming messages to normalize it into gotify format?

I'm not familiar with gojq, but if it allows us to use a script to transform the request, I think that would be a great solution.