From a9b5875fb08f71ca7dc7f57a0b815353455f9cda Mon Sep 17 00:00:00 2001 From: Alexander Korelskiy Date: Wed, 29 Jun 2022 18:24:13 +0300 Subject: [PATCH 1/2] Fix message html entities escaping when sending to Telegram --- bridge/telegram/html.go | 13 +++++++++++-- bridge/telegram/telegram.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bridge/telegram/html.go b/bridge/telegram/html.go index 41326f6fcb..4aa9fd3aea 100644 --- a/bridge/telegram/html.go +++ b/bridge/telegram/html.go @@ -2,7 +2,6 @@ package btelegram import ( "bytes" - "html" "github.com/russross/blackfriday" ) @@ -24,10 +23,16 @@ func (options *customHTML) Paragraph(out *bytes.Buffer, text func() bool) { func (options *customHTML) BlockCode(out *bytes.Buffer, text []byte, lang string) { out.WriteString("
")
 
-	out.WriteString(html.EscapeString(string(text)))
+	out.WriteString(string(text))
 	out.WriteString("
\n") } +func (options *customHTML) CodeSpan(out *bytes.Buffer, text []byte) { + out.WriteString("") + out.WriteString(string(text)) + out.WriteString("") +} + func (options *customHTML) Header(out *bytes.Buffer, text func() bool, level int, id string) { options.Paragraph(out, text) } @@ -42,6 +47,10 @@ func (options *customHTML) BlockQuote(out *bytes.Buffer, text []byte) { out.WriteByte('\n') } +func (options *customHTML) LineBreak(out *bytes.Buffer) { + out.WriteByte('\n') +} + func (options *customHTML) List(out *bytes.Buffer, text func() bool, flags int) { options.Paragraph(out, text) } diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 25225416e6..43cb818fc9 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -101,7 +101,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) { } if b.GetString("MessageFormat") == HTMLFormat { - msg.Text = makeHTML(msg.Text) + msg.Text = makeHTML(html.EscapeString(msg.Text)) } // Delete message From cd55af480d802e7957f375d4af2ead0ba9dd99e3 Mon Sep 17 00:00:00 2001 From: Alexander Korelskiy Date: Wed, 20 Jul 2022 13:18:45 +0300 Subject: [PATCH 2/2] Fix error messages in telegram and slack bridges --- bridge/slack/handlers.go | 2 +- bridge/telegram/handlers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index 225931d4e4..242444276e 100644 --- a/bridge/slack/handlers.go +++ b/bridge/slack/handlers.go @@ -80,7 +80,7 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) { case *slack.FileDeletedEvent: rmsg, err := b.handleFileDeletedEvent(ev) if err != nil { - b.Log.Errorf("%#v", err) + b.Log.Printf("%#v", err) continue } messages <- rmsg diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 46bda48098..ad41354e0c 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -176,7 +176,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { if update.Message == nil && update.ChannelPost == nil && update.EditedMessage == nil && update.EditedChannelPost == nil { - b.Log.Error("Getting nil messages, this shouldn't happen.") + b.Log.Info("Received event without messages, skipping.") continue }