Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/notif/telegram.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -193,7 +194,8 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
TemplateBody: model.NotifTeamsDefaultTemplateBody,
},
Telegram: &model.NotifTelegram{
Token: "abcdef123456",
APIURL: gotgbot.DefaultAPIURL,
Token: "abcdef123456",
ChatIDs: []string{
"8547439",
"1234567",
Expand Down Expand Up @@ -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{
Expand All @@ -362,6 +365,7 @@ func TestLoadEnv(t *testing.T) {
},
TemplateBody: model.NotifTelegramDefaultTemplateBody,
DisableNotification: utl.NewFalse(),
APIURL: "http://telegram-bot-api:8081",
},
},
Providers: &model.Providers{
Expand Down
7 changes: 6 additions & 1 deletion internal/model/notif_telegram.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion internal/notif/telegram/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
Expand Down
Loading