diff options
author | Wim <wim@42.be> | 2019-03-02 22:38:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-02 22:38:44 +0100 |
commit | f57370f33abf7e2d61d39f4867c9c95f9fc6cd8c (patch) | |
tree | 9f8eff90fcc9ff5636a89a64bd626b459d8fe583 /bridge | |
parent | c557d51b6faf146e67ececceaeb731a87e1a498b (diff) | |
download | matterbridge-msglm-f57370f33abf7e2d61d39f4867c9c95f9fc6cd8c.tar.gz matterbridge-msglm-f57370f33abf7e2d61d39f4867c9c95f9fc6cd8c.tar.bz2 matterbridge-msglm-f57370f33abf7e2d61d39f4867c9c95f9fc6cd8c.zip |
Add support for URL in messageEntities (telegram). Fixes #735 (#736)
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/telegram/handlers.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 93576fb4..fa8f2ffb 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -144,6 +144,9 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { // quote the previous message b.handleQuoting(&rmsg, message) + // handle entities (adding URLs) + b.handleEntities(&rmsg, message) + if rmsg.Text != "" || len(rmsg.Extra) > 0 { rmsg.Text = helper.RemoveEmptyNewLines(rmsg.Text) // channels don't have (always?) user information. see #410 @@ -353,3 +356,22 @@ func (b *Btelegram) handleQuote(message, quoteNick, quoteMessage string) string format = strings.Replace(format, "{QUOTEMESSAGE}", quoteMessage, -1) return format } + +// handleEntities handles messageEntities +func (b *Btelegram) handleEntities(rmsg *config.Message, message *tgbotapi.Message) { + if message.Entities == nil { + return + } + // for now only do URL replacements + for _, e := range *message.Entities { + if e.Type == "text_link" { + url, err := e.ParseURL() + if err != nil { + b.Log.Errorf("entity text_link url parse failed: %s", err) + continue + } + link := rmsg.Text[e.Offset : e.Offset+e.Length] + rmsg.Text = strings.Replace(rmsg.Text, link, url.String(), 1) + } + } +} |