mautrix / whatsapp

A Matrix-WhatsApp puppeting bridge
https://maunium.net/go/mautrix-whatsapp
GNU Affero General Public License v3.0
1.29k stars 175 forks source link

Inviting a non-contact matrix puppet of whatsApp user to a new room don't work as expected #284

Open wlongo opened 3 years ago

wlongo commented 3 years ago

When i tried to invite the matrix puppet of a whatsapp contact to a room ( @whatsapp_xxxxxxxxxxxx:matrix-home-server.org ) , the puppet didn't get properly invited.

Some context for this behavior:

  1. the contact was completely new to the whatsapp bridge and was not on the phone's contact list. 2.the contact was not on matrix as well.
  2. If i use the !wa pm --force ... phone_number to initiate the chat, everything works as expected.

I investigated the issue here and i found out that this was because the bridge bot was silently receiving the error "SynapseError: 403 - Application service has not registered this user" and thus, aborting the process of creating the private portal.

I located the issue on the HandlePuppetInvite handler when it was checking the members of the room ( method joinAndCheckMembers () ). I suppose since the puppet was recently created, it was not yet registered on matrix.

I don't know if this was an intentional behavior, but i patched the code and now it's working perfectly.

If you think it's valid to provide a PR, let me know !

ptimatth commented 1 year ago

I think i have an equivalent issue but in the other way.

An unknown contact send me a message on WA and the bridge has crashed after create the room and invite me in.

Mar 29, 2023 13:51:49 WRN Failed to insert IMMEDIATE/336XXXXXXXX@s.whatsapp.net with priority 0: pq: null value in column "queue_id" of relation "backfill_queue" violates not-null constraint module=Database/Backfillpanic:
runtime error: invalid memory address or nil pointer dereference[signal SIGSEGV: segmentation violation code=0x1 addr=0x0
 pc=0x575901]

goroutine 53278 [running]:
database/sql.(*Rows).close(0x0, {0x0, 0x0})
        /usr/local/go/src/database/sql/sql.go:3274 +0xa1database/sql.(*Rows).Close
(0x40ea2b?)
        /usr/local/go/src/database/sql/sql.go:3270 +0x1d
maunium.net/go/mautrix/util/dbutil.(*LoggingRows).Close(0xc000470e00)   /builds/mautrix/whatsapp/.cache/pkg/mod/maunium.net/go/mautrix@v0.15.0/util/dbutil/connlog.go:129 +0x2a

maunium.net/go/mautrix-whatsapp/database.(*Backfill).Insert(0xc000803d80)
        /builds/mautrix/whatsapp/database/backfill.go:230 +0x5ca
main.(*User).EnqueueImmediateBackfills(0xc0003887e0, {0xc0006f7990, 0x1, 0x116434a?})
/builds/mautrix/whatsapp/historysync.go:514 +0x4dmain.(*Portal).CreateMatrixRoom(0xc000786880, 0xc0003887e0
, 0x0, 0x0, 0x1)
        /builds/mautrix/whatsapp/portal.go:1750 +0x2529main.(*Portal).handleMessageLoopItem(0xc000786880
, {0xc000460b40, 0x0, 0x0, 0x0, 0xc0003887e0})  /builds/mautrix/whatsapp/portal.go:302 +
0x145
main.(*Portal).handleMessageLoop(0xc000786880)
        /builds/mautrix/whatsapp/portal.go:391 +0x1cd
created by main.(*WABridge).newBlankPortal
        /builds/mautrix/whatsapp/portal.go:203 +0x238