~xenrox/ntfy-alertmanager

652c8b32cd787a3fbe1f875ba624cb8160949256 — Thorben Günther a month ago e85b5e6
Limit number of ntfy actions

ntfy supports a maximum of three actions. If more a defined, the sending
of the message will fail. To prevent this, the surplus actions will be
removed.
1 files changed, 7 insertions(+), 3 deletions(-)

M main.go
M main.go => main.go +7 -3
@@ 33,6 33,8 @@ import (

var version = "dev"

var MAX_NTFY_ACTIONS = 3

type bridge struct {
	cfg    *config.Config
	logger *slog.Logger


@@ 360,9 362,11 @@ func (br *bridge) publish(n *notification) error {
	}

	nActions := len(actions)
	if nActions > 3 {
		// TODO: Limit actions to three
		br.logger.Warn(fmt.Sprintf("Publish: Too many actions (%d), ntfy only supports up to three.", nActions))
	if nActions > MAX_NTFY_ACTIONS {
		br.logger.Warn(fmt.Sprintf("Publish: Too many actions (%d), ntfy only supports up to %d - removing surplus actions.", nActions, MAX_NTFY_ACTIONS))
		br.logger.Debug("Action list",
			slog.Any("actions", actions))
		actions = actions[:MAX_NTFY_ACTIONS]
	}
	req.Header.Set("Actions", strings.Join(actions, ";"))