New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wbm

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wbm - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

assets/demo.gif

15

package.json
{
"dependencies": {
"p-queue": "^6.2.1",
"ora": "^4.0.3",
"puppeteer": "^2.1.1",

@@ -8,12 +8,9 @@ "qrcode-terminal": "^0.12.0"

"name": "wbm",
"description": "WhatsApp-Bulk-Message-API is an API to send bulk message.",
"version": "1.0.0",
"description": "wbm is an API to send bulk message.",
"version": "1.0.1",
"main": "src/index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Briuor/WhatsApp-Bulk-Message-API.git"
"url": "git+https://github.com/Briuor/wbm.git"
},

@@ -30,5 +27,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/Briuor/WhatsApp-Bulk-Message-API/issues"
"url": "https://github.com/Briuor/wbm/issues"
},
"homepage": "https://github.com/Briuor/WhatsApp-Bulk-Message-API#readme"
"homepage": "https://github.com/Briuor/wbm#readme"
}

74

README.md

@@ -1,2 +0,72 @@

# WhatsApp-Bulk-Message-API
WhatsApp-Bulk-Message-API is an API to send bulk message.
# wbm
> wbm is an API to send bulk messages in whatsapp.
<p align="center">
<img src="https://github.com/Briuor/wbm/tree/master/assets/demo.gif">
</p>
## Installation
```bash
> npm install wbm
```
## Usage
:tw-26a0: **At the beginning it will display a QR Code on terminal, just scan it using whatsapp app.**
### Send same message to every contact
```javascript
const wbm = require('wbm');
wbm.start().then(async () => {
const phones = ['5535988841854']; // phone numbers ['5535988841854', ...]
const message = "good morning";
await wbm.send(phones, message);
})
```
### Send custom message to every contact
```javascript
const wbm = require('wbm');
wbm.start().then(async () => {
const contacts = [{ phone: '5535988841854', name: 'Bruno' }];
for (contact of contacts) {
let message = 'good morning ' + contact.name;
await wbm.sendTo(contact.phone, message);
}
})
```
## API
### send(phones, message)
Send same message to every phone number.
##### phones
Array of phone numbers: ['5535988841854', ...]
Type: `array`
##### message
Message to send to every phone number
Type: `string`
### sendTo(phone, message)
Send message to a phone number.
##### phone
Phone number: '5535988841854'.
Type: `string`
##### message
Message to send to phone number.
Type: `string`
## License
[MIT](https://choosealicense.com/licenses/mit/)
const puppeteer = require("puppeteer");
const qrcode = require("qrcode-terminal");
const ora = require('ora');
const { default: PQueue } = require('p-queue');
// const whatsapp = require("../firebase/whatsapp.js");
// const fixPhone = require("./util/fixPhone");
const queue = new PQueue({ concurrency: 1 });
let browser = null;
let page = null;
let spinner = ora();
let counter = { fails: 0, success: 0 }

@@ -16,18 +13,18 @@ async function start() {

headless: true,
args: ["--no-sandbox", "--disable-gpu"]
args: ["--no-sandbox"]
});
console.log(browser)
page = await browser.newPage();
// prevent dialog blocking page and just accept it(necessary when a message is sent too fast)
page.on("dialog", async dialog => {
await dialog.accept();
});
// fix the chrome headless mode issues
await page.setUserAgent(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
);
page.on("dialog", async dialog => { await dialog.accept(); });
// fix the chrome headless mode true issues
// https://gitmemory.com/issue/GoogleChrome/puppeteer/1766/482797370
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
page.setDefaultTimeout(60000);
await generateQRCode();
}
async function generateQRCode() {
spinner.start('generating QRCode\n');
await page.goto("https://web.whatsapp.com");
// generate QRCode
await page.waitForSelector('div[data-ref]');

@@ -38,19 +35,51 @@ const qrcodeData = await page.evaluate(() => {

});
console.log("Gerou")
qrcode.generate(qrcodeData, { small: true });
spinner.info('QRCode generated! Scan it using Whatsapp App.');
await page.waitForSelector('div[data-ref]', { hidden: true });
};
}
/**
* @param {string} phone phone number: '5535988841854'
* @param {string} message Message to send to phone number
* Send message to a phone number
*/
async function sendTo(phone, message) {
await page.goto("https://web.whatsapp.com/send?phone=" + phone + "&text=" + message);
await page.waitForSelector('div[data-tab="1"]');
await page.keyboard.press("Enter");
console.log(phone + " enviado");
spinner.start('Sending Message\n');
await page.goto(`https://web.whatsapp.com/send?phone=${phone}&text=${message}`);
await page.waitForSelector('div#startup');
await page.waitForSelector('div#startup', { hidden: true });
try {
await page.waitForSelector('div[data-tab="1"]', { timeout: 3000 });
await page.keyboard.press('Enter');
await page.waitFor(1000);
spinner.succeed(`${phone} Sent`);
counter.success++;
} catch (error) {
spinner.fail(`${phone} Failed`);
counter.fails++;
}
}
/**
* @param {array} phones Array of phone numbers: ['5535988841854', ...]
* @param {string} message Message to send to every phone number
* Send same message to every phone number
*/
async function send(phones, message) {
for (let phone of phones) {
await queue.add(() => sendTo(phone, message))
await sendTo(phone, message);
}
await browser.close();
showResult();
}
async function end() {
await browser.close();
showResult();
}
function showResult() {
spinner.info(`Result: ${counter.success} sent, ${counter.fails} failed`);
}
module.exports = {

@@ -60,2 +89,3 @@ start,

sendTo,
end
}

@@ -1,7 +0,16 @@

const wpm = require('./src/index');
const wbm = require('./src/index');
(async () => {
await wpm.start();
const phones = ['5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854', '5535988841854']
wpm.send(phones, 'EAE');
})();
// wbm.start().then(async () => {
// const phones = ['5535988841854', '35988841854', '5535988841854']; // array of phone numbers ['5535988841854', ...]
// const message = 'hello';
// await wbm.send(phones, message);
// })
wbm.start().then(async () => {
const contacts = [{ phone: '5535988841854', name: 'Bruno' }, { phone: '35988841854', name: 'Bruno' }, { phone: '5535988841854', name: 'Bruno' }];
for (contact of contacts) {
let message = `hi ${contact.name}`;
await wbm.sendTo(contact.phone, message);
}
await wbm.end();
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc