open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.14k stars 600 forks source link

Specify timeout on send methods #1152

Closed ahmed-safari closed 3 years ago

ahmed-safari commented 3 years ago

When device is not connected, send functions doesn't return until it is connected again. It waits for an infinite amount of time. Is there a way around this?

smashah commented 3 years ago

@Sp0derDev you might want to try safeMode. It checks the state before making a request to the browser instance

https://docs.openwa.dev/interfaces/configobject.html#safemode

ahmed-safari commented 3 years ago

I tried it, it still doesn't work most of the time. It keeps trying to send.

smashah commented 3 years ago

@github-actions run

âš¡ Release! âš¡ ```js (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`); })(); ```
ahmed-safari commented 3 years ago

Thank you, do you mind helping with implementing a timeout ?

smashah commented 3 years ago

@Sp0derDev CI server got stuck on the release, going to try fixing then will explain how to do it

smashah commented 3 years ago

Changelog

🚀 Release 3.1.8 (2020-12-11)

smashah commented 3 years ago

@Sp0derDev Ok. In the latest version (3.1.8) there are two major changes that will help you out.

  1. safeMode now forces an update to the state of the connection. If it is connected, it will resolve quickly and result in CONNECTED and continue with the desired command. If there are issues with the connection between the device and the session then it will resolve in about 6 seconds and throw a confirmed TIMEOUT state message (or some other undesirable state).

  2. You can now set callTimeout in the config (docs). This is the number of milliseconds the client method will wait before timing out. It will throw a PageEvaluateionTimeout error with a generic message. This should free up your process to continue doing other things. Just because you got this error, it does not mean that the desired command failed. It just means your process is no longer waiting for a response so please be careful when using this as some consecutive commands may rely on the resolved value.

I'm sure there will be some teething problems that will need further patches so please report with any feedback/issues. Or just report back if it is working as expected for you so I can close this issue.

Thanks

smashah commented 3 years ago

Closing for now, please report back if there are any further issues. Thanks