fix(message): find sent message indexed under alternate wid (lid/pn)#201839
fix(message): find sent message indexed under alternate wid (lid/pn)#201839telmedola wants to merge 1 commit into
Conversation
client.sendMessage() sends via addAndSendMsgToChat and then looks the sent message up with Msg.get(newMsgKey._serialized). For contacts with a lid/phone-number wid pair, WhatsApp Web can index the message under the chat sibling wid, so the lookup fails and the promise resolves with undefined even though the message was delivered. fall back to searching the chat own collection by the random key id (independent of the wid used in the key) and to a key rebuilt with wawebapicontact.getAlternateUserWid, including the sibling chat. When the message still cannot be found, keep the lookup context in window.WWebJS.lastSendMessageDebug as an internal diagnostic aid. related to wwebjs#3767 co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The real bug is that Meta changed the message payload. Instead of returning newMsgKey._serialized, it is now returning newMsgKey.$1. I don't know whether this change is permanent or if Meta will roll it back in the next few hours. However, if it is permanent, we'll need to update all relevant code to accept $1 as a fallback when _serialized is not available. edit: |
Thanks — you're right, That said, the fallback in this PR is complementary rather than redundant: it looks the sent message up by the random id part of the key ( |
Description
client.sendMessage()sometimes resolves withundefinedeven though the message is actually delivered to the recipient.Root cause: in
window.WWebJS.sendMessage, sending and retrieving the sent message are two separate steps:WAWebSendMsgChatAction.addAndSendMsgToChat(chat, message)sends the message;Msg.get(newMsgKey._serialized)looks it up in the collection to return it.For contacts with a lid/phone-number wid pair, WhatsApp Web can index the sent message under the chat's sibling wid (lid ↔ pn), so the lookup by the original key finds nothing and the function silently returns
undefined— after the message has already gone out. Callers then treat a delivered message as failed, which typically leads to duplicate sends.Fix: when the lookup by the original key fails, the sent message is now searched:
m.id.id === newMsgKey.id), which does not depend on the wid used to build the key;WAWebApiContact.getAlternateUserWid), and in the sibling chat's collection.If the message still cannot be found, the lookup context (attempted key, chat id, alternate wid, last message keys of the chat) is stored in
window.WWebJS.lastSendMessageDebugas an internal diagnostic aid, andundefinedis returned as before. No public API change; behavior for already-working cases is unchanged (the original lookup runs first).Related Issue(s)
Related to #3767
Testing Summary
Test Details
Reproduced in production with a customer-service system sending messages to contacts whose
getNumberId()resolves to a@lidwid: the recipient received the message, butsendMessageresolved withundefined(TypeErrorin our caller when readingresponse.id). With this patch,sendMessagereturns the properMessageobject for those contacts; text and media sends to regular@c.uscontacts were also re-tested and behave as before. <-- ajuste conforme sua validação do novo buildEnvironment
Type of Change
Checklist
npm test).index.d.ts) have been updated if necessary. (no public API change)example.js) / documentation have been updated if applicable. (not applicable)