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
14.49k stars 3.45k forks source link

Evaluation failed: TypeError: chat.forwardMessages is at __puppeteer_evaluation_script__:5:31 #2426

Open cpetrag opened 10 months ago

cpetrag commented 10 months ago

Is there an existing issue for this?

Describe the bug

Not forwarding messages

Expected behavior

Not forwarding messages

Steps to Reproduce the Bug or Issue

Forwarding messages

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Is there an existing issue for this? I have searched the existing issues Describe the bug the bot is just displays the message: Evaluation failed: TypeError: chat.forwardMessages is at puppeteer_evaluation_script:5:31

Expected behavior should respond

Steps to Reproduce the Bug or Issue on message and on ready not working

Relevant Code No response

Browser Type Google Chrome

WhatsApp Account Type Standard

Does your WhatsApp account have multidevice enabled? Yes, I am using Multi Device

Environment no hwencements

Additional context No response

Additional context

No response

Todpig commented 10 months ago

estou com o mesmo problema

yajuj commented 10 months ago

Try replacing 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);
}
cpetrag commented 10 months ago

Try replacing 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);
}

Works!!!!! Thanks!!!

Todpig commented 10 months ago

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 () => { console.log("Conexão feita!"); const userGroups = await client.getChats(); const groupEnvios = userGroups.find((chat) => chat.name === "name1"); const groupPechinchou = userGroups.find( (chat) => chat.name === "name2" );

const message = groupEnvios.lastMessage; console.log(message); message.forward(groupPechinchou.id._serialized); });

client.initialize();

C:\Users\Lucas\Documents\testeForward\node_modules\whatsapp-web.js\src\structures\Message.js:385 await this.client.pupPage.evaluate(async (msgId, chatId) => { ^

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

Node.js v19.9.0

Todpig commented 10 months ago

Try replacing 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);
}

it works!! thank you my friend

DukazzCruz commented 2 months ago

Work for me install independent "puppeteer": "^22.6.4". Try it.

const waClient = new Client({ restartOnAuthFail: true, authStrategy: new LocalAuth({ clientId: "LaraNoti222", dataPath: "./WWebJ", }), webVersionCache: { type: "remote", remotePath: "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2410.1.html" }, puppeteer: { headless: true, args: [ "--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-accelerated-2d-canvas", "--no-first-run", "--no-zygote", "--single-process", "--disable-gpu", ], }, });