5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 21:50:28 +00:00

Add support for MessageFormat=htmlnick (telegram). #444

This commit is contained in:
Wim 2018-06-18 23:38:52 +02:00
parent 9b25716136
commit d02eda147c

View File

@ -1,6 +1,7 @@
package btelegram package btelegram
import ( import (
"html"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -97,6 +98,11 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
if strings.ToLower(b.GetString("MessageFormat")) == "htmlnick" {
b.Log.Debug("Using mode HTML - nick only")
msg.Text = html.EscapeString(msg.Text)
m.ParseMode = tgbotapi.ModeHTML
}
m := tgbotapi.NewEditMessageText(chatid, msgid, msg.Username+msg.Text) m := tgbotapi.NewEditMessageText(chatid, msgid, msg.Username+msg.Text)
if b.GetString("MessageFormat") == "HTML" { if b.GetString("MessageFormat") == "HTML" {
b.Log.Debug("Using mode HTML") b.Log.Debug("Using mode HTML")
@ -391,13 +397,17 @@ func (b *Btelegram) sendMessage(chatid int64, username, text string) (string, er
m.Text = username + text m.Text = username + text
if b.GetString("MessageFormat") == "HTML" { if b.GetString("MessageFormat") == "HTML" {
b.Log.Debug("Using mode HTML") b.Log.Debug("Using mode HTML")
m.Text = username + text
m.ParseMode = tgbotapi.ModeHTML m.ParseMode = tgbotapi.ModeHTML
} }
if b.GetString("MessageFormat") == "Markdown" { if b.GetString("MessageFormat") == "Markdown" {
b.Log.Debug("Using mode markdown") b.Log.Debug("Using mode markdown")
m.ParseMode = tgbotapi.ModeMarkdown m.ParseMode = tgbotapi.ModeMarkdown
} }
if strings.ToLower(b.GetString("MessageFormat")) == "htmlnick" {
b.Log.Debug("Using mode HTML - nick only")
m.Text = username + html.EscapeString(text)
m.ParseMode = tgbotapi.ModeHTML
}
res, err := b.c.Send(m) res, err := b.c.Send(m)
if err != nil { if err != nil {
return "", err return "", err