HOWTO change Template Telegramm Message

Hi guys

Need to change telegramm alert template . Can some one help me to find it

Fox example delete URL section on telegramm message

2 Likes

Hi garamelek,

It’s currently not possible to configure the template for the Telegram alerts. It would have to be done either in code (with a custom build) or through adding support for templating to the Telegram alerting.

All the code related to the telegram alerter can be found here: https://github.com/grafana/grafana/blob/master/pkg/services/alerting/notifiers/telegram.go

What is your use case if I may ask? Is it just about deleting the url or do you want to customize it to fit your specific use case.

Dear lgram ,

Thanks for you comment . i just want to delete URL:http://localhost:3000… from telegramm message , because it take more space . And the second problem with grafana when alert is alram is triggered grafana send
[Alerting] TR-A Haber HD alert
State: TR-A Haber HD alert
Message: TR-A2 Turk SD Проверить
URL: http://localhost:3000//d/ieR6Pggmk/cliptv?fullscreen=true&edit=true&tab=alert&panelId=38&orgId=1

And after some time when alarm is recovered i receive again same message but only [OK ] is changed

[OK] TR-A Haber HD alert
State: TR-A Haber HD alert
Message: TR-A2 Turk SD Проверить
URL: http://localhost:3000//d/ieR6Pggmk/cliptv?fullscreen=true&edit=true&tab=alert&panelId=38&orgId=1

Is that bug or something wrong in my configuration ?

That looks about right. We might make it possible to configure the messages being sent in the future but it’s not planned for now.

1 Like

Any plan to remove url in msg?

Hello, I have the same concern. I want to remove URL which is showing up in my telegram alerts. any solution yet?

Hello, I have installed the latest 8.0 version of grafana, seems there is no custom templating option for telegram alerts in source code or anywhere. can any one please help, i just want to remove that URL(http://localhost:3000) from the alert.

1 Like

Would like to add my +1 for this functionality too

Also would like to get rid of the URL in the message, further customization would be great as well. For E-Mail Alerts there are html templates that one can modify, any chance something similar could be done for Telegram?

Hello, it’s Grafana v8.4.4, is it already possible to change Telegram templates? The default template is very unsightly and contains excessive information. If possible, can someone please share nicer templates?


Hi, my brother. I don’t know if I solved the problem, but it did trim a lot of content for me, you can take a look Example message template | Grafana documentation.

1 Like

Thank you @ryan06c6 , below I’m sharing what I have eventually arrived at. Still not very nice looking:

{{ define "Telegram" }}
  {{ if gt (len .Alerts.Firing) 0 }}
  FIRING: {{ len .Alerts.Firing }} alerts
  {{ range .Alerts.Firing }}
  {{ if gt (len .Annotations) 0 }}
  Summary: {{ .Annotations.summary }}
  Description: {{ .Annotations.description }}
  Alert ID:  {{ .Fingerprint }}
  Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ if gt (len .Alerts.Resolved) 0 }}
  RESOLVED: {{ len .Alerts.Resolved }} alerts
  {{ range .Alerts.Resolved }}
  {{ if gt (len .Annotations) 0 }}
  Summary: {{ .Annotations.summary }}
  Description: {{ .Annotations.description }}
  Alert ID:  {{ .Fingerprint }}
  Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ end }}
{{ end }}
2 Likes

Nice, thanks for sharing. Just to make the template easier you can use {{ if .List }} instead of {{ if gt (len .List) 0 }} so your template would be this:

{{ define "Telegram" }}
  {{ if .Alerts.Firing }}
  FIRING: {{ len .Alerts.Firing }} alerts
  {{ range .Alerts.Firing }}
  {{ if .Annotations }}
  Summary: {{ .Annotations.summary }}
  Description: {{ .Annotations.description }}
  Alert ID:  {{ .Fingerprint }}
  Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ if .Alerts.Resolved }}
  RESOLVED: {{ len .Alerts.Resolved }} alerts
  {{ range .Alerts.Resolved }}
  {{ if .Annotations }}
  Summary: {{ .Annotations.summary }}
  Description: {{ .Annotations.description }}
  Alert ID:  {{ .Fingerprint }}
  Labels: {{ range .Labels.SortedPairs }} {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}
  {{ end }}
  {{ end }}
{{ end }}