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

Allow sending custom properties in POSTed JSON #827

Open
tka85 opened this issue Aug 1, 2023 · 9 comments
Open

Allow sending custom properties in POSTed JSON #827

tka85 opened this issue Aug 1, 2023 · 9 comments
Labels
android-app ntfy Android app enhancement New feature or request server Relates to the main binary (server or client)

Comments

@tka85
Copy link

tka85 commented Aug 1, 2023

💡 Idea
When publishing a notification using JSON, it would be useful to allow sending additional custom properties which will be forwarded verbatim to the mobile front end (assuming one uses a self-hosted ntfy server and builds their own mobile app). These additional properties could be nested under the toplevel "extras" property in the POSTed JSON.

💻 Target components
This is a feature request for the ntfy server.

Example:

{
  "topic": "1234", 
  // existing properties
  "message": "foo",
  "title": "bar",
  // additional custom properties
  "extras": {
    "customField": "baz"
  }
}
@tka85 tka85 added the enhancement New feature or request label Aug 1, 2023
@wunter8
Copy link
Contributor

wunter8 commented Aug 1, 2023

What would be the goal of this? Why not just send a custom JSON string as the body of the notification?

@tka85
Copy link
Author

tka85 commented Aug 2, 2023

The ntfy server currently only understands predefined properties in the POSTed JSON. Added custom properties do not get forwarded to the frontend. Use case is for self-hosted nfty servers with a custom frontend that needs fields beyond the known message, title etc.

This is the relevant discussion with @binwiederhier .

@wunter8
Copy link
Contributor

wunter8 commented Aug 2, 2023

I understand what you're asking for (and I agree with binwiederhier that it'd probably be easy to implement), but I don't understand why sending an (escaped) JSON string as the body of the message doesn't work. If you're already building a custom frontend, then you don't need to use any of ntfy's existing fields (except to get your JSON string out).

The current ntfy response looks like this:

{ 
   "id":"fajyTv5FQ0iM",
   "time":1690985276,
   "expires":1691028476,
   "event":"message",
   "topic":"test",
   "message":"testing"
}

You want to change it to this:

{ 
   "id":"fajyTv5FQ0iM",
   "time":1690985276,
   "expires":1691028476,
   "event":"message",
   "topic":"test",
   "message":"testing"
    "extras": {
        "customField": "value"
    }
}

Then, after data = resp.json(), you could access the custom value at data.extras.customField

Why not do this?

{ 
   "id":"fajyTv5FQ0iM",
   "time":1690985276,
   "expires":1691028476,
   "event":"message",
   "topic":"test",
   "message":"\"{\"message\": \"testing\", \"customField\": \"value\"}\""
}

Then, after data = resp.json().message.json(), you could access the custom value at data.customField, right?

@tka85
Copy link
Author

tka85 commented Aug 3, 2023

Just opened the issue because as @binwiederhier suggested
(a) this was something he had already considered doing before and
(b) the implementation is easy

Yes, what you propose would work. I'm not saying it wouldn't.
But cannibalizing the preexisting message that has very specific semantics, is a hackey workaround.

@wunter8
Copy link
Contributor

wunter8 commented Aug 5, 2023

Got it. I hope you don't feel like I am dismissing the value of your proposal. I know other people have already been sending JSON strings with custom fields as the message, so I wanted to make sure you weren't having problems with that.

And I'm sure they will also be happy to have a convenient extras field where they can put additional information instead.

I will see if I can implement this sometime this week.

@tka85
Copy link
Author

tka85 commented Aug 6, 2023

I don't feel like that at all. I completely understand you asking for justification esp. when it comes to feature requests. After all it is I who makes a request for your time and effort.

Much appreciated regardless of whether you go ahead with its implementation or not.

wunter8 added a commit to wunter8/ntfy that referenced this issue Aug 8, 2023
@tka85
Copy link
Author

tka85 commented Aug 20, 2023

@wunter8 I see the fix. Would it be possible to also get arrays to be allowed values inside the extras object?

wunter8 added a commit to wunter8/ntfy that referenced this issue Sep 10, 2023
@tka85
Copy link
Author

tka85 commented Oct 25, 2023

Any update on this?

@wunter8
Copy link
Contributor

wunter8 commented Oct 25, 2023

Nope. Sorry. I've been busy with work and haven't been able to finish the Android side of things yet

@binwiederhier binwiederhier added android-app ntfy Android app server Relates to the main binary (server or client) labels Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android-app ntfy Android app enhancement New feature or request server Relates to the main binary (server or client)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants