diff options
author | Wim <wim@42.be> | 2022-03-13 18:48:30 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2022-03-20 14:57:48 +0100 |
commit | 4da1444ffc5b55b01af29d9bbe56f36e25f0907c (patch) | |
tree | 0c0af43f48ebcb3591d6be9ce70a405ea098f7d5 | |
parent | 21c4e56d1631008a5a3cff012a36859dfb1ccb4d (diff) | |
download | matterbridge-msglm-4da1444ffc5b55b01af29d9bbe56f36e25f0907c.tar.gz matterbridge-msglm-4da1444ffc5b55b01af29d9bbe56f36e25f0907c.tar.bz2 matterbridge-msglm-4da1444ffc5b55b01af29d9bbe56f36e25f0907c.zip |
Check for Conversation on receiving messages (whatsapp)
-rw-r--r-- | bridge/whatsapp/handlers.go | 46 | ||||
-rw-r--r-- | bridge/whatsapp/whatsapp.go | 9 |
2 files changed, 29 insertions, 26 deletions
diff --git a/bridge/whatsapp/handlers.go b/bridge/whatsapp/handlers.go index ff905b04..84336012 100644 --- a/bridge/whatsapp/handlers.go +++ b/bridge/whatsapp/handlers.go @@ -46,44 +46,52 @@ func (b *Bwhatsapp) handleMessage(message *events.Message) { func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.Message) { senderJID := messageInfo.Sender + channel := messageInfo.Chat senderName := b.getSenderName(messageInfo.Sender) if senderName == "" { senderName = "Someone" // don't expose telephone number } - if msg.GetExtendedTextMessage() == nil { + if msg.GetExtendedTextMessage() == nil && msg.GetConversation() == "" { + b.Log.Debugf("message without text content? %#v", msg) return } - text := msg.GetExtendedTextMessage().GetText() - ci := msg.GetExtendedTextMessage().GetContextInfo() + var text string - if senderJID == (types.JID{}) && ci.Participant != nil { - senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) - } + if msg.GetExtendedTextMessage() == nil { + text = msg.GetConversation() + } else { + text = msg.GetExtendedTextMessage().GetText() + ci := msg.GetExtendedTextMessage().GetContextInfo() - if ci.MentionedJid != nil { - // handle user mentions - for _, mentionedJID := range ci.MentionedJid { - numberAndSuffix := strings.SplitN(mentionedJID, "@", 2) + if senderJID == (types.JID{}) && ci.Participant != nil { + senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) + } - // mentions comes as telephone numbers and we don't want to expose it to other bridges - // replace it with something more meaninful to others - mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer)) - if mention == "" { - mention = "someone" - } + if ci.MentionedJid != nil { + // handle user mentions + for _, mentionedJID := range ci.MentionedJid { + numberAndSuffix := strings.SplitN(mentionedJID, "@", 2) + + // mentions comes as telephone numbers and we don't want to expose it to other bridges + // replace it with something more meaninful to others + mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer)) + if mention == "" { + mention = "someone" + } - text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1) + text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1) + } } } rmsg := config.Message{ UserID: senderJID.String(), Username: senderName, - Text: msg.GetExtendedTextMessage().GetText(), - Channel: ci.GetRemoteJid(), + Text: text, + Channel: channel.String(), Account: b.Account, Protocol: b.Protocol, Extra: make(map[string][]interface{}), diff --git a/bridge/whatsapp/whatsapp.go b/bridge/whatsapp/whatsapp.go index 7ee4045f..7e79ecaf 100644 --- a/bridge/whatsapp/whatsapp.go +++ b/bridge/whatsapp/whatsapp.go @@ -324,14 +324,9 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) { message.Conversation = &text - /* - message.ExtendedTextMessage = &proto.ExtendedTextMessage{ - Text: &text, - } - */ - ID := whatsmeow.GenerateMessageID() - b.Log.Debugf("=> Sending %#v to %#v with ID %s", message, groupJID, ID) + + b.Log.Debugf("=> Sending %#v", message) _, err := b.wc.SendMessage(groupJID, ID, &message) |