Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't forward messages #2435

Open
1 task done
Todpig opened this issue Aug 23, 2023 · 6 comments · May be fixed by #2272
Open
1 task done

I can't forward messages #2435

Todpig opened this issue Aug 23, 2023 · 6 comments · May be fixed by #2272
Labels
bug Something isn't working

Comments

@Todpig
Copy link

Todpig commented Aug 23, 2023

Is there an existing issue for this?

  • I have searched the existing issues

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

@Todpig Todpig added the bug Something isn't working label Aug 23, 2023
@mrfelipemartins
Copy link
Contributor

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
Copy link

cpetrag commented Aug 23, 2023

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
Copy link
Author

Todpig commented Aug 24, 2023

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
Copy link

thedeaddan commented Aug 27, 2023

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
Copy link
Author

Todpig commented Aug 28, 2023

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 😥😔

@alechkos alechkos linked a pull request Aug 29, 2023 that will close this issue
7 tasks
@imaperson1060
Copy link

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]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants