Baileys engine: outbound first message to an unsaved contact shows as an unidentified LID on our own linked phone — any way to force PN addressing on send? #1509
Replies: 4 comments
|
Yes. In v0.10.10, the Baileys adapter deliberately resolves a phone-dialect chat ID to its known LID immediately before sending. The exact path is:
That behavior is already present in the v0.10.10 tag and its recipient resolver. So the PN → LID conversion you inferred is happening inside OpenWA/Baileys even though the REST boundary correctly reports There is no configuration flag in that path to force PN addressing. The conversion is intentional: the code comment records that LID-migrated contacts can reject a PN-addressed send with ack 463 ( Therefore:
The practical workarounds are to save/synchronize the contact before the first outbound message, or tolerate the unidentified label until WhatsApp learns the PN↔LID/contact association (for example after a reply). If the message is delivered, keeping the adapter LID routing is the safer behavior. |
|
From what I understand, Baileys can resolve a PN JID to a LID internally during the send process, even if we pass the recipient as |
|
I reproduced this issue and tracked it down to OpenWA’s Baileys send path, not the API input. Even if you send: <e164>@c.usOpenWA can still resolve that phone-number JID to a LID before calling Baileys The relevant logic is in: inside The current behavior is effectively: const pn = this.host.toEngineJid(chatId);
const lid =
await this.sock().signalRepository?.lidMapping?.getLIDForPN(pn);
return lid ?? chatId;So the flow becomes: That matches the behavior you described: the API receives a PN-style JID, but the actual send can still become LID-addressed below the API layer. I tested the same scenario with bare Baileys using: const result = await sock.onWhatsApp(phone);
const jid = result[0].jid;
await sock.sendMessage(jid, {
text: 'Bare Baileys test',
});Baileys returned: and when sending directly to that JID, the linked phone displayed the actual phone number correctly instead of The important difference was that bare Baileys kept the top-level conversation PN-addressed: while still using LIDs internally where needed for device/session resolution. The fix I tested in OpenWA was changing private async toDeliverableJid(chatId: string): Promise<string> {
return this.host.toEngineJid(chatId);
}So OpenWA now does: and lets Baileys handle LID resolution internally. After rebuilding, the logs changed to: LIDs still appeared internally in session fetching / Most importantly, the linked phone now showed the correct phone number. I also tested a number that had previously appeared as So yes:
One thing worth noting: the existing code comments mention that PN-addressed sends to some LID-migrated accounts may fail with ack error However, with current Baileys, PN-addressed sends still perform LID-aware device/session resolution internally, so forcing the top-level conversation JID to |
|
Thanks @eryoungboy for the reproduction, and for confirming the mechanism rather than just the symptom. Your reading of the send path is correct: The LID preference is deliberate, and we would not remove it. We verified live that WhatsApp rejects PN-addressed 1:1 sends to LID-migrated accounts with ack 463 ("missing tctoken") while the same send addressed to the LID delivers; the comment above The proposed patch also removes the So there is no supported way to force PN today, and no flag is planned. The label clears once WhatsApp associates the two ids, typically after the first reply. Related on the cold-contact side, #830 stays open and upstream-blocked. |
Uh oh!
There was an error while loading. Please reload this page.
Version: v0.10.10 (build 20260724)
Deployment: Docker on EasyPanel — Postgres + Redis adapters, local storage
Engine: Baileys (
@whiskeysockets/baileys@7.0.0-rc13)What we see
When we send the first message through the API to a number that has never messaged the session and is not saved in the phone's address book, the chat that shows up on our own linked phone (the account's primary device) appears as an unidentified id — no name, no number.
The message itself is delivered fine, so this is not #830. In our own app the contact renders correctly; only the linked phone shows the unidentified label. As soon as the contact replies, the name appears there too.
What we already ruled out on our side
<e164>@c.us, never@lid.GET /sessions/{id}/contacts/check/{number}before every send, and it returnswhatsappId: <e164>@c.us— so the id we hand to the gateway is already the phone dialect.[OpenWA send] chatId=55XXXXXXXXXXX@c.us -> status=201So the PN → LID conversion seems to happen below our API call, inside the gateway/engine layer.
Numbers
Across 69 individual chats on one account: contacts who had replied show a name in ~80% of cases; contacts who never replied show as unidentified in ~74%; a couple show the raw number instead. The behavior started the day after we switched the engine from whatsapp-web.js to Baileys, which matches #666 (rc13 shipped in v0.10.1).
Question
Does the Baileys adapter address outbound chats using the LID jid, and is there any setting to force phone-dialect (PN) addressing on send?
We read the changelogs through v0.23.3 and found LID work on the read side (blocklist, group metadata, contacts) but nothing about outbound addressing — before scheduling an upgrade that costs a re-pair across all our sessions, we would like to know whether this area was touched.
All reactions