binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.54k stars 729 forks source link

Add support for server templates #1218

Open UiP9AV6Y opened 1 week ago

UiP9AV6Y commented 1 week ago

instead of sending title/message templates as part of the publishing request, systems can simply reference existing templates from the server. this has two advantages a) publish URLs become shorter b) publish URLs become easier to reuse

the changes backwards-compatible, as the tpl parameter continues to support truthy boolean values. the feature has to be enabled on the server. available templates and their content are exposed via new API endpoints.

wunter8 commented 1 week ago

Wow! Thanks for working on this! Having message templates on the server is one of the features we talked about in the past, but obviously we haven't implemented it yet.

Binwiederhier will be the one to decide whether to merge this, but here are some of my thoughts:

  1. It's great that this is backwards-compatible
  2. I don't love that the feature is all or nothing: title and message both online or both server templates. I'm thinking mostly for titles, which are typically short and might not even depend on the contents of the JSON body. For example, having to create a file on the server just to have a title with "New Grafana Alert" (or any other fixed string) would be unfortunate.

I don't know the best way to remedy this, though. I considered something like tpl=server,inline for a server message and inline title. Or tpl=1&message=server:grafana&title=New+Grafana+Alert. Looking toward the future, though, we have discussed making it possible to template all message fields (such as priority and tags) based on the JSON body. I don't know what that looks like and how it combines with this.

  1. I don't use Golang very much. I saw some different styles between your code and the existing ntfy code. Not sure which is better 🤷‍♂️
  2. You seemed to do a good job adding additional tests while keeping the existing template tests 👍
  3. Thanks for keeping security concerns in mind like path traversals!