matterbridge
matterbridge copied to clipboard
"Someone" instead of real nick when messaging from WhatsApp via web or desktop app (to Nextcloud Talk)
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 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.
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"
}
Having the same issue with WhatsApp ↔ Matrix.
Pls fix.
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.
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?
@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 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
Okay...
@42wim What do you think of the idea of always just using the PushName?
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.
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
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...