matterbridge icon indicating copy to clipboard operation
matterbridge copied to clipboard

"Someone" instead of real nick when messaging from WhatsApp via web or desktop app (to Nextcloud Talk)

Open pikseliahky opened this issue 2 years ago • 3 comments

Describe the bug When sending message from WhatsApp via web interface or desktop app, the sender's nick is not recognized and is instead replaced by "Someone" in the bridged message, which makes it unable to recognize the sender and thus makes group conversations partially impossible. However, messages sent from the same account from an iPhone app get bridged with a correctly displayed nick. This behaviour remains constant even after reloading/reopening/refreshing the sending client app, or sending multiple messages.

To Reproduce Set up a WhatsApp <-> Nextcloud Talk bridge, send messages from WhatsApp browser-based or desktop client to the bridged group/channel.

Expected behavior The actual nick of the sender is always displayed correctly regardless of the sending WhatsApp device/interface.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Matterbridge version: 1.25.2

Additional context Config file content:

###################################################################
# NCTalk (Nextcloud Talk)
###################################################################

[nctalk.bridge]
# Url of your Nextcloud server
Server = "https://xxxxxxxx.xx"

# Enable to not verify the certificate on your Nextcloud server.
# e.g. when using selfsigned certificates
# OPTIONAL (default false)
SkipTLSVerify=true

# Username of the bot
Login = "xxxx"

# Password of the bot
Password = "xxxxxxxx"

# Suffix for Guest Users
GuestSuffix = " (Guest)"

# Separate display name (Note: needs to be configured from Nextcloud Talk to work)
SeparateDisplayName=false

RemoteNickFormat="{PROTOCOL}:{NICK} \r\n"

###################################################################
#WHATSAPP section
###################################################################

[whatsapp.mywhatsapp]
Number="+xxxxxxxxxxx"
SessionFile="session-xxxxxxxx.gob"
QrOnWhiteTerminal=false

# Messages will be seen by other WhatsApp contacts as coming from the bridge. 
# Original nick will be part of the message.
RemoteNickFormat="{NICK} \r\n"

###################################################################
#Gateway configuration
###################################################################

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="whatsapp.mywhatsapp"
channel="[email protected]"

[[gateway.inout]]
account="nctalk.bridge"
channel="xxxxxxxxxx"

pikseliahky avatar Aug 20 '22 16:08 pikseliahky

@pikseliahky Sorry to bother you but I wonder if you can send me your already compiled binary for linux through any link? Apparently the ability to compile it with GO no longer works.

ghost avatar Aug 23 '22 02:08 ghost

First, this is the same as #1363 (but that one was created for the old whatsapp bridge) If you are using the new bridge (whatsappmulti), you can test this ugly workaround i did for it (that i didn't test but got told that it does work):

diff --git a/bridge/whatsappmulti/handlers.go b/bridge/whatsappmulti/handlers.go
index c6b96a5e..dd7e87bd 100644
--- a/bridge/whatsappmulti/handlers.go
+++ b/bridge/whatsappmulti/handlers.go
@@ -51,7 +51,7 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
 	senderJID := messageInfo.Sender
 	channel := messageInfo.Chat
 
-	senderName := b.getSenderName(messageInfo.Sender)
+	senderName := b.getSenderName(messageInfo.Sender, messageInfo.PushName)
 	if senderName == "" {
 		senderName = "Someone" // don't expose telephone number
 	}
@@ -118,7 +118,7 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
 	imsg := msg.Message.GetImageMessage()
 
 	senderJID := msg.Info.Sender
-	senderName := b.getSenderName(senderJID)
+	senderName := b.getSenderName(senderJID, msg.Info.PushName)
 	ci := imsg.GetContextInfo()
 
 	if senderJID == (types.JID{}) && ci.Participant != nil {
@@ -181,7 +181,7 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
 	imsg := msg.Message.GetVideoMessage()
 
 	senderJID := msg.Info.Sender
-	senderName := b.getSenderName(senderJID)
+	senderName := b.getSenderName(senderJID, msg.Info.PushName)
 	ci := imsg.GetContextInfo()
 
 	if senderJID == (types.JID{}) && ci.Participant != nil {
@@ -238,7 +238,7 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
 	imsg := msg.Message.GetAudioMessage()
 
 	senderJID := msg.Info.Sender
-	senderName := b.getSenderName(senderJID)
+	senderName := b.getSenderName(senderJID, msg.Info.PushName)
 	ci := imsg.GetContextInfo()
 
 	if senderJID == (types.JID{}) && ci.Participant != nil {
@@ -295,7 +295,7 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
 	imsg := msg.Message.GetDocumentMessage()
 
 	senderJID := msg.Info.Sender
-	senderName := b.getSenderName(senderJID)
+	senderName := b.getSenderName(senderJID, msg.Info.PushName)
 	ci := imsg.GetContextInfo()
 
 	if senderJID == (types.JID{}) && ci.Participant != nil {
diff --git a/bridge/whatsappmulti/helpers.go b/bridge/whatsappmulti/helpers.go
index a7cc5c98..22fcb540 100644
--- a/bridge/whatsappmulti/helpers.go
+++ b/bridge/whatsappmulti/helpers.go
@@ -17,7 +17,7 @@ type ProfilePicInfo struct {
 	Status int16  `json:"status"`
 }
 
-func (b *Bwhatsapp) getSenderName(senderJid types.JID) string {
+func (b *Bwhatsapp) getSenderName(senderJid types.JID, AltName string) string {
 	if sender, exists := b.contacts[senderJid]; exists {
 		if sender.FullName != "" {
 			return sender.FullName
@@ -64,6 +64,10 @@ func (b *Bwhatsapp) getSenderName(senderJid types.JID) string {
 		}
 	}
 
+	if AltName != "" {
+		return AltName
+	}
+
 	return "Someone"
 }

Th3-822 avatar Aug 23 '22 18:08 Th3-822

Having the same issue with WhatsApp ↔ Matrix.

Pls fix.

drequivalent avatar Sep 21 '22 15:09 drequivalent

I'll try that patch, will convert into a PR if it works well.

The author of whatsmeow suggested that we could just always use the PushName since it is always there.

ilmaisin avatar Nov 26 '22 20:11 ilmaisin

https://github.com/42wim/matterbridge/blob/0c839469839314f432703b8294cf318d5d16d785/bridge/whatsappmulti/helpers.go#L21-L69

We have code already in the repo that should be able to revet to the PushName if it can't get the name of the contact. Why does it not work for this specific case?

ilmaisin avatar Nov 26 '22 21:11 ilmaisin

@Th3-822 The patch seems to indeed work, but I don't really understand why, see the previous message. Could you explain it a bit?

ilmaisin avatar Nov 27 '22 22:11 ilmaisin

@ilmaisin i didn't test anything neither know how to use Go I could only assume that it was * contacts aren't updating or * somehow it can't match the JID (don't even know if both have the @s.domain stuff)...

But this also shows Someone when user isn't in contacts, so getSenderName() is only using the (phone) contacts anyways, it still needs a fallback for the PushName in the MessageInfo object for non-contacts, thats was i added to get it working after checking MessageInfo on the docs and Googling the Go syntax

The contacts code still needs to be checked to see why isn't getting the contacts on Connect... And add listeners for the events of Contact, PushName and maybe BusinessName changes to keep them updated

Th3-822 avatar Nov 28 '22 01:11 Th3-822

Okay...

@42wim What do you think of the idea of always just using the PushName?

ilmaisin avatar Nov 28 '22 02:11 ilmaisin

If I send from Whatsapp Web, .0:5 gets added to the JID before the @ sign. It probably is the thing that confuses the getSenderName function.

ilmaisin avatar Nov 29 '22 12:11 ilmaisin

There are two types of JIDs: regular JID pairs (user and server) and AD-JIDs (user, agent and device).

Maybe using ParseJID and using only the user part (as server is always s.whatsapp.com) for the contacts cache, or just removing manually the agent and device parts

Th3-822 avatar Nov 29 '22 15:11 Th3-822

There are two types of JIDs: regular JID pairs (user and server) and AD-JIDs (user, agent and device).

Maybe using ParseJID and using only the user part (as server is always s.whatsapp.com) for the contacts cache, or just removing manually the agent and devie parts

I'm currently working on that...

ilmaisin avatar Nov 29 '22 15:11 ilmaisin