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

fetchMessages() Not Retrieving Sent Messages from client.sendMessage() #3267

Open
1 task done
ePearl2020 opened this issue Sep 7, 2024 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@ePearl2020
Copy link

ePearl2020 commented Sep 7, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am experiencing an issue with whatsapp-web.js where messages sent using client.sendMessage() are not being retrieved with fetchMessages(). Only messages sent by the user are showing up. However, when I send a message through the real-time browser interface, it appears correctly. Messages sent programmatically are not appearing in the message history fetched by fetchMessages(), whereas messages sent through the WhatsApp Web UI appear as expected.

Expected behavior

Expected Behavior:

The message sent via client.sendMessage() should appear in the results of fetchMessages() along with other messages in the chat history.

Actual Behavior:

The message sent via client.sendMessage() is not included in the results returned by fetchMessages(). Messages sent through the WhatsApp Web UI are shown correctly.

Steps to Reproduce the Bug or Issue

  1. Initialize the whatsapp-web.js client.
  2. Use client.sendMessage(chatId, 'Your message here') to send a message.
  3. Immediately after sending, use chat.fetchMessages({ limit: 10 }) to fetch recent messages from the chat.
  4. Observe that the sent message is not included in the fetched messages.

Relevant Code

const { Client } = require('whatsapp-web.js');
const client = new Client();

client.on('ready', async () => {
const chatId = '9XXXXXXXXXXXX@c.us'; // Replace with your chat ID

// Send a message
const sentMessage = await client.sendMessage(chatId, ' receipt 📃. Thanks!\n\nᴬᴵ');
console.log('Sent message:', sentMessage);

// Fetch recent messages
const chat = await client.getChatById(chatId);
const messages = await chat.fetchMessages({ limit: 50 });
console.log('Fetched messages:', messages);

});

client.initialize();

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Operating System: Windows 10
npm/Yarn: npm
whatsapp-web.js Version: [e.g., v1.17.2]

Additional context

No response

@ePearl2020 ePearl2020 added the bug Something isn't working label Sep 7, 2024
@momokang
Copy link
Contributor

I don't have such issue, perhaps it's just delay of retrieve messages? Because there is some delay if you send through the API and phone WhatsApp is not synced, do you try with client.on('message_create', async (message) => {}); and check the message is created successfully?

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

No branches or pull requests

2 participants