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.
This commit is contained in:
Thorben Günther 2024-11-06 14:41:46 +01:00
parent e85b5e6ea5
commit 652c8b32cd
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED

10
main.go
View file

@ -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, ";"))