Whatsapp-web.js: Fetch only unread messages

Created on 29 Apr 2020  路  4Comments  路  Source: pedroslopez/whatsapp-web.js

Is there any way to fetch only unread messages from each chat?

stale

Most helpful comment

You can use:

let chats = await client.getChats();
for (let chat of messages){
  if( chat.unreadCount > 0){
    unreadMessages = await chat.fetchMessages( {limit: chat.unreadCount} );
  }
}

All 4 comments

@pedroslopez Any ideas how to implement this feature ?

You may be able to filter by ack. https://pedroslopez.me/whatsapp-web.js/Message.html#ack

You can see the possible values here: https://github.com/pedroslopez/whatsapp-web.js/blob/bcd02aa5e4cb96387487595ff02f2c0308793160/src/util/Constants.js#L128

Read messages have an ack of 3, which means unread would have a value < 3.

I鈥檓 not entirely sure, I鈥檓 not able to test at the moment, but you could give it a shot. Let me know if it works, if not I can do some tests later on

You can use:

let chats = await client.getChats();
for (let chat of messages){
  if( chat.unreadCount > 0){
    unreadMessages = await chat.fetchMessages( {limit: chat.unreadCount} );
  }
}

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings