summaryrefslogtreecommitdiffstats
path: root/bridge/telegram/telegram.go
diff options
context:
space:
mode:
authorPaul <36549980+Humorhenker@users.noreply.github.com>2021-04-03 23:15:19 +0200
committerGitHub <noreply@github.com>2021-04-03 23:15:19 +0200
commitb293e3fa75b8b5d1e793c2abbe61f0779fd2e5b0 (patch)
tree4803aa44805ad18e2f18d8f2272c6e10f8dd861e /bridge/telegram/telegram.go
parent21eb37e471c338a90f2e23c86106f7e49e2d1196 (diff)
downloadmatterbridge-msglm-b293e3fa75b8b5d1e793c2abbe61f0779fd2e5b0.tar.gz
matterbridge-msglm-b293e3fa75b8b5d1e793c2abbe61f0779fd2e5b0.tar.bz2
matterbridge-msglm-b293e3fa75b8b5d1e793c2abbe61f0779fd2e5b0.zip
Adding caption to send telegram images. Fixes #1357 (#1358)
* Used tgbotapi caption option to attach caption to photos / documents * remove "text/template/parse" * added TGGetParseMode to clean up. Added tg upload function for video, audio and voice * fixed varname Textout. Changed fileextension logic to avoid chaining regex * fixed textout varname * fixed parsemode varname * gofmt Co-authored-by: Wim <wim@42.be>
Diffstat (limited to 'bridge/telegram/telegram.go')
-rw-r--r--bridge/telegram/telegram.go41
1 files changed, 23 insertions, 18 deletions
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go
index f1c7168c..0f08a45b 100644
--- a/bridge/telegram/telegram.go
+++ b/bridge/telegram/telegram.go
@@ -69,6 +69,28 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error {
return nil
}
+func TGGetParseMode(b *Btelegram, username string, text string) (textout string, parsemode string) {
+ textout = username + text
+ if b.GetString("MessageFormat") == HTMLFormat {
+ b.Log.Debug("Using mode HTML")
+ parsemode = tgbotapi.ModeHTML
+ }
+ if b.GetString("MessageFormat") == "Markdown" {
+ b.Log.Debug("Using mode markdown")
+ parsemode = tgbotapi.ModeMarkdown
+ }
+ if b.GetString("MessageFormat") == MarkdownV2 {
+ b.Log.Debug("Using mode MarkdownV2")
+ parsemode = MarkdownV2
+ }
+ if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick {
+ b.Log.Debug("Using mode HTML - nick only")
+ textout = username + html.EscapeString(text)
+ parsemode = tgbotapi.ModeHTML
+ }
+ return textout, parsemode
+}
+
func (b *Btelegram) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
@@ -131,24 +153,7 @@ func (b *Btelegram) getFileDirectURL(id string) string {
func (b *Btelegram) sendMessage(chatid int64, username, text string) (string, error) {
m := tgbotapi.NewMessage(chatid, "")
- m.Text = username + text
- if b.GetString("MessageFormat") == HTMLFormat {
- b.Log.Debug("Using mode HTML")
- m.ParseMode = tgbotapi.ModeHTML
- }
- if b.GetString("MessageFormat") == "Markdown" {
- b.Log.Debug("Using mode markdown")
- m.ParseMode = tgbotapi.ModeMarkdown
- }
- if b.GetString("MessageFormat") == MarkdownV2 {
- b.Log.Debug("Using mode MarkdownV2")
- m.ParseMode = MarkdownV2
- }
- 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
- }
+ m.Text, m.ParseMode = TGGetParseMode(b, username, text)
m.DisableWebPagePreview = b.GetBool("DisableWebPagePreview")