Telegram: Escape all necessary characters

Fixes #108.
matrix
Harvey Tindall 4 years ago
parent 7035a3fe9c
commit fb6256d1ed
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -146,6 +146,9 @@ func (t *TelegramDaemon) QuoteReply(upd *tg.Update, content string) error {
return err
}
var escapedChars = []string{"_", "\\_", "*", "\\*", "[", "\\[", "]", "\\]", "(", "\\(", ")", "\\)", "~", "\\~", "`", "\\`", ">", "\\>", "#", "\\#", "+", "\\+", "-", "\\-", "=", "\\=", "|", "\\|", "{", "\\{", "}", "\\}", ".", "\\.", "!", "\\!"}
var escaper = strings.NewReplacer(escapedChars...)
// Send will send a telegram message to a list of chat IDs. message.text is used if no markdown is given.
func (t *TelegramDaemon) Send(message *Message, ID ...int64) error {
for _, id := range ID {
@ -153,9 +156,7 @@ func (t *TelegramDaemon) Send(message *Message, ID ...int64) error {
if message.Markdown == "" {
msg = tg.NewMessage(id, message.Text)
} else {
text := strings.ReplaceAll(message.Markdown, ".", "\\.")
text = strings.ReplaceAll(text, "![", "[")
text = strings.ReplaceAll(text, "!", "\\!")
text := escaper.Replace(message.Markdown)
msg = tg.NewMessage(id, text)
msg.ParseMode = "MarkdownV2"
}

Loading…
Cancel
Save