diff options
Diffstat (limited to 'bridge/telegram/handlers.go')
-rw-r--r-- | bridge/telegram/handlers.go | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 5ffb1eca..985397ef 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -11,7 +11,7 @@ import ( "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" "github.com/davecgh/go-spew/spew" - tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + tgbotapi "github.com/matterbridge/telegram-bot-api/v6" ) func (b *Btelegram) handleUpdate(rmsg *config.Message, message, posted, edited *tgbotapi.Message) *tgbotapi.Message { @@ -20,6 +20,11 @@ func (b *Btelegram) handleUpdate(rmsg *config.Message, message, posted, edited * if posted.Text == "/chatId" { chatID := strconv.FormatInt(posted.Chat.ID, 10) + // Handle chat topics + if posted.IsTopicMessage { + chatID = chatID + "/" + strconv.Itoa(posted.MessageThreadID) + } + _, err := b.Send(config.Message{ Channel: chatID, Text: fmt.Sprintf("ID of this chat: %s", chatID), @@ -91,7 +96,8 @@ func (b *Btelegram) handleForwarded(rmsg *config.Message, message *tgbotapi.Mess // handleQuoting handles quoting of previous messages func (b *Btelegram) handleQuoting(rmsg *config.Message, message *tgbotapi.Message) { - if message.ReplyToMessage != nil { + // Used to check if the message was a reply to the root topic + if message.ReplyToMessage != nil && !(message.ReplyToMessage.MessageID == message.MessageThreadID) { //nolint:nestif usernameReply := "" if message.ReplyToMessage.From != nil { if b.GetBool("UseFirstName") { @@ -211,9 +217,14 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { // set the ID's from the channel or group message rmsg.ID = strconv.Itoa(message.MessageID) rmsg.Channel = strconv.FormatInt(message.Chat.ID, 10) + if message.MessageThreadID != 0 { + rmsg.Channel += "/" + strconv.Itoa(message.MessageThreadID) + } // preserve threading from telegram reply - if message.ReplyToMessage != nil { + if message.ReplyToMessage != nil && + // Used to check if the message was a reply to the root topic + !(message.ReplyToMessage.MessageID == message.MessageThreadID) { rmsg.ParentID = strconv.Itoa(message.ReplyToMessage.MessageID) } @@ -326,12 +337,12 @@ func (b *Btelegram) maybeConvertWebp(name *string, data *[]byte) { // handleDownloadFile handles file download func (b *Btelegram) handleDownload(rmsg *config.Message, message *tgbotapi.Message) error { - size := 0 + size := int64(0) var url, name, text string switch { case message.Sticker != nil: text, name, url = b.getDownloadInfo(message.Sticker.FileID, ".webp", true) - size = message.Sticker.FileSize + size = int64(message.Sticker.FileSize) case message.Voice != nil: text, name, url = b.getDownloadInfo(message.Voice.FileID, ".ogg", true) size = message.Voice.FileSize @@ -348,7 +359,7 @@ func (b *Btelegram) handleDownload(rmsg *config.Message, message *tgbotapi.Messa text = " " + message.Document.FileName + " : " + url case message.Photo != nil: photos := message.Photo - size = photos[len(photos)-1].FileSize + size = int64(photos[len(photos)-1].FileSize) text, name, url = b.getDownloadInfo(photos[len(photos)-1].FileID, "", true) } @@ -452,7 +463,7 @@ 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, parentID int) (string, error) { +func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, threadid int, parentID int) (string, error) { var media []interface{} for _, f := range msg.Extra["file"] { fi := f.(config.FileInfo) @@ -502,7 +513,7 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, parentID } } - return b.sendMediaFiles(msg, chatid, parentID, media) + return b.sendMediaFiles(msg, chatid, threadid, parentID, media) } func (b *Btelegram) handleQuote(message, quoteNick, quoteMessage string) string { |