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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility functions to Message Templates #1121

Open
davidatkinsondoyle opened this issue May 29, 2024 · 0 comments 路 May be fixed by #1127
Open

Add utility functions to Message Templates #1121

davidatkinsondoyle opened this issue May 29, 2024 · 0 comments 路 May be fixed by #1127
Labels
enhancement New feature or request

Comments

@davidatkinsondoyle
Copy link

davidatkinsondoyle commented May 29, 2024

馃挕 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

@davidatkinsondoyle davidatkinsondoyle added the enhancement New feature or request label May 29, 2024
wunter8 added a commit to wunter8/ntfy that referenced this issue Jun 3, 2024
@wunter8 wunter8 linked a pull request Jun 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant