diff options
author | Paul <36549980+Humorhenker@users.noreply.github.com> | 2021-04-03 23:15:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 23:15:19 +0200 |
commit | b293e3fa75b8b5d1e793c2abbe61f0779fd2e5b0 (patch) | |
tree | 4803aa44805ad18e2f18d8f2272c6e10f8dd861e /bridge/telegram/handlers.go | |
parent | 21eb37e471c338a90f2e23c86106f7e49e2d1196 (diff) | |
download | matterbridge-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/handlers.go')
-rw-r--r-- | bridge/telegram/handlers.go | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index dbbc36ea..a93c71bb 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -2,7 +2,7 @@ package btelegram import ( "html" - "regexp" + "path/filepath" "strconv" "strings" "unicode/utf16" @@ -391,21 +391,32 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64) string { Name: fi.Name, Bytes: *fi.Data, } - re := regexp.MustCompile(".(jpg|jpe|png)$") - if re.MatchString(fi.Name) { - c = tgbotapi.NewPhotoUpload(chatid, file) - } else { - c = tgbotapi.NewDocumentUpload(chatid, file) + switch filepath.Ext(fi.Name) { + case ".jpg", ".jpe", ".png": + pc := tgbotapi.NewPhotoUpload(chatid, file) + pc.Caption, pc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + c = pc + case ".mp4", ".m4v": + vc := tgbotapi.NewVideoUpload(chatid, file) + vc.Caption, vc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + c = vc + case ".mp3", ".oga": + ac := tgbotapi.NewAudioUpload(chatid, file) + ac.Caption, ac.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + c = ac + case ".ogg": + voc := tgbotapi.NewVoiceUpload(chatid, file) + voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + c = voc + default: + dc := tgbotapi.NewDocumentUpload(chatid, file) + dc.Caption, dc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + c = dc } _, err := b.c.Send(c) if err != nil { b.Log.Errorf("file upload failed: %#v", err) } - if fi.Comment != "" { - if _, err := b.sendMessage(chatid, msg.Username, fi.Comment); err != nil { - b.Log.Errorf("posting file comment %s failed: %s", fi.Comment, err) - } - } } return "" } |