Wa-automate-nodejs: Get connection state

Created on 13 Nov 2020  Â·  7Comments  Â·  Source: open-wa/wa-automate-nodejs

I'm using the easyApi to interact with the library and I wanted to periodically check if the session is online i.e there's no issue with the host phone or the server on which the library is running.

I tried to test it by turning off internet on the host phone and hitting the /getConnectionState, /getMe or similar endpoints of the easyApi but I'm still getting a successful response. The /getSnapshot endpoint also shows that WA Web is running normally.

The only workaround I could find was hitting the /refresh endpoint, after which /getConnectionState returns an offline status. Is there an alternative?

Awaiting fix confirmation bug enhancement

All 7 comments

Looks like it will only update connection state when you try to do something that requires contacting the host account device. If anything I'll have to trick it into pinging the device every time you call getConnectionState

@shubham0804 please restart your session and try again. Although getConnectionState() now takes about 4 seconds to resolve, it will be much more reliable and up to date.

If you ever want to 'wake up' the connection between the session and the host device just call getConnectionState()

Please report back if it working for you.

changing getConnectionState caused issues so now I've implemented client.forceUpdateConnectionState() instead.

@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`);

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

    await postComment(result);

//create changelog image
exec(`npm run release-image`);
exec(`git commit -a -m 'updated release-image'`);
exec(`git push --force`);
  })();

Changelog

🚀 Release 3.0.16 (2020-11-15)

  • build(deps): bump socket.io from 3.0.0 to 3.0.1 #1052
  • build(deps): bump ts-json-schema-generator from 0.77.0 to 0.78.0 #1061
  • Release 3.0.16 afd46ca
  • added 401 information to docs #1070 8d6f554
  • Feature: Implemented forceUpdateConnectionState() #1072 3b03950
  • CLI: new flag --headful to launch browser window c2cfbac
  • ignore needsToScan error on kill #1063 96e4979
  • patched: #1072 #1069 1ca07fb
  • prevent client.kill() from being called twice. 7a04599
  • bump popup socket io version 5d1167b
  • patched loadAndGetAllMessagesInChat #1051 6477105
  • patch: #1051 4d48454

client.forceUpdateConnectionState() has solved the issue! Would it be possible to call it through the easyApi?

Never mind. It's working through the easyApi after updating. Thanks!

Was this page helpful?
0 / 5 - 0 ratings