diff --git a/config/notifiers.go b/config/notifiers.go index 682b38df08..0bceb4b6f0 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -143,7 +143,7 @@ var ( }, DisableNotifications: false, Message: `{{ template "telegram.default.message" . }}`, - ParseMode: "MarkdownV2", + ParseMode: "HTML", } ) @@ -661,9 +661,6 @@ func (c *TelegramConfig) UnmarshalYAML(unmarshal func(interface{}) error) error if c.ChatID == 0 { return fmt.Errorf("missing chat_id on telegram_config") } - if c.APIUrl == nil { - return fmt.Errorf("missing api_url on telegram_config") - } if c.ParseMode != "" && c.ParseMode != "Markdown" && c.ParseMode != "MarkdownV2" && diff --git a/notify/telegram/telegram_test.go b/notify/telegram/telegram_test.go index 0c87cf5d4d..ecae7774f0 100644 --- a/notify/telegram/telegram_test.go +++ b/notify/telegram/telegram_test.go @@ -21,13 +21,37 @@ import ( "github.com/go-kit/log" commoncfg "github.com/prometheus/common/config" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/notify/test" ) +func TestTelegramUnmarshal(t *testing.T) { + in := ` +route: + receiver: test +receivers: +- name: test + telegram_configs: + - chat_id: 1234 + bot_token: secret +` + var c config.Config + err := yaml.Unmarshal([]byte(in), &c) + require.NoError(t, err) + + require.Len(t, c.Receivers, 1) + require.Len(t, c.Receivers[0].TelegramConfigs, 1) + + require.Equal(t, "https://api.telegram.org", c.Receivers[0].TelegramConfigs[0].APIUrl.String()) + require.Equal(t, config.Secret("secret"), c.Receivers[0].TelegramConfigs[0].BotToken) + require.Equal(t, int64(1234), c.Receivers[0].TelegramConfigs[0].ChatID) + require.Equal(t, "HTML", c.Receivers[0].TelegramConfigs[0].ParseMode) +} + func TestTelegramRetry(t *testing.T) { - // Fake url for testing purpouses + // Fake url for testing purposes fakeURL := config.URL{ URL: &url.URL{ Scheme: "https",