diff options
author | Jan Martin Reckel <57252256+reckel-jm@users.noreply.github.com> | 2022-03-12 00:19:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-12 00:19:02 +0100 |
commit | ccb5b1d0759ed1028aca994e6ab53c30435237f3 (patch) | |
tree | f8c40b93915eb88cc15768c7586715fb0f13573f /bridge/telegram/handlers.go | |
parent | 0dbbd0414cbd69a8afd79ba47740a8e17be6da89 (diff) | |
download | matterbridge-msglm-ccb5b1d0759ed1028aca994e6ab53c30435237f3.tar.gz matterbridge-msglm-ccb5b1d0759ed1028aca994e6ab53c30435237f3.tar.bz2 matterbridge-msglm-ccb5b1d0759ed1028aca994e6ab53c30435237f3.zip |
Fix Telegram Problem (unforwarded formatting and skipping of linebreaks) (#1749)
* Change bridge/telegram/handlers.go
Comment out the removing of empty lines
add support for bold, italic and striked telegram messages
* Implement Telegram MessageEntities correctly
* Apply gofmt
Co-authored-by: Jan Martin Reckel <jan-martin.reckel@s2017.tu-chemnitz.de>
Co-authored-by: Wim <wim@42.be>
Diffstat (limited to 'bridge/telegram/handlers.go')
-rw-r--r-- | bridge/telegram/handlers.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index c5ed8c46..a27a6732 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -201,7 +201,8 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { b.handleEntities(&rmsg, message) if rmsg.Text != "" || len(rmsg.Extra) > 0 { - rmsg.Text = helper.RemoveEmptyNewLines(rmsg.Text) + // Comment the next line out due to avoid removing empty lines in Telegram + // rmsg.Text = helper.RemoveEmptyNewLines(rmsg.Text) // channels don't have (always?) user information. see #410 if message.From != nil { rmsg.Avatar = helper.GetAvatar(b.avatarMap, strconv.FormatInt(message.From.ID, 10), b.General) @@ -509,5 +510,21 @@ func (b *Btelegram) handleEntities(rmsg *config.Message, message *tgbotapi.Messa rmsg.Text = rmsg.Text[:offset] + "```\n" + rmsg.Text[offset:offset+e.Length] + "\n```" + rmsg.Text[offset+e.Length:] indexMovedBy += 8 } + + if e.Type == "bold" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "*" + rmsg.Text[offset:offset+e.Length] + "*" + rmsg.Text[offset+e.Length:] + indexMovedBy += 2 + } + if e.Type == "italic" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "_" + rmsg.Text[offset:offset+e.Length] + "_" + rmsg.Text[offset+e.Length:] + indexMovedBy += 2 + } + if e.Type == "strike" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "~" + rmsg.Text[offset:offset+e.Length] + "~" + rmsg.Text[offset+e.Length:] + indexMovedBy += 2 + } } } |