Skip to content

Commit

Permalink
feat: statusFind
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Apr 19, 2022
1 parent c2bdc5a commit 7ee608d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ venom
},
// statusFind
(statusSession, session) => {
console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser
console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser || initBrowser || openBrowser || connectBrowserWs || initWhatsapp || erroPageWhatsapp || successPageWhatsapp || waitForLogin || waitChat || successChat
//Create session wss return "serverClose" case server for close
console.log('Session name: ', session);
},
Expand Down Expand Up @@ -227,7 +227,7 @@ venom

## Callback Status Session

Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or `qrReadSuccess` or `qrReadFail` or `autocloseCalled` or `desconnectedMobile` or `deleteToken` or `chatsAvailable` or `deviceNotConnected` or `serverWssNotConnected` or `noOpenBrowser` or `Create session wss return "serverClose" case server for close`
Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or `qrReadSuccess` or `qrReadFail` or `autocloseCalled` or `desconnectedMobile` or `deleteToken` or `chatsAvailable` or `deviceNotConnected` or `serverWssNotConnected` or `noOpenBrowser` or `initBrowser` or `openBrowser` or `connectBrowserWs` or `initWhatsapp` or `erroPageWhatsapp` or `successPageWhatsapp` or `waitForLogin` or `waitChat` or `successChat` or `Create session wss return "serverClose" case server for close`

| Status | Condition |
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -244,7 +244,15 @@ Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or
| `deviceNotConnected` | Chat not available because the phone is disconnected `(Trying to connect to the phone)` |
| `serverWssNotConnected` | The address wss was not found! |
| `noOpenBrowser` | It was not found in the browser, or some command is missing in args |

| `initBrowser` | Starting the browser |
| `openBrowser` | The browser has been successfully opened! |
| `connectBrowserWs` | Connection with BrowserWs successfully done! |
| `initWhatsapp` | Starting whatsapp! |
| `erroPageWhatsapp` | Error accessing whatsapp page |
| `successPageWhatsapp` | Page Whatsapp successfully accessed |
| `waitForLogin` | Waiting for login verification! |
| `waitChat` | Waiting for the chat to load |
| `successChat` | Chat successfully loaded! |
```javascript
const venom = require('venom-bot');
venom
Expand All @@ -253,7 +261,7 @@ venom
undefined,
(statusSession, session) => {
console.log('Status Session: ', statusSession);
//return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser
//return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser || initBrowser || openBrowser || connectBrowserWs || initWhatsapp || erroPageWhatsapp || successPageWhatsapp || waitForLogin || waitChat || successChat
//Create session wss return "serverClose" case server for close
console.log('Session name: ', session);
},
Expand Down
17 changes: 16 additions & 1 deletion src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export async function create(
if (!mergedOptions.disableWelcome) {
welcomeScreen();
}

statusFind && statusFind('initBrowser', this.session);

// Initialize whatsapp
if (mergedOptions.browserWS) {
logger.info(`Waiting... checking the wss server...`, { session });
Expand Down Expand Up @@ -197,7 +200,9 @@ export async function create(
logger.info('Has been properly connected to the wss server', {
session
});
statusFind && statusFind('connectBrowserWs', this.session);
} else {
statusFind && statusFind('openBrowser', this.session);
logger.info('Browser successfully opened', {
session
});
Expand Down Expand Up @@ -235,10 +240,12 @@ export async function create(
if (SessionTokenCkeck(browserSessionToken)) {
browserToken = browserSessionToken;
}

logger.info('Checking page...', {
session
});

statusFind && statusFind('initWhatsapp', this.session);
// Initialize whatsapp
const page: false | Page = await initWhatsapp(
session,
Expand All @@ -255,9 +262,12 @@ export async function create(
logger.info('Error accessing the page: "https://web.whatsapp.com"', {
session
});

statusFind && statusFind('erroPageWhatsapp', this.session);
throw 'Error when trying to access the page: "https://web.whatsapp.com"';
}

statusFind && statusFind('successPageWhatsapp', this.session);
logger.info(`${chalk.green('Page successfully accessed')}`, {
session
});
Expand Down Expand Up @@ -341,7 +351,10 @@ export async function create(
console.log(`\nDebug: Option waitForLogin it's true. waiting...`);
}

statusFind && statusFind('waitForLogin', this.session);

const isLogged = await client.waitForLogin(catchQR, statusFind);

if (!isLogged) {
throw 'Not Logged';
}
Expand Down Expand Up @@ -383,6 +396,8 @@ export async function create(
);
}

statusFind && statusFind('waitChat', this.session);

await page.waitForSelector('#app .two', { visible: true }).catch(() => {});

if (mergedOptions.debug) {
Expand Down Expand Up @@ -427,7 +442,7 @@ export async function create(
if (mergedOptions.debug) {
console.log(`\nDebug: injecting Api done...`);
}

statusFind && statusFind('successChat', this.session);
return client;
}
}

0 comments on commit 7ee608d

Please sign in to comment.