pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.21k stars 3.63k forks source link

I can't forward messages #2435

Open Todpig opened 1 year ago

Todpig commented 1 year ago

Is there an existing issue for this?

Describe the bug

After whatsapp update I can't forward messages

Expected behavior

forwad message

Steps to Reproduce the Bug or Issue

1- conection 2- get message 3 - forward message 4 - errror

TypeError: Cannot read properties of undefined (reading 'pupPage') at Message.forward (C:\Users\Lucas\Documents\teste\node_modules\whatsapp-web.js\src\structures\Message. js:387:27) at Client. (C:\Users\Lucas\Documents\teste\app.js:21:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Relevant Code

const { Client, LocalAuth } = require("whatsapp-web.js"); const qrcode = require("qrcode-terminal");

const client = new Client({ puppeteer: { headless: false, }, authStrategy: new LocalAuth({ clientId: "test" }), });

client.on("qr", (qr) => { qrcode.generate(qr, { small: true }); });

client.on("ready", async () => { try { console.log("Conexão feita! Valeu boy."); const userGroups = await client.getChats(); const groupsPechin = userGroups.filter((chat) => chat.name === "Envios"); const message = groupsPechin[0].lastMessage; await message.forward(chatId); } catch (err) { console.log(err); } });

client.initialize();

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

whatsapp-web.js

Additional context

No response

mrfelipemartins commented 1 year ago

I don't think the problem is in forwarding messages, looks like a problem accessing the Puppeteer instance.

Take a look at this PR, make sure you implement this fix and see if your problem will be solved. #2434

cpetrag commented 1 year ago

I don't think the problem is in forwarding messages, looks like a problem accessing the Puppeteer instance.

Take a look at this PR, make sure you implement this fix and see if your problem will be solved. #2434

Not solved....

Todpig commented 1 year ago

for me it worked: whatsapp-web.js/src/structures/Message.js : 387 async forward(chat) { const chatId = typeof chat === 'string' ? chat : chat.id._serialized;

        await this.client.pupPage.evaluate(async (msgId, chatId) => {
         let msg = window.Store.Msg.get(msgId);
         let chat = window.Store.Chat.get(chatId);
         window.Store.Chat.forwardMessagesToChats([msg],[chat]);

        }, this.id._serialized, chatId);
    }
thedeaddan commented 1 year ago

for me it worked: whatsapp-web.js/src/structures/Message.js : 387 async forward(chat) { const chatId = typeof chat === 'string' ? chat : chat.id._serialized;

        await this.client.pupPage.evaluate(async (msgId, chatId) => {
         let msg = window.Store.Msg.get(msgId);
         let chat = window.Store.Chat.get(chatId);
         window.Store.Chat.forwardMessagesToChats([msg],[chat]);

        }, this.id._serialized, chatId);
    }

Media forwarding stopped working

UPD: Adding one second delay for sending photos solved the problem, apparently Whatsapp does not have time to process photos (With other types of files everything works without delay)

Todpig commented 1 year ago

for me it worked: whatsapp-web.js/src/structures/Message.js : 387 async forward(chat) { const chatId = typeof chat === 'string' ? chat : chat.id._serialized;

        await this.client.pupPage.evaluate(async (msgId, chatId) => {
         let msg = window.Store.Msg.get(msgId);
         let chat = window.Store.Chat.get(chatId);
         window.Store.Chat.forwardMessagesToChats([msg],[chat]);

        }, this.id._serialized, chatId);
    }

however, when I try to forward it through the GroupChat.lastMessage attribute, the same error returns 😥😔

imaperson1060 commented 11 months ago

for me it worked: whatsapp-web.js/src/structures/Message.js : 387 async forward(chat) { const chatId = typeof chat === 'string' ? chat : chat.id._serialized;

        await this.client.pupPage.evaluate(async (msgId, chatId) => {
         let msg = window.Store.Msg.get(msgId);
         let chat = window.Store.Chat.get(chatId);
         window.Store.Chat.forwardMessagesToChats([msg],[chat]);

        }, this.id._serialized, chatId);
    }

this works for me! the only part i needed to change was window.Store.Chat.forwardMessagesToChats([msg],[chat]);