[GH-ISSUE #1121] Add utility functions to Message Templates #792

Closed
opened 2026-05-07 00:27:34 +02:00 by BreizhHardware · 0 comments

Originally created by @davidatkinsondoyle on GitHub (May 29, 2024).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1121

💡 Idea

As a Notification Publisher
I would like like utility template functions to be available in message template
So that I can perform more advanced string manipulation in templates

Issues raised as outcome of thread on Discord.

Example Solution, using splitList and trim functions form sprig

Using the Slack Webhook format Alert Service in TrueNas emits a payload as below;

{"text": "TrueNAS @ truenasserver.some.domain\n\nNew alerts:\n* Job \"some notification\" succeeded.\n\n\n* Job \"some notification\" succeeded.\n\n\n\nThese alerts have been cleared:\n* Job \"some notification\" succeeded.\n\n\n* Job \"some notification\" succeeded.\n\n\n\nCurrent alerts:\n* Job 'some notification' finished.\n\n\n* Job \"some notification\" succeeded.\n\n\n* Replication \"some notification\" succeeded.\n\n\n\n"}

To turn this payload into a more usable nfty notification, with a title and message;

Title Template

{{- index (splitList "\n" .text) 0 -}}

Renders;

TrueNAS @ truenasserver.some.domain

Message Template

{{ range $index, $value := (splitList "\n\n" .text) }}
{{if eq $index 0}}{{else}}{{. | trim }}{{end}}{{end}}

Renders;

New alerts:

  • Job "some notification" succeeded.
  • Job "some notification" succeeded.

These alerts have been cleared:

  • Job "some notification" succeeded.
  • Job "some notification" succeeded.

Current alerts:

  • Job 'some notification' finished.
  • Job "some notification" succeeded.
  • Replication "some notification" succeeded.

Possible implementations / Inspiration

💻 Target components
ntfy server

Originally created by @davidatkinsondoyle on GitHub (May 29, 2024). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1121 :bulb: **Idea** As a Notification Publisher I would like like utility template functions to be available in message template So that I can perform more advanced string manipulation in templates Issues raised as outcome of [thread](https://discord.com/channels/874398661709295626/874398661709295629/1245342591722192897) on Discord. ## Example Solution, using _splitList_ and _trim_ functions form [sprig](https://github.com/Masterminds/sprig) Using the Slack Webhook format [Alert Service](https://www.truenas.com/docs/core/uireference/system/alertservices/) in TrueNas emits a payload as below; ``` json {"text": "TrueNAS @ truenasserver.some.domain\n\nNew alerts:\n* Job \"some notification\" succeeded.\n\n\n* Job \"some notification\" succeeded.\n\n\n\nThese alerts have been cleared:\n* Job \"some notification\" succeeded.\n\n\n* Job \"some notification\" succeeded.\n\n\n\nCurrent alerts:\n* Job 'some notification' finished.\n\n\n* Job \"some notification\" succeeded.\n\n\n* Replication \"some notification\" succeeded.\n\n\n\n"} ``` To turn this payload into a more usable nfty notification, with a title and message; ### Title Template ``` {{- index (splitList "\n" .text) 0 -}} ``` Renders; > TrueNAS @ truenasserver.some.domain ### Message Template ``` {{ range $index, $value := (splitList "\n\n" .text) }} {{if eq $index 0}}{{else}}{{. | trim }}{{end}}{{end}} ``` Renders; >New alerts: >* Job "some notification" succeeded. >* Job "some notification" succeeded. > >These alerts have been cleared: >* Job "some notification" succeeded. >* Job "some notification" succeeded. > >Current alerts: >* Job 'some notification' finished. >* Job "some notification" succeeded. >* Replication "some notification" succeeded. ## Possible implementations / Inspiration - [sprig](https://github.com/Masterminds/sprig) - https://github.com/hairyhenderson/gomplate :computer: **Target components** ntfy server
BreizhHardware 2026-05-07 00:27:34 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#792
No description provided.