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.05k stars 3.58k forks source link

Message not visible to sender but visible to receiver. #3254

Open MartinMbae opened 2 weeks ago

MartinMbae commented 2 weeks ago

Is there an existing issue for this?

Describe the bug

I'm experiencing an issue while using this library to develop a message scheduling bot. The bot is designed to run every minute to check for scheduled messages. When a scheduled message is found, the bot launches the client, and upon the "ready" event, it sends the message using client.sendMessage().

Problem: On some occasions, messages are successfully sent to the intended recipient; however, they do not appear on the sender's end (my account). This inconsistency occurs most of the time but not always. When this issue happens, the recipient receives the message as expected, but there is no record of the message on the sender's device or chat history.

Additional Information: This issue does not occur 100% of the time; it is intermittent but frequent. No error messages or warnings are logged during the process.

Troubleshooting Steps Taken: I have tried to introduce a delay both before and after sending messages. It doesn't help.

Expected behavior

Messages sent using client.sendMessage() should appear in both the recipient's and sender's chat histories consistently.

Actual Behavior: Messages are sent to the recipient, but they do not appear in the sender's chat history in most cases.

Steps to Reproduce the Bug or Issue

Relevant Code


  const wwebVersion = '2.3000.1015407831';
  const store = new MongoStore({mongoose: mongoose});

  const client = new Client({
                    authStrategy: new RemoteAuth({
                        clientId: identifier,
                        store: store,
                        backupSyncIntervalMs: 60000 * 2,
                    }),
                    webVersion: `${wwebVersion}`,
                    webVersionCache: {
                        type: "remote",
                        remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
                    },
                    puppeteer: {
                        headless: true,
                        args: [
                            "--no-sandbox",
                            '--disable-setuid-sandbox',
                            '--disable-dev-shm-usage',
                            '--disable-accelerated-2d-canvas',
                            '--no-first-run',
                            '--no-zygote',
                            '--single-process',
                        ],
                    },
                    // authTimeoutMs: 1000000,
                    takeoverOnConflict: true,
                    qrMaxRetries: 1
                });

......


  client.on('ready', async () => {
                    console.log('Client is ready!');

                    let currContext = this;
                    console.log("Wait before sending")
                    setTimeout(function () {
                        sendScheduledStatusAndMessages(currContext).then(r => {
                            console.log("Initiated from on Client Ready")
                        });
                    }, 15000);
                });

.......


    async sendTextMessage(userId, contactNumber, message, currContext, instanceId, fromWeb = false) {
        try {
            const client = currContext.allSessions[instanceId];
            if (!client) {
                console.log('WhatsApp client not found for this user.');
                return null;
            }

            if (fromWeb){
              let num = await  client.getNumberId(contactNumber);
                if(num == null){
                    console.log("Contact doesn't exist");
                    return null;
                }else{
                    contactNumber = num._serialized;
                }
            }
            return await client.sendMessage(contactNumber, message);

        } catch (error) {
            console.error('Error sending message:', error);
            return null;
        }
    }

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS : Ubuntu 22 Phone: Android whatsapp-web.js version [ 1.25] WhatsApp Web version : 2.3000.1015953369 Branch: web-exodus Platform: Node.js v22.1.0,

Additional context

Could you please provide guidance on what might be causing this behavior or any additional troubleshooting steps I could take? Any help to resolve this issue would be greatly appreciated.

jailton-urbano commented 2 weeks ago

Estou com o mesmo problema.

facundogodixital commented 2 weeks ago

I'm experiencing the same issue.

It happens randomly and only with one of the hundreds of connected numbers.

The message is sent normally without any problems, but it doesn't appear in the sender's WhatsApp application. However, if I list the conversation using the whatsapp-web.js library, the message appears among the sent messages.