From a025fcfba2cecb8ffa1b62f0f5fe79f43da46925 Mon Sep 17 00:00:00 2001 From: milarin Date: Sun, 22 Jan 2023 13:40:42 +0100 Subject: [PATCH] support for html parsing in telegram messages --- envvars.go | 2 +- telegram.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/envvars.go b/envvars.go index 133fcb1..b02100f 100644 --- a/envvars.go +++ b/envvars.go @@ -18,7 +18,7 @@ var ( TelegramBotToken = envvars.String("TELEGRAM_API_TOKEN", "") TelegramChatID = envvars.Int64("TELEGRAM_CHAT_ID", 0) - TelegramOrganizeMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_ORGANIZE_MESSAGE_PATTERN", `Download finished{{range .}}\n{{.Anime.Title.UserPreferred}} episode {{.Episode}}{{end}}`)) + TelegramOrganizeMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_ORGANIZE_MESSAGE_PATTERN", `Recently Downloaded Animes ({{len .}} eps){{range .}}\n{{.Anime.Title.UserPreferred}} Episode {{.Episode}}{{end}}`)) TelegramOrganizeMessagePattern = template.Must(template.New("TELEGRAM_ORGANIZE_MESSAGE_PATTERN").Parse(TelegramOrganizeMessagePatternStr)) TelegramOrganizeMessageSendCondition = envvars.ObjectSlice("TELEGRAM_ORGANIZE_MESSAGE_SEND_CONDITION", ",", []SendCondition{SendConditionAlways}, SendConditionFromString) TelegramOrganizeMessageSendInterval = envvars.Duration("TELEGRAM_ORGANIZE_MESSAGE_SEND_INTERVAL", 0) diff --git a/telegram.go b/telegram.go index bb43ac8..507e51d 100644 --- a/telegram.go +++ b/telegram.go @@ -72,11 +72,12 @@ func sendAllQueuedAnimeEpisodes() { } func SendTelegramMessage(text string) { - if TelegramBot == nil { + if TelegramBot == nil || strings.TrimSpace(text) == "" { return } msg := tgbotapi.NewMessage(TelegramChatID, text) + msg.ParseMode = "html" _, err := TelegramBot.Send(msg) if err != nil { adverr.Println(adverr.Wrap("could not send telegram message", err))