diff options
author | Joseph Mansy <36427684+yousefmansy1@users.noreply.github.com> | 2023-04-03 14:27:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 23:27:44 +0200 |
commit | 5bbe422161a8b924ef502c7ae6d60b01cb02ae46 (patch) | |
tree | dd49b8000ef4347bdc5a72594944eb0a8d55a330 | |
parent | 6500714a93c6658749df8e477a729d9053f5c9b1 (diff) | |
download | matterbridge-msglm-5bbe422161a8b924ef502c7ae6d60b01cb02ae46.tar.gz matterbridge-msglm-5bbe422161a8b924ef502c7ae6d60b01cb02ae46.tar.bz2 matterbridge-msglm-5bbe422161a8b924ef502c7ae6d60b01cb02ae46.zip |
Support telegram chat Join/Leave updates (#2019)
Co-authored-by: Wim <wim@42.be>
-rw-r--r-- | bridge/telegram/handlers.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 9f8d1c38..efafa9d6 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -199,6 +199,8 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { spew.Dump(update.Message) } + b.handleGroupUpdate(update) + var message *tgbotapi.Message rmsg := config.Message{Account: b.Account, Extra: make(map[string][]interface{})} @@ -261,6 +263,50 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { } } +func (b *Btelegram) handleGroupUpdate(update tgbotapi.Update) { + msg := update.Message + + switch { + case msg.NewChatMembers != nil: + b.handleUserJoin(update) + case msg.LeftChatMember != nil: + b.handleUserLeave(update) + } +} + +func (b *Btelegram) handleUserJoin(update tgbotapi.Update) { + msg := update.Message + for _, user := range msg.NewChatMembers { + rmsg := config.Message{ + UserID: strconv.FormatInt(user.ID, 10), + Username: user.FirstName, // for some reason all the other name felids are empty on this event (at least for me) + Channel: strconv.FormatInt(msg.Chat.ID, 10), + Account: b.Account, + Protocol: b.Protocol, + Event: config.EventJoinLeave, + Text: "joined chat", + } + b.Remote <- rmsg + } +} + +func (b *Btelegram) handleUserLeave(update tgbotapi.Update) { + msg := update.Message + user := msg.LeftChatMember + + rmsg := config.Message{ + UserID: strconv.FormatInt(user.ID, 10), + Username: user.FirstName, // for some reason all the other name felids are empty on this event (at least for me) + Channel: strconv.FormatInt(msg.Chat.ID, 10), + Account: b.Account, + Protocol: b.Protocol, + Event: config.EventJoinLeave, + Text: "left chat", + } + + b.Remote <- rmsg +} + // handleDownloadAvatar downloads the avatar of userid from channel // sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful. // logs an error message if it fails |