Skip to content

Commit

Permalink
fix session
Browse files Browse the repository at this point in the history
  • Loading branch information
Briuor committed Sep 1, 2020
1 parent 8b2a2a5 commit ef8c28d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"name": "wbm",
"description": "wbm is an API to send bulk messages in whatsapp.",
"version": "1.1.9",
"version": "1.1.10",
"main": "src/index.js",
"devDependencies": {},
"repository": {
Expand All @@ -31,4 +31,4 @@
"url": "https://github.com/Briuor/wbm/issues"
},
"homepage": "https://github.com/Briuor/wbm#readme"
}
}
16 changes: 8 additions & 8 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ async function start({ showBrowser = false, qrCodeData = false, session = true }
}
}

/**
* Check if needs to scan qr code or already is is inside the chat
*/
function isAuthenticated() {
console.log('Authenticating...');
return merge(needsToScan(page), isInsideChat(page))
Expand All @@ -72,11 +75,7 @@ function needsToScan() {
function isInsideChat() {
return from(
page
.waitForFunction(`
document.getElementsByClassName('app')[0] &&
document.getElementsByClassName('app')[0].attributes &&
!!document.getElementsByClassName('app')[0].attributes.tabindex
`,
.waitForFunction(`document.getElementsByClassName('h70RQ two')[0]`,
{
timeout: 0,
}).then(() => true)
Expand Down Expand Up @@ -107,7 +106,7 @@ async function generateQRCode() {
const qrcodeData = await getQRCodeData();
qrcode.generate(qrcodeData, { small: true });
console.log("QRCode generated! Scan it using Whatsapp App.");
} catch {
} catch (err) {
throw await QRCodeExeption("QR Code can't be generated(maybe your connection is too slow).");
}
await waitQRCode();
Expand All @@ -120,7 +119,7 @@ async function waitQRCode() {
// if user scan QR Code it will be hidden
try {
await page.waitForSelector("div[data-ref]", { timeout: 30000, hidden: true });
} catch {
} catch (err) {
throw await QRCodeExeption("Dont't be late to scan the QR Code.");
}
}
Expand Down Expand Up @@ -150,13 +149,14 @@ async function sendTo(phoneOrContact, message) {
await page.goto(`https://web.whatsapp.com/send?phone=${phone}&text=${encodeURI(message)}`);
await page.waitForSelector("div#startup", { hidden: true, timeout: 60000 });
await page.waitForSelector('div[data-tab="1"]', { timeout: 5000 });

await page.keyboard.press("Enter");
await page.waitFor(1000);
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`${phone} Sent\n`);
counter.success++;
} catch {
} catch (err) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`${phone} Failed\n`);
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const wbm = require('./src/index');

(async () => {
await wbm.start().then(async () => {
await wbm.start({showBrowser: true}).then(async () => {
const phones = ['5535988841854', '35988841854', '5535988841854'];
const message = 'Good Morning.';
await wbm.send(phones, message);
Expand Down

0 comments on commit ef8c28d

Please sign in to comment.