notification-controller icon indicating copy to clipboard operation
notification-controller copied to clipboard

Telegram Alerts failed with can't parse entities error

Open AlexGurtoff opened this issue 1 year ago • 2 comments

My actual Alert manifest:

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
  name: helmrelease-status
  namespace: flux-system
spec:
  providerRef:
    name: telegram
  eventSeverity: info
  eventSources:
    - kind: HelmRelease
      name: "*"
      namespace: somenamespace

But when it comes to sending an alert, I see an error in the logs:

{"level":"error","ts":"2024-08-20T14:28:35.559Z","logger":"event-server","msg":"failed to send notification","eventInvolvedObject":{"kind":"HelmRelease","namespace":"somenamespace","name":"blabla-some-service","uid":"567941c5-b3c2-495e-bc9a-0b70b84d832d","apiVersion":"helm.toolkit.fluxcd.io/v2","resourceVersion":"5585528"},"Alert":{"name":"helmrelease-status","namespace":"flux-system"},"error":"Bad Request: can't parse entities: Character '-' is reserved and must be escaped with the preceding '\\'"}

I see such code that must handle it in telegram.go

// The telegram API requires that some special characters are escaped
// in the message string. Docs: https://core.telegram.org/bots/api#formatting-options.
func escapeString(str string) string {
	chars := "\\.-_[]()~>`#+=|{}!*"
	for _, char := range chars {
		start := 0
		idx := 0
		for start < len(str) && idx != -1 {
			idx = strings.IndexRune(str[start:], char)
			if idx != -1 {
				newIdx := start + idx
				str = str[:newIdx] + `\` + str[newIdx:]
				start = newIdx + 2
			}
		}
	}

	return str
}

So why isn't it working for me? What am I missing? I would be grateful for any help

AlexGurtoff avatar Aug 20 '24 14:08 AlexGurtoff

UPD: I don't know why, but when I rebuilt the docker image locally from my laptop on the main branch and changed the image for the notification controller - it starts working. So the 1.3.0 release doesn't work for me, but the last commit on the main branch is fine. Mythic

AlexGurtoff avatar Aug 21 '24 08:08 AlexGurtoff

Fixed in https://github.com/fluxcd/notification-controller/pull/829 this PR will be included in Flux 2.4 release.

stefanprodan avatar Aug 21 '24 08:08 stefanprodan