@@ -16,9 +16,10 @@ const defaultAPIURL = "https://api.telegram.org"
16
16
17
17
// AlertProvider is the configuration necessary for sending an alert using Telegram
18
18
type AlertProvider struct {
19
- Token string `yaml:"token"`
20
- ID string `yaml:"id"`
21
- APIURL string `yaml:"api-url"`
19
+ Token string `yaml:"token"`
20
+ ID string `yaml:"id"`
21
+ TopicId string `yaml:"topic-id,omitempty"`
22
+ APIURL string `yaml:"api-url"`
22
23
23
24
// ClientConfig is the configuration of the client used to communicate with the provider's target
24
25
ClientConfig * client.Config `yaml:"client,omitempty"`
@@ -32,9 +33,10 @@ type AlertProvider struct {
32
33
33
34
// Override is a configuration that may be prioritized over the default configuration
34
35
type Override struct {
35
- group string `yaml:"group"`
36
- token string `yaml:"token"`
37
- id string `yaml:"id"`
36
+ group string `yaml:"group"`
37
+ token string `yaml:"token"`
38
+ id string `yaml:"id"`
39
+ topicId string `yaml:"topic-id,omitempty"`
38
40
}
39
41
40
42
// IsValid returns whether the provider's configuration is valid
@@ -94,6 +96,7 @@ type Body struct {
94
96
ChatID string `json:"chat_id"`
95
97
Text string `json:"text"`
96
98
ParseMode string `json:"parse_mode"`
99
+ TopicId string `json:"message_thread_id,omitempty"`
97
100
}
98
101
99
102
// buildRequestBody builds the request body for the provider
@@ -127,6 +130,7 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al
127
130
ChatID : provider .getIDForGroup (ep .Group ),
128
131
Text : text ,
129
132
ParseMode : "MARKDOWN" ,
133
+ TopicId : provider .getTopicIdForGroup (ep .Group ),
130
134
})
131
135
return bodyAsJSON
132
136
}
@@ -140,6 +144,15 @@ func (provider *AlertProvider) getIDForGroup(group string) string {
140
144
return provider .ID
141
145
}
142
146
147
+ func (provider * AlertProvider ) getTopicIdForGroup (group string ) string {
148
+ for _ , override := range provider .Overrides {
149
+ if override .group == group && len (override .topicId ) > 0 {
150
+ return override .topicId
151
+ }
152
+ }
153
+ return provider .TopicId
154
+ }
155
+
143
156
// GetDefaultAlert returns the provider's default alert configuration
144
157
func (provider * AlertProvider ) GetDefaultAlert () * alert.Alert {
145
158
return provider .DefaultAlert
0 commit comments