Wa-automate-nodejs: client.getAllUnreadMessages is not working (always returns empty array even tough there are new messages)

Created on 10 Apr 2020  ยท  5Comments  ยท  Source: open-wa/wa-automate-nodejs

Describe the bug
Can't get a list of unread messages.

Steps to Reproduce
As per indicated in the pest practices in the readme, one should be able to process new messages when wa-automate session is created.

The docs state that this could be accomplished by const unreadMessages = await client.getAllUnreadMessages();

However, as you can see from the attached screenshot, this is not working, as it returns empty arrays:

image

create() code
This is the code you use to create the client. e.g


const client = await wa.create(
    `session_123`,
{
    headless: false,
    defaultViewport: false,
    args: ['--start-maximized', '--window-size=1920,1080' ]
  },
  );

Trying to debug this, I followed the code path and noticed that WAPI.getAllNewMessages() works up until the filter of c.msgs._models, because even the new messages, still unread (haven't clicked it's chat window yet) are being returned with isNewMsg: undefined

image

Expected behavior
It should return new messages for processing.

DEBUG INFO

โ”€โ”€โ”€โ”€โ”ค
โ”‚     WA_VERSION      โ”‚                                                                 '2.2013.7'                                                                  โ”‚
โ”‚       PAGE_UA       โ”‚ 'WhatsApp/0.4.613 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36' โ”‚
โ”‚ WA_AUTOMATE_VERSION โ”‚                                                                  '1.8.44'                                                                   โ”‚
โ”‚   BROWSER_VERSION   โ”‚                                                            'Chrome/80.0.3987.0'

Screenshots
If applicable, add screenshots to help explain your problem. Use headless: false to get screenshots

Host (please complete the following information):

  • OS: macOs / iPhone

Additional context
The documentation is not very clear about the difference between getAllUnreadMessages and getAllUnreadMessages and getAllNewMessages.

PRIORITY bug good first issue

Most helpful comment

@feliperaul Please try:

const newChatsWithNewMessages = await client.getIndicatedNewMessages()

It returns an array of objects:

[{
"id": "[email protected]", //the id of the chat with new messages
"indicatedNewMessages": [] //array of messages, not including any messages by the host phone
}]

All 5 comments

Hey @feliperaul,

Thanks for following the issue template.

The distinction is based on the actual properties of the messages - which may not get updated in real time.

  1. getAllUnreadMessages return messages where ack: -1
  2. getAllNewMessages returns messages where isNewMsg: true

So although they're technically correct, it's not really what people expect (i.e the messages represented with the numbers in the chat list).

@github-actions run


โšก Release! โšก

(async () => {
function exec(cmd) {
  console.log(execSync(cmd).toString());
}

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";

exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i`);
exec(`npm run release-ci`);

var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();

    await postComment(result);
  })();

Changelog

๐Ÿš€ Release 1.8.48 (2020-04-10)

  • Release 1.8.48 6626a1e
  • implemented getIndicatedNewMessages #297 0af07a6

@feliperaul Please try:

const newChatsWithNewMessages = await client.getIndicatedNewMessages()

It returns an array of objects:

[{
"id": "[email protected]", //the id of the chat with new messages
"indicatedNewMessages": [] //array of messages, not including any messages by the host phone
}]

@smashah Working great Shah! Thank you so much.

Just a correction, it was missing the function invocation:

const newChatsWithNewMessages = await client.getIndicatedNewMessages();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

renato-macedo picture renato-macedo  ยท  6Comments

smashah picture smashah  ยท  5Comments

arisros picture arisros  ยท  4Comments

vsilva472 picture vsilva472  ยท  4Comments

yoavmmn picture yoavmmn  ยท  5Comments