diff --git a/docs/notif/telegram.md b/docs/notif/telegram.md index a8bedefd..6f70d674 100644 --- a/docs/notif/telegram.md +++ b/docs/notif/telegram.md @@ -27,7 +27,7 @@ Multiple chat IDs can be provided in order to deliver notifications to multiple | `tokenFile` | | Use content of secret file as Telegram bot token if `token` not defined | | `chatIDs` | | List of chat IDs to send notifications to | | `chatIDsFile` | | Use content of secret file as chat IDs if `chatIDs` not defined | -| `chatTopics` | | Nested List of chat topic IDs to send notifications to. | +| `chatTopics` | | List of chat topic IDs to send notifications to. | | `chatTopicsFile` | | Use content of secret file as chat topic IDs if `chatTopics` not defined | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body | @@ -42,7 +42,7 @@ Multiple chat IDs can be provided in order to deliver notifications to multiple Chat IDs secret file must be a valid JSON array like: `[123456789,987654321]` !!! example "chat topic IDS secret file" - Chat topics is a nested array, so you can specify multiple topics per chat ID: `[[10,15][10,20]]` + Chat topics is also an array, so you can specify a topic ID per chat ID: `[10,20]` ### Default `templateBody` diff --git a/internal/model/notif_telegram.go b/internal/model/notif_telegram.go index 62de8027..30e669a4 100644 --- a/internal/model/notif_telegram.go +++ b/internal/model/notif_telegram.go @@ -5,13 +5,13 @@ const NotifTelegramDefaultTemplateBody = `Docker tag {{ if .Entry.Image.HubLink // NotifTelegram holds Telegram notification configuration details type NotifTelegram struct { - Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` - TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` - ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"omitempty"` - ChatIDsFile string `yaml:"chatIDsFile,omitempty" json:"chatIDsFile,omitempty" validate:"omitempty,file"` - ChatTopics [][]int64 `yaml:"chatTopics,omitempty" json:"chatTopics,omitempty" validate:"omitempty"` - ChatTopicsFile string `yaml:"chatTopicsFile,omitempty" json:"chatTopicsFile,omitempty" validate:"omitempty,file"` - TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` + Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` + TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` + ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"omitempty"` + ChatIDsFile string `yaml:"chatIDsFile,omitempty" json:"chatIDsFile,omitempty" validate:"omitempty,file"` + ChatTopics []int64 `yaml:"chatTopics,omitempty" json:"chatTopics,omitempty" validate:"omitempty"` + ChatTopicsFile string `yaml:"chatTopicsFile,omitempty" json:"chatTopicsFile,omitempty" validate:"omitempty,file"` + TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` } // GetDefaults gets the default values diff --git a/internal/notif/telegram/client.go b/internal/notif/telegram/client.go index 9968cebb..8bf6b1f8 100644 --- a/internal/notif/telegram/client.go +++ b/internal/notif/telegram/client.go @@ -102,18 +102,13 @@ func (c *Client) Send(entry model.NotifEntry) error { } for i, chatID := range chatIDs { - if len(chatTopics) > i && len(chatTopics[i]) > 0 { - for _, topic := range chatTopics[i] { - err = sendTelegramMessage(bot, chatID, topic, string(body)) - if err != nil { - return err - } - } - } else { - err = sendTelegramMessage(bot, chatID, 0, string(body)) - if err != nil { - return err - } + var chatTopic int64 + if len(chatTopics) > i { + chatTopic = chatTopics[i] + } + err = sendTelegramMessage(bot, chatID, chatTopic, string(body)) + if err != nil { + return err } }