getChats function suddenly stopped working. In a few hours ago it was working. Nothing changed in my envoirment.
Steps to reproduce the behavior:
let client = new Client({puppeteer:{ headless: true, 'product': 'chrome', args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--no-first-run', '--no-zygote', '--single-process', '--disable-gpu']}})
client.on('qr', (qr) => {
QRCode.toDataURL(qr, function (err, url) {
/* SEND BASE64 TO FRONTEND */
})
})
client.on('ready', async () => {
/* START TO GET CHATS ON NEXT STEP */
});
client.getChats().then((chats)=>{ /* RETURN DATA TO FRONTEND */ })
...
Get chats object.
Library
Error on Logentries in Heroku with Puppeteer buildpack:
21 Dec 2020 20:30:08.070340 <190>1 2020-12-21T23:30:07.453981+00:00 app web.1 - - (node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 38)
21 Dec 2020 20:30:08.070188 <190>1 2020-12-21T23:30:07.453774+00:00 app web.1 - - (node:23) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
at Client.getChats (/app/node_modules/whatsapp-web.js/src/Client.js:493:22)
at processTicksAndRejections (internal/process/task_queues.js:89:5)Exception
Please run this to identify which chat is having the issue:
client.on('ready', () => {
const chatIds = await client.pupPage.evaluate(async () => {
const chats = await window.WWebJS.getChats();
return chats.map(c => c.id._serialized);
});
let chatCount = 0;
for (let chatId of chatIds) {
try {
const chat = await client.getChatById(chatId);
if (!chat) {
console.log(`Could not serialize chat ${chatId}`);
} else {
chatCount++;
}
} catch (e) {
console.log(`Could not serialize chat ${chatId}`, e);
}
}
console.log(`Correctly got ${chatCount} chats`);
});
With your code, Logentries returned:
Correctly got 109 chats
Could not serialize chat [hidden]@c.us TypeError: Cannot read property 'isGroup' of undefined
This is a business contact: 5511999910621
Can you identify any particularities for that chat ID that has a problem with serialization? Are there any special messages in the conversation?
This is a business contact: 5511999910621 (with official whatsapp api enabled to interact)
This is the id? It seems like it has the brazilian aditional 9. Usually whatsapp get ride of it
It's a brazilian number: [email protected]
Error Could not serialize chat TypeError: Cannot read property 'isGroup' of undefined
I tried chatting with the number and everything seems to be okay.
Please run the client in headless: false so you can see the chrome window, open the console and run the following:
await window.WWebJS.getChatModel(Store.Chat.get("[email protected]"));
and post the results.
I believe it worked for you because you didn't interact with the chat. Here for me, the chat featured action buttons (yes or no), waited for a text response at the end of the conversation but I didn't respond. I believe that if you interact with the chat, you can reproduce the error.
Printscreen of chat: https://postimg.cc/HcvmdykD
@frmontini could you please take the steps I outlined in my previous message?
This issue was addressed in a previous release, but there may be other properties that need to be filtered out. The steps I mentioned should help identify what these are.
Please run the client in
headless: falseso you can see the chrome window, open the console and run the following:await window.WWebJS.getChatModel(Store.Chat.get("[email protected]"));and post the results.
The result following your steps:
{"id":"[email protected]","pendingMsgs":false,"lastReceivedKey":{"fromMe":false,"remote":"[email protected]","id":"1606AE6C987B4EDC39","_serialized":"[email protected]_1606AE6C987B4EDC39"},"t":1608518082,"unreadCount":0,"archive":false,"isReadOnly":false,"muteExpiration":0,"notSpam":true,"pin":0,"ephemeralDuration":0,"ephemeralSettingTimestamp":0,"msgUnsyncedButtonReplyMsgs":[{"id":{"fromMe":false,"remote":"[email protected]","id":"77221E977D87F3169C","_serialized":"[email protected]_77221E977D87F3169C"},"unsyncedButtonReplies":[]}],"isGroup":false,"formattedTitle":"Minha Claro","isMuted":false}
Could you make the following changes in src/util/Injected.js and report your results?
Replace window.WWebJS.getChatModel with:
window.WWebJS.getChatModel = async chat => {
let res = chat.serialize();
res.isGroup = chat.isGroup;
res.formattedTitle = chat.formattedTitle;
res.isMuted = chat.mute && chat.mute.isMuted;
if (chat.groupMetadata) {
await window.Store.GroupMetadata.update(chat.id._serialized);
res.groupMetadata = chat.groupMetadata.serialize();
}
delete res.msgs;
delete res.msgUnsyncedButtonReplyMsgs;
delete res.unsyncedButtonReplies;
return res;
};
@pedroslopez works fine :D
@frmontini Thanks for reporting! The fix has been released in v1.11.2.
@pedroslopez thank you for the great job :D
Most helpful comment
Could you make the following changes in src/util/Injected.js and report your results?
Replace
window.WWebJS.getChatModelwith: