diff --git a/package-lock.json b/package-lock.json index 3d1bc10..bbdcb16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "wbm", - "version": "1.1.9", + "version": "1.1.10", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -342,4 +342,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 696671a..7917280 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -31,4 +31,4 @@ "url": "https://github.com/Briuor/wbm/issues" }, "homepage": "https://github.com/Briuor/wbm#readme" -} \ No newline at end of file +} diff --git a/src/api.js b/src/api.js index 1574587..2a2dc52 100644 --- a/src/api.js +++ b/src/api.js @@ -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)) @@ -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) @@ -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(); @@ -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."); } } @@ -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`); diff --git a/test.js b/test.js index 869ab1c..9d3fde6 100644 --- a/test.js +++ b/test.js @@ -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);