notify/telegram: Set API and ParseMode defaults

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
This commit is contained in:
Matthias Loibl 2022-04-05 12:41:09 +02:00
parent a68fcc0445
commit 34e60d2c80
No known key found for this signature in database
GPG Key ID: 78A796CA74CA38BA
1 changed files with 14 additions and 0 deletions

View File

@ -16,6 +16,7 @@ package telegram
import (
"context"
"net/http"
"net/url"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
@ -44,6 +45,19 @@ func New(conf *config.TelegramConfig, t *template.Template, l log.Logger, httpOp
return nil, err
}
if conf.APIUrl == nil {
apiURL, err := url.Parse("https://api.telegram.org")
if err != nil {
return nil, err
}
conf.APIUrl = &config.URL{URL: apiURL}
}
if conf.ParseMode == "" {
// The default Telegram template is in HTML,
// so we need to set the parse mode to HTML for Telegram not to return a parse error.
conf.ParseMode = "HTML"
}
client, err := createTelegramClient(conf.BotToken, conf.APIUrl.String(), conf.ParseMode, httpclient)
if err != nil {
return nil, err