Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 311ee09f06024fc241bbab0930f50f6b65e3bf9c Author: Wohlstand <admin@wohlnet.ru> Date: Tue Jun 03 17:53:46 2025 +0000 Telegram: If attachments of mixed types, send everything as documents diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 85a2ba9..dd23772 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -5126 +51241 @@ func (b *Btelegram) handleEdit(msg *config.Message, chatid int64) (string, error  // handleUploadFile handles native upload of files  func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, threadid int, parentID int) (string, error) {   var media []interface{} + equal := true + first := true + var prev string + + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + var ftype string + + switch filepath.Ext(fi.Name) { + case ".jpg", ".jpe", ".png": + ftype = "image" + case ".mp4", ".m4v": + ftype = "video" + case ".mp3", ".oga", ".ogg", ".opus", ".flac": + ftype = "audio" + default: + ftype = "document" + } + + if ftype == "document" { + equal = false + break + } + + if first { + prev = ftype + equal = true + } else { + if prev != ftype { + equal = false + } + prev = ftype + } + } +   for _, f := range msg.Extra["file"] {   fi := f.(config.FileInfo)   file := tgbotapi.FileBytes{ @@ -5236 +55815 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, threadid   fi.Comment = makeHTML(html.EscapeString(fi.Comment))   }   + if !equal { + dc := tgbotapi.NewInputMediaDocument(file) + if fi.Comment != "" { + dc.Caption, dc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) + } + media = append(media, dc) + continue + } +   switch filepath.Ext(fi.Name) {   case ".jpg", ".jpe", ".png":   pc := tgbotapi.NewInputMediaPhoto(file) @@ -53621 +58022 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, threadid   vc.Caption, vc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)   }   media = append(media, vc) - case ".mp3", ".oga": + case ".mp3", ".oga", ".ogg", ".opus", ".flac":   ac := tgbotapi.NewInputMediaAudio(file)   if fi.Comment != "" {   ac.Caption, ac.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment)   } + ac.Caption = fi.Name   media = append(media, ac) - case ".ogg": - voc := tgbotapi.NewVoice(chatid, file) - voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) - voc.ReplyToMessageID = parentID - res, err := b.c.Send(voc) - if err != nil { - return "", err - } - return strconv.Itoa(res.MessageID), nil +// case ".ogg": +// voc := tgbotapi.NewVoice(chatid, file) +// voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) +// voc.ReplyToMessageID = parentID +// res, err := b.c.Send(voc) +// if err != nil { +// return "", err +// } +// return strconv.Itoa(res.MessageID), nil   default:   dc := tgbotapi.NewInputMediaDocument(file)   if fi.Comment != "" {