Fix Telegram token being checked for content instead of topic

This commit is contained in:
Andrey N 2024-06-01 23:52:43 +03:00 committed by GitHub
parent 4910d2ca55
commit 3fabf4381e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

10
auth.go
View file

@ -85,13 +85,11 @@ func NotifyTelegram(msg string) {
return return
} }
client := &http.Client{} client := &http.Client{}
var data *strings.Reader data := "chat_id=" + Cfg.TelegramChat + "&text=" + msg
if Cfg.TelegramToken != "" { if Cfg.TelegramTopic != "" {
data = strings.NewReader("chat_id=" + Cfg.TelegramChat + "&message_thread_id=" + Cfg.TelegramTopic + "&text=" + msg) data += "&message_thread_id=" + Cfg.TelegramTopic
} else {
data = strings.NewReader("chat_id=" + Cfg.TelegramChat + "&text=" + msg)
} }
req, err := http.NewRequest("POST", "https://api.telegram.org/bot"+Cfg.TelegramToken+"/sendMessage", data) req, err := http.NewRequest("POST", "https://api.telegram.org/bot"+Cfg.TelegramToken+"/sendMessage", strings.NewReader(data))
if err != nil { if err != nil {
slog.Error("failed telegram request", "error", err) slog.Error("failed telegram request", "error", err)
return return