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

Can Firebase and Cache be disabled via the JSON payload? #1119

Open
stendler opened this issue May 26, 2024 · 6 comments
Open

Can Firebase and Cache be disabled via the JSON payload? #1119

stendler opened this issue May 26, 2024 · 6 comments
Labels
question This is a question

Comments

@stendler
Copy link

Question

The documentation explains how to disable firebase or message caching via http request headers.
But these are not listed in the corresponding table on publishing via JSON.

Is this just missing from the documentation or not implemented?
If not implemented, could the JSON payload be paired with the request headers?

Is there a simple way to test this? The message payload does not seem to include any hint about how these properties were set.

@stendler stendler added the question This is a question label May 26, 2024
@wunter8
Copy link
Contributor

wunter8 commented May 26, 2024

I'm pretty sure those parameters are not parsed in a JSON body (see

func (s *Server) transformBodyJSON(next handleFunc) handleFunc {
).

You can try including them, and if they're not supported, ntfy will reject the request as "invalid JSON".

You can also turn on debug logs on the server and see if things are written to the cache or forwarded to firebase

@stendler
Copy link
Author

That's the right code, thank you!

So this looks like adding them via headers in addition to the JSON message payload should work.

You can try including them, and if they're not supported, ntfy will reject the request as "invalid JSON".

I did send messages against ntfy.sh with "firebase": "no" in the JSON payload, and it did not get rejected (or rather the notification went through - not sure if there was a response with an error message).

@wunter8
Copy link
Contributor

wunter8 commented May 26, 2024

So this looks like adding them via headers in addition to the JSON message payload should work.

Sorry, I missed this question. Yes, you can definitely combine JSON body and HTTP headers.

I just did a quick test, and a JSON body with "cache":"no" was not rejected by the ntfy server, BUT it was written to the cache. So "cache" (and I'm pretty sure "firebase") needs to be included as a header right now and not in the JSON body

@stendler
Copy link
Author

Thanks for confirming!

Now the question would be: should firebase and cache be added to the JSON functionality? Looking at the code, this seems straightforward to implement, and I would create a PR for this.

@wunter8
Copy link
Contributor

wunter8 commented May 29, 2024

I'm not sure. I don't know what @binwiederhier's preferences are regarding fields in the JSON body vs fields in HTTP headers

@stendler
Copy link
Author

I've implemented it and opened a PR as an exercise :)

Feel free to close it, if the feature is not desired. Though, I believe, since the JSON API is intended as a workaround for apps that make it difficult or impossible to define http headers, that this change just completes the API.

ntfy/docs/publish.md

Lines 1082 to 1084 in 9d3fc20

For some integrations with other tools (e.g. [Jellyfin](https://jellyfin.org/), [overseerr](https://overseerr.dev/)),
adding custom headers to HTTP requests may be tricky or impossible, so ntfy also allows publishing the entire message
as JSON in the request body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This is a question
Projects
None yet
Development

No branches or pull requests

2 participants