diff --git a/receivers/telegram/config.go b/receivers/telegram/config.go index fc94a041..55610868 100644 --- a/receivers/telegram/config.go +++ b/receivers/telegram/config.go @@ -26,6 +26,7 @@ type Config struct { DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty" yaml:"disable_web_page_preview,omitempty"` ProtectContent bool `json:"protect_content,omitempty" yaml:"protect_content,omitempty"` DisableNotifications bool `json:"disable_notifications,omitempty" yaml:"disable_notifications,omitempty"` + APIURL string `json:"api_url,omitempty" yaml:"api_url,omitempty"` } func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error) { @@ -71,5 +72,8 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi if !found { return settings, fmt.Errorf("unknown parse_mode, must be Markdown, MarkdownV2, HTML or None") } + if settings.APIURL == "" { + settings.APIURL = APIURL + } return settings, nil } diff --git a/receivers/telegram/config_test.go b/receivers/telegram/config_test.go index cd8fe70c..62444143 100644 --- a/receivers/telegram/config_test.go +++ b/receivers/telegram/config_test.go @@ -43,6 +43,7 @@ func TestNewConfig(t *testing.T) { name: "Minimal valid configuration", settings: `{ "bottoken": "test-token", "chatid": "test-chat-id" }`, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "test-chat-id", Message: templates.DefaultMessageEmbed, @@ -59,6 +60,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "test-chat-id", Message: templates.DefaultMessageEmbed, @@ -75,6 +77,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token-key"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token-key", ChatID: "test-chat-id", Message: templates.DefaultMessageEmbed, @@ -96,6 +99,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "chat-id", Message: templates.DefaultMessageEmbed, @@ -109,6 +113,7 @@ func TestNewConfig(t *testing.T) { name: "Extracts all fields", settings: FullValidConfigForTesting, expectedConfig: Config{ + APIURL: "https://api.test.com/bot%s/%s", BotToken: "test-token", ChatID: "12345678", Message: "test-message", @@ -124,6 +129,7 @@ func TestNewConfig(t *testing.T) { settings: FullValidConfigForTesting, secureSettings: receiversTesting.ReadSecretsJSONForTesting(FullValidSecretsForTesting), expectedConfig: Config{ + APIURL: "https://api.test.com/bot%s/%s", BotToken: "test-secret-token", ChatID: "12345678", Message: "test-message", @@ -149,6 +155,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "12345678", Message: templates.DefaultMessageEmbed, @@ -165,6 +172,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "12345678", Message: templates.DefaultMessageEmbed, @@ -181,6 +189,7 @@ func TestNewConfig(t *testing.T) { "bottoken": []byte("test-token"), }, expectedConfig: Config{ + APIURL: APIURL, BotToken: "test-token", ChatID: "12345678", Message: templates.DefaultMessageEmbed, diff --git a/receivers/telegram/telegram.go b/receivers/telegram/telegram.go index 6208584b..903b3d37 100644 --- a/receivers/telegram/telegram.go +++ b/receivers/telegram/telegram.go @@ -174,7 +174,7 @@ func (tn *Notifier) newWebhookSyncCmd(action string, fn func(writer *multipart.W } cmd := &receivers.SendWebhookSettings{ - URL: fmt.Sprintf(APIURL, tn.settings.BotToken, action), + URL: fmt.Sprintf(tn.settings.APIURL, tn.settings.BotToken, action), Body: b.String(), HTTPMethod: "POST", HTTPHeader: map[string]string{ diff --git a/receivers/telegram/testing.go b/receivers/telegram/testing.go index 55714627..e774b083 100644 --- a/receivers/telegram/testing.go +++ b/receivers/telegram/testing.go @@ -2,6 +2,7 @@ package telegram // FullValidConfigForTesting is a string representation of a JSON object that contains all fields supported by the notifier Config. It can be used without secrets. const FullValidConfigForTesting = `{ + "api_url": "https://api.test.com/bot%s/%s", "bottoken" :"test-token", "chatid" :"12345678", "message" :"test-message",