open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.14k stars 600 forks source link

Strange behavior with sending messages #771

Closed votanruchel closed 4 years ago

votanruchel commented 4 years ago

I decided to create this issue because this problem may be occurring with someone else. I will attach a demo print.

https://imgur.com/a/zUoOJ27

When sending messages, I realized that there was no answer ... So I decided to remove enable the headless, and I noticed a strange behavior on the whatsapp web, in which my messages are in fact sent but the symbol of the clock remains, and it never leaves it ... I don't know if it's due to my phone or something else, I don't believe it's a bug in the code, I'm even using the p-queue. Has anyone experienced the same problem? NOTE: It even detects incoming messages and responds to them, however it is never actually sent

smashah commented 4 years ago

How are you managing the queue? Are all of the messages like this or only some of them?

votanruchel commented 4 years ago

Function:

const sendMsg = async(gId, gName) => {
        console.log("Start Send message function")
        if (post_list.length > 0 && groupsIDS.length > 0) {
            const randomLink = Math.floor(Math.random() * post_list.length);
            console.log("Sending Message")
            await client.sendLinkWithAutoPreview(gId, post_list[randomLink].link, post_list[randomLink].title)
                .then(res => {
                    const obj = {
                        gId,
                        gName,
                        postLink: post_list[randomLink].link,
                        postTitle: post_list[randomLink].title,
                        msgId: res,
                    }
                    messagesIDS.push(obj);
                    console.log(messagesIDS);
                }).catch(err => {
                    console.log(err);
                });
        }
        postCounter++;
    }

Queue (autostart: true):

    groupsIDS.map(async(index) => {
        await queue.add(() => sendMsg(index.gId, index.gName));
        console.log(`Task Queued: ${index.gName} | ${index.gId}`);
    })

The first message is usually sent remaining not. Also, the function does not return the message id, even if sent has no response. But if sent only to a group with the bot's cell phone and my user she returns (sometimes) and sending it to myself too

smashah commented 4 years ago

There should be some sort of batching/delay on sending those messages if you're gonna be sending them to every group.

votanruchel commented 4 years ago

I tested it with a 30 second interval for each submission and it had the same effect.

votanruchel commented 4 years ago

I have now added a 30 second delay per message to each of the queue, it has the same effect, so that slower lol. For some reason the function returns me the id if I click on the chat, is there a possibility that the device I'm using for the bot is too slow? we are talking about an Iphone 5 with Whatsapp Business

smashah commented 4 years ago

Web sends the message to the device. If the device is slow/app is closed in the background then yes it will cause delays. You should use a relatively up to date Android device which you can keep awake.

smashah commented 4 years ago

Also 30 seconds between batches is over the top. Half a second between batches of 5 is reasonable.

votanruchel commented 4 years ago

I tested it with another device and it had the same result. So I decided to use the sendText () method, and in fact, the whole problem is in the sendLinkWithAutoPreview () method. With sendText it worked perfectly, without crashes or delays, and returning the message id as expected. Is there any possibility to correct the sendLinkWithAutoPreview () method?

smashah commented 4 years ago

@votanruchel might be related to: https://github.com/open-wa/wa-automate-nodejs/issues/341

Try https://open-wa.github.io/wa-automate-nodejs/classes/client.html#ghostforward after the first message is sent.

smashah commented 4 years ago

Closing for now thanks