summaryrefslogtreecommitdiffstats
path: root/bridge/whatsappmulti/handlers.go
diff options
context:
space:
mode:
authorJoseph Mansy <36427684+yousefmansy1@users.noreply.github.com>2023-03-14 15:12:45 -0700
committerGitHub <noreply@github.com>2023-03-14 23:12:45 +0100
commitd42277979abcefe885bb068cad989eaf71460872 (patch)
tree28627bc93cd50851af1c791d496394e379fc4ae9 /bridge/whatsappmulti/handlers.go
parent24cf007a74bf1e04456ae05c9ccc73b1fb823b88 (diff)
downloadmatterbridge-msglm-d42277979abcefe885bb068cad989eaf71460872.tar.gz
matterbridge-msglm-d42277979abcefe885bb068cad989eaf71460872.tar.bz2
matterbridge-msglm-d42277979abcefe885bb068cad989eaf71460872.zip
Support topic changes and Join/Leave messages (whatsapp) (#2017)
Diffstat (limited to 'bridge/whatsappmulti/handlers.go')
-rw-r--r--bridge/whatsappmulti/handlers.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/bridge/whatsappmulti/handlers.go b/bridge/whatsappmulti/handlers.go
index ae825f75..8791df5e 100644
--- a/bridge/whatsappmulti/handlers.go
+++ b/bridge/whatsappmulti/handlers.go
@@ -21,9 +21,82 @@ func (b *Bwhatsapp) eventHandler(evt interface{}) {
switch e := evt.(type) {
case *events.Message:
b.handleMessage(e)
+ case *events.GroupInfo:
+ b.handleGroupInfo(e)
}
}
+func (b *Bwhatsapp) handleGroupInfo(event *events.GroupInfo) {
+
+ b.Log.Debugf("Receiving event %#v", event)
+
+ switch {
+ case event.Join != nil:
+ b.handleUserJoin(event)
+ case event.Leave != nil:
+ b.handleUserLeave(event)
+ case event.Topic != nil:
+ b.handleTopicChange(event)
+ }
+}
+
+func (b *Bwhatsapp) handleUserJoin(event *events.GroupInfo) {
+ for _, joinedJid := range event.Join {
+ senderName := b.getSenderNameFromJID(joinedJid)
+
+ rmsg := config.Message{
+ UserID: joinedJid.String(),
+ Username: senderName,
+ Channel: event.JID.String(),
+ Account: b.Account,
+ Protocol: b.Protocol,
+ Event: config.EventJoinLeave,
+ Text: "joined chat",
+ }
+
+ b.Remote <- rmsg
+ }
+}
+func (b *Bwhatsapp) handleUserLeave(event *events.GroupInfo) {
+ for _, leftJid := range event.Leave {
+ senderName := b.getSenderNameFromJID(leftJid)
+
+ rmsg := config.Message{
+ UserID: leftJid.String(),
+ Username: senderName,
+ Channel: event.JID.String(),
+ Account: b.Account,
+ Protocol: b.Protocol,
+ Event: config.EventJoinLeave,
+ Text: "left chat",
+ }
+
+ b.Remote <- rmsg
+ }
+}
+func (b *Bwhatsapp) handleTopicChange(event *events.GroupInfo) {
+ msg := event.Topic
+ senderJid := msg.TopicSetBy
+ senderName := b.getSenderNameFromJID(senderJid)
+
+ text := msg.Topic
+ if text == "" {
+ text = "removed topic"
+ }
+
+ rmsg := config.Message{
+ UserID: senderJid.String(),
+ Username: senderName,
+ Channel: event.JID.String(),
+ Account: b.Account,
+ Protocol: b.Protocol,
+ Event: config.EventTopicChange,
+ Text: "Topic changed: " + text,
+ }
+
+ b.Remote <- rmsg
+}
+
func (b *Bwhatsapp) handleMessage(message *events.Message) {
msg := message.Message
switch {