summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Mansy <36427684+yousefmansy1@users.noreply.github.com>2023-03-09 13:02:31 -0800
committerGitHub <noreply@github.com>2023-03-09 22:02:31 +0100
commit768fb791c52a24b81f5acb10e0bb90e697ebc552 (patch)
treedeeea4f9c32230a2a35986bfa30e65c9594eabb4
parentd00dcf3f58ba8f6a0919e8bdadfe9ba89864ed8d (diff)
downloadmatterbridge-msglm-768fb791c52a24b81f5acb10e0bb90e697ebc552.tar.gz
matterbridge-msglm-768fb791c52a24b81f5acb10e0bb90e697ebc552.tar.bz2
matterbridge-msglm-768fb791c52a24b81f5acb10e0bb90e697ebc552.zip
Use AuthorSignature as a fallback username (telegram) (#1979)
This comes in handy for annoucement type channels where neither the SenderChat or From structs contain name information. Also Tweak username logic as when using a full name the username field can be " " instead of "".
-rw-r--r--bridge/telegram/handlers.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go
index b9cc7e6f..5ffb1eca 100644
--- a/bridge/telegram/handlers.go
+++ b/bridge/telegram/handlers.go
@@ -128,7 +128,9 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa
rmsg.Username = message.From.FirstName
}
if b.GetBool("UseFullName") {
- rmsg.Username = message.From.FirstName + " " + message.From.LastName
+ if message.From.FirstName != "" && message.From.LastName != "" {
+ rmsg.Username = message.From.FirstName + " " + message.From.LastName
+ }
}
if rmsg.Username == "" {
rmsg.Username = message.From.UserName
@@ -148,7 +150,9 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa
rmsg.Username = message.SenderChat.FirstName
}
if b.GetBool("UseFullName") {
- rmsg.Username = message.SenderChat.FirstName + " " + message.SenderChat.LastName
+ if message.SenderChat.FirstName != "" && message.SenderChat.LastName != "" {
+ rmsg.Username = message.SenderChat.FirstName + " " + message.SenderChat.LastName
+ }
}
if rmsg.Username == "" || rmsg.Username == "Channel_Bot" {
@@ -164,6 +168,11 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa
}
}
+ // Fallback on author signature (used in "channel" type of chat)
+ if rmsg.Username == "" && message.AuthorSignature != "" {
+ rmsg.Username = message.AuthorSignature
+ }
+
// if we really didn't find a username, set it to unknown
if rmsg.Username == "" {
rmsg.Username = unknownUser