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

Add support for sender_chat (telegram) (#1677)

* Add support for sender_chat (telegram)

Fixes #1654
https://core.telegram.org/bots/api#december-7-2021

* Add debuglevel option

Add `debuglevel=1` in telegram config to increase debug
This commit is contained in:
Wim 2022-02-04 16:15:19 +01:00 committed by GitHub
parent 4801850013
commit 4b226a6a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import (
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "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/go-telegram-bot-api/telegram-bot-api/v5"
) )
@ -123,6 +124,25 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa
} }
} }
if message.SenderChat != nil { //nolint:nestif
rmsg.UserID = strconv.FormatInt(message.SenderChat.ID, 10)
if b.GetBool("UseFirstName") {
rmsg.Username = message.SenderChat.FirstName
}
if rmsg.Username == "" || rmsg.Username == "Channel_Bot" {
rmsg.Username = message.SenderChat.UserName
if rmsg.Username == "" || rmsg.Username == "Channel_Bot" {
rmsg.Username = message.SenderChat.FirstName
}
}
// only download avatars if we have a place to upload them (configured mediaserver)
if b.General.MediaServerUpload != "" || (b.General.MediaServerDownload != "" && b.General.MediaDownloadPath != "") {
b.handleDownloadAvatar(message.SenderChat.ID, rmsg.Channel)
}
}
// if we really didn't find a username, set it to unknown // if we really didn't find a username, set it to unknown
if rmsg.Username == "" { if rmsg.Username == "" {
rmsg.Username = unknownUser rmsg.Username = unknownUser
@ -139,6 +159,10 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
continue continue
} }
if b.GetInt("debuglevel") == 1 {
spew.Dump(update.Message)
}
var message *tgbotapi.Message var message *tgbotapi.Message
rmsg := config.Message{Account: b.Account, Extra: make(map[string][]interface{})} rmsg := config.Message{Account: b.Account, Extra: make(map[string][]interface{})}