diff --git a/docs/notif/telegram.md b/docs/notif/telegram.md index 9fd8b7890..0b6be17e8 100644 --- a/docs/notif/telegram.md +++ b/docs/notif/telegram.md @@ -25,6 +25,7 @@ Multiple chat IDs can be provided in order to deliver notifications to multiple | Name | Default | Description | |-----------------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| +| `apiURL` | `https://api.telegram.org` | Custom Telegram bot API base URL, for proxies or self-hosted bot API servers | | `token` | | Telegram bot token | | `tokenFile` | | Use content of [secret file](../faq.md#secrets-loaded-from-files-and-trailing-newlines) as Telegram bot token if `token` not defined | | `chatIDs` | | List of [chat IDs](#chatids-format) to send notifications to | @@ -33,6 +34,7 @@ Multiple chat IDs can be provided in order to deliver notifications to multiple | `disableNotification` | `false` | Send silent message with no sound | !!! abstract "Environment variables" + * `DIUN_NOTIF_TELEGRAM_APIURL` * `DIUN_NOTIF_TELEGRAM_TOKEN` * `DIUN_NOTIF_TELEGRAM_TOKENFILE` * `DIUN_NOTIF_TELEGRAM_CHATIDS` (comma separated) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 1c8b7780e..da610ae3f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/crazy-max/diun/v4/internal/model" "github.com/crazy-max/diun/v4/pkg/registry" "github.com/crazy-max/diun/v4/pkg/utl" @@ -193,7 +194,8 @@ for {{ .Entry.Manifest.Platform }} platform. TemplateBody: model.NotifTeamsDefaultTemplateBody, }, Telegram: &model.NotifTelegram{ - Token: "abcdef123456", + APIURL: gotgbot.DefaultAPIURL, + Token: "abcdef123456", ChatIDs: []string{ "8547439", "1234567", @@ -347,6 +349,7 @@ func TestLoadEnv(t *testing.T) { environ: []string{ "DIUN_NOTIF_TELEGRAM_TOKEN=abcdef123456", "DIUN_NOTIF_TELEGRAM_CHATIDS=8547439,1234567", + "DIUN_NOTIF_TELEGRAM_APIURL=http://telegram-bot-api:8081", "DIUN_PROVIDERS_SWARM=true", }, expected: &Config{ @@ -362,6 +365,7 @@ func TestLoadEnv(t *testing.T) { }, TemplateBody: model.NotifTelegramDefaultTemplateBody, DisableNotification: utl.NewFalse(), + APIURL: "http://telegram-bot-api:8081", }, }, Providers: &model.Providers{ diff --git a/internal/model/notif_telegram.go b/internal/model/notif_telegram.go index d4d13e32e..1c5bda485 100644 --- a/internal/model/notif_telegram.go +++ b/internal/model/notif_telegram.go @@ -1,12 +1,16 @@ package model -import "github.com/crazy-max/diun/v4/pkg/utl" +import ( + "github.com/PaulSonOfLars/gotgbot/v2" + "github.com/crazy-max/diun/v4/pkg/utl" +) // NotifTelegramDefaultTemplateBody ... const NotifTelegramDefaultTemplateBody = `Docker tag {{ if .Entry.Image.HubLink }}[{{ .Entry.Image }}]({{ .Entry.Image.HubLink }}){{ else }}{{ .Entry.Image }}{{ end }} which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }} on {{ .Entry.Image.Domain }} registry (triggered by {{ escapeMarkdown .Meta.Hostname }} host).` // NotifTelegram holds Telegram notification configuration details type NotifTelegram struct { + APIURL string `yaml:"apiURL,omitempty" json:"apiURL,omitempty" validate:"omitempty,url"` Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` ChatIDs []string `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"omitempty"` @@ -24,6 +28,7 @@ func (s *NotifTelegram) GetDefaults() *NotifTelegram { // SetDefaults sets the default values func (s *NotifTelegram) SetDefaults() { + s.APIURL = gotgbot.DefaultAPIURL s.TemplateBody = NotifTelegramDefaultTemplateBody s.DisableNotification = utl.NewFalse() } diff --git a/internal/notif/telegram/client.go b/internal/notif/telegram/client.go index 6bbadec59..04186cb4b 100644 --- a/internal/notif/telegram/client.go +++ b/internal/notif/telegram/client.go @@ -73,7 +73,7 @@ func (c *Client) Send(entry model.NotifEntry) error { Client: http.Client{}, DefaultRequestOpts: &gotgbot.RequestOpts{ Timeout: gotgbot.DefaultTimeout, - APIURL: gotgbot.DefaultAPIURL, + APIURL: c.cfg.APIURL, }, }, })