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:
parent
e85b5e6ea5
commit
652c8b32cd
1 changed files with 7 additions and 3 deletions
10
main.go
10
main.go
|
@ -33,6 +33,8 @@ import (
|
||||||
|
|
||||||
var version = "dev"
|
var version = "dev"
|
||||||
|
|
||||||
|
var MAX_NTFY_ACTIONS = 3
|
||||||
|
|
||||||
type bridge struct {
|
type bridge struct {
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
|
@ -360,9 +362,11 @@ func (br *bridge) publish(n *notification) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
nActions := len(actions)
|
nActions := len(actions)
|
||||||
if nActions > 3 {
|
if nActions > MAX_NTFY_ACTIONS {
|
||||||
// TODO: Limit actions to three
|
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.Warn(fmt.Sprintf("Publish: Too many actions (%d), ntfy only supports up to three.", nActions))
|
br.logger.Debug("Action list",
|
||||||
|
slog.Any("actions", actions))
|
||||||
|
actions = actions[:MAX_NTFY_ACTIONS]
|
||||||
}
|
}
|
||||||
req.Header.Set("Actions", strings.Join(actions, ";"))
|
req.Header.Set("Actions", strings.Join(actions, ";"))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue