[BUG] Messages sent to Meta AI from the phone show up as self-chat messages on a linked device, and keep getting redelivered
Describe the bug If you send something to Meta AI from your phone, the copy that reaches a Baileys linked device gets filed under your own chat instead of the Meta AI chat. Baileys then sends the delivery receipt for the wrong chat, so WhatsApp never marks it as delivered and keeps sending it again.
We found this the hard way. My wife sent a phone number to Meta AI on 1 Sep. Our self-chat assistant (Hermes Agent, which runs on Baileys) picked it up as if she had sent it to the assistant, and replied. Then the same message kept coming back every 7-8 minutes, for more than two weeks. Over 1,700 copies.
It comes from decodeMessageNode in src/Utils/decode-wa-message.ts (still the same on master):
if (recipient && !isJidMetaAI(recipient)) {
// ...
chatId = recipient
} else {
// ...
chatId = from
}With a Meta AI recipient it falls through to chatId = from, so key.remoteJid ends up as your own JID. handleMessage then sends:
<receipt id='<id>' recipient='<own-lid>@lid' to='<own-lid>@lid' type='sender'/>That recipient doesn't match the message, and the server just keeps redelivering the same stored stanza. Same ciphertext every time, only t and sts change. This is what the incoming stanza looks like (IDs removed):
<message from='<own-lid>@lid' type='text' id='<id>' notify='<name>'
recipient='867051314767696@bot' peer_recipient_pn='<own-pn>:<device>@s.whatsapp.net' t='...' sts='...'>
<registration>...</registration>
<enc count='4' v='2' type='msg'>...</enc>
<biz actual_actors='1' privacy_mode_ts='...' host_storage='2'/>
</message>To Reproduce
- Link a Baileys client to an account as a companion device.
- From the phone, send any message to Meta AI.
- On the Baileys side, the
messages.upsertfor that message hasremoteJidset to your own JID, and the receipt above goes out. - Leave it running. The same message id comes back every few minutes, and in a burst after a reconnect.
To be fair, we've only seen this with one message on one account, so this is what we observed rather than a tested repro.
Expected behavior
The copy should be filed under the Meta AI chat, and the receipt should name the bot as the recipient. That's what whatsmeow does (buildBaseReceipt: to is the sender, recipient is the stanza's recipient):
<receipt id='<id>' to='<own-lid>@lid' recipient='867051314767696@bot' type='sender'/>Environment (please complete the following information):
- Is this on a server? No, a MacBook Air at home that stays on. Hermes Agent's WhatsApp bridge, Node 22, Baileys 7.0.0-rc13.
- What do your
connectOptionslook like?browser: ['Hermes Agent', 'Chrome', '120.0'],syncFullHistory: false,markOnlineOnConnect: false,getMessagereturns{ conversation: '' },versionfromfetchLatestBaileysVersion(). - Do you have multiple clients on the same IP? Yes, two on the same home connection, each on a different WhatsApp number: this one (Hermes on a MacBook Air, my wife's number) and an OpenClaw WhatsApp bot on another machine for my own number. The message in question was sent from my wife's account, so only the Hermes client was involved.
- Are you using a proxy? No.
Additional context
What stopped it for us is a workaround in our own bridge, not a change to Baileys. For every incoming message node from our own account with a @bot recipient, we send the correct receipt ourselves.
The order turned out to matter. Sending ours after Baileys' own receipt changed nothing, we got 4 more copies in the next half hour. Sending it first, straight from a CB:message listener before Baileys has decrypted anything, fixed it: one more copy, then nothing for 9+ hours, reconnects included. I don't know why. My guess is the server only takes the first receipt a device sends for a message.
Happy to share logs or the patch.
Source: WhiskeySockets/Baileys