fix(telegram): support only one topicID per chatID

This commit is contained in:
jon4hz
2024-03-17 17:52:46 +01:00
committed by CrazyMax
parent 45893c2ed9
commit d673b3c9dc
3 changed files with 16 additions and 21 deletions

View File

@@ -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 | | `tokenFile` | | Use content of secret file as Telegram bot token if `token` not defined |
| `chatIDs` | | List of chat IDs to send notifications to | | `chatIDs` | | List of chat IDs to send notifications to |
| `chatIDsFile` | | Use content of secret file as chat IDs if `chatIDs` not defined | | `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 | | `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 | | `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]` Chat IDs secret file must be a valid JSON array like: `[123456789,987654321]`
!!! example "chat topic IDS secret file" !!! 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` ### Default `templateBody`

View File

@@ -5,13 +5,13 @@ const NotifTelegramDefaultTemplateBody = `Docker tag {{ if .Entry.Image.HubLink
// NotifTelegram holds Telegram notification configuration details // NotifTelegram holds Telegram notification configuration details
type NotifTelegram struct { type NotifTelegram struct {
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"`
TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"`
ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"omitempty"` ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"omitempty"`
ChatIDsFile string `yaml:"chatIDsFile,omitempty" json:"chatIDsFile,omitempty" validate:"omitempty,file"` ChatIDsFile string `yaml:"chatIDsFile,omitempty" json:"chatIDsFile,omitempty" validate:"omitempty,file"`
ChatTopics [][]int64 `yaml:"chatTopics,omitempty" json:"chatTopics,omitempty" validate:"omitempty"` ChatTopics []int64 `yaml:"chatTopics,omitempty" json:"chatTopics,omitempty" validate:"omitempty"`
ChatTopicsFile string `yaml:"chatTopicsFile,omitempty" json:"chatTopicsFile,omitempty" validate:"omitempty,file"` ChatTopicsFile string `yaml:"chatTopicsFile,omitempty" json:"chatTopicsFile,omitempty" validate:"omitempty,file"`
TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
} }
// GetDefaults gets the default values // GetDefaults gets the default values

View File

@@ -102,18 +102,13 @@ func (c *Client) Send(entry model.NotifEntry) error {
} }
for i, chatID := range chatIDs { for i, chatID := range chatIDs {
if len(chatTopics) > i && len(chatTopics[i]) > 0 { var chatTopic int64
for _, topic := range chatTopics[i] { if len(chatTopics) > i {
err = sendTelegramMessage(bot, chatID, topic, string(body)) chatTopic = chatTopics[i]
if err != nil { }
return err err = sendTelegramMessage(bot, chatID, chatTopic, string(body))
} if err != nil {
} return err
} else {
err = sendTelegramMessage(bot, chatID, 0, string(body))
if err != nil {
return err
}
} }
} }