# wbm

> wbm is an API to send bulk messages in whatsapp.

Latest version **1.1.16** (published 2021-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install wbm
pnpm add wbm
yarn add wbm
bun add wbm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.16 |
| Published | 2021-07-13 |
| First published | 2020-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 78.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 221 |
| Author | Briuor |
| Maintainers | briuor |
| Keywords | whatsapp, whatsapp-api, whatsapp-library, whatsapp-send-message, whatsapp-bulk-message, whatsapp-sender, whatsapp-message-sender, bulk-messages, bulk-messages-api |

## Links

- npm: https://www.npmjs.com/package/wbm
- Repository: https://github.com/Briuor/wbm
- Homepage: https://github.com/Briuor/wbm#readme
- Issues: https://github.com/Briuor/wbm/issues
- npm.io page: https://npm.io/package/wbm

## Dependencies (4)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.5
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [puppeteer](https://npm.io/package/puppeteer.md) ^2.1.1
- [qrcode-terminal](https://npm.io/package/qrcode-terminal.md) ^0.12.0

## Recent versions

- 1.1.16 (latest) — 2021-07-13
- 1.1.15 — 2021-06-03
- 1.1.14 — 2021-04-02
- 1.1.13 — 2020-12-17
- 1.1.12 — 2020-10-29
- 1.1.11 — 2020-09-23
- 1.1.10 — 2020-09-01
- 1.1.9 — 2020-04-08
- 1.1.8 — 2020-04-08
- 1.0.8 — 2020-03-22
- 1.0.7 — 2020-03-22
- 1.0.6 — 2020-03-13
- 1.0.5 — 2020-03-13
- 1.0.4 — 2020-02-23
- 1.0.3 — 2020-02-23
- … 3 more at https://npm.io/package/wbm/versions

## README

[![npm version](https://img.shields.io/npm/v/wbm.svg?color=%2378e08f)](https://www.npmjs.com/package/wbm)

# wbm
> wbm is an **unofficial** API to send bulk messages in whatsapp.

<p align="center"> 
<img style="border-radius: 5px" src="https://raw.githubusercontent.com/Briuor/wbm/master/assets/demo.gif">
</p>

## Note
**wbm** is an **unofficial** solution. It's not recommended using **wbm** in your company or for marketing purpose.

## Installation
```bash
> npm install wbm
```

## Usage
**At the beginning it will display a QR Code on terminal, just scan it using whatsapp app.<br />
Your session will be remembered, there is no need to authenticate everytime.**

### Send same message to every contact

```javascript
const wbm = require('wbm');

wbm.start().then(async () => {
    const phones = ['5535988841854', '35988841854', '5535988841854'];
    const message = 'Good Morning.';
    await wbm.send(phones, message);
    await wbm.end();
}).catch(err => console.log(err));

```
### Send custom message to every contact

```javascript
const wbm = require('wbm');

wbm.start().then(async () => {
    const contacts = [
        { phone: '5535988841854', name: 'Bruno', age: 21 },
        { phone: '5535988841854', name: 'Will', age: 33 }
    ];
    const message = 'Hi {{name}}, your age is {{age}}';
    // Hi Bruno, your age is 21
    // Hi Will, your age is 33
    await wbm.send(contacts, message);
    await wbm.end();
}).catch(err => console.log(err));
```

### Send custom messages using YOUR OWN RULE

```javascript
const wbm = require('wbm');

wbm.start().then(async () => {
    const contacts = [
        { phone: '5535988841854', name: 'Bruno', group: 'friend' }, 
        { phone: '5535988841854', name: 'Will', group: 'customer' }
    ];
    for (contact of contacts) {
        let message = 'hi';
        if(contact.group === 'customer') {
            message = 'Good morning ' + contact.name;
        }
        else if(contact.group === 'friend') {
            message = 'Hey ' + contact.name + '. Wassup?';
        }
        await wbm.sendTo(contact.phone, message);
    }
    await wbm.end();
}).catch(err => console.log(err));

```

## API
### start(options)
* **options**<br />
	Object containing optional parameters as attribute.<br />
	Type: `object`<br />
	* **showBrowser**<br />
	Show browser running the script.<br />
	Default: `false`<br />
	Type: `boolean`<br />
	* **qrCodeData**<br />
	Instead of generate the QR Code, returns the data used to generate the QR Code as promise.<br />
	Default: `false`<br />
	Type: `boolean`<br />
	* **session**<br />
	Keep user session, so the user must scan the QR Code once.<br />
    If you already is authenticated and **wbm** is asking for QR Code, please run using **session: false** once to reset your session. Then you use **session: true** again.<br />
	Default: `true`<br />
	Type: `boolean`

```javascript
// It will open a browser, return the QR code data as promise and not keep user session
wbm.start({showBrowser: true, qrCodeData: true, session: false})
.then(async qrCodeData => {
    console.log(qrCodeData); // show data used to generate QR Code
    await wbm.waitQRCode();
    // waitQRCode() is necessary when qrCodeData is true
    // ...
    await wbm.end();
} ).catch(err => { console.log(err); });
```

### send(phoneOrContacts, message)

Send message to every phone number.

- **phoneOrContacts**<br />
Array of phone numbers: ['5535988841854', ...].<br />
Or <br />
Array of contacts: [{phone: '5535988841854', name: 'Will', group: 'partner', age: 22', any: 'anything', ...}, ...]<br />
Type: `array`

- **message**<br />
Message to send to every phone number.<br />
Text inside curly braces like {{attribute}} will be replaced by the contact object respective attribute.<br />
Type: `string`

```javascript
wbm.start().then(async () => {
    const contacts = [
        {phone: '5535988841854', name: 'Bruno'},
        {phone: '5535988841854', name: 'Will'}
    ];
    await wbm.send(contacts, 'Hey {{name}}');
    // Hey Bruno
    // Hey Will
    await wbm.send(['5535988841854', '5535988841854'], 'Hey man'); 
    // Hey man
    // Hey man
    await wbm.end();
}).catch(err => { console.log(err); });
```

### sendTo(phoneOrContact, message)

Send message to a single phone number.

- **phoneOrContact**<br />
Phone number. Example '5535988841854'.<br />
Type: `string`<br />
Or
Contact object. Example: {phone: '5535988841854', name: 'Will', group: 'partner'}<br />
Type: `object`

- **message**<br />
Message to send to phone number.<br />
Text inside curly braces like {{attribute}} will be replaced by the contact object respective attribute.<br />
Type: `string`

```javascript
wbm.start().then(async () => {
    await wbm.sendTo({phone: '5535988841854', name: 'Bruno'}, 'Hey {{name}}');
    // Hey Bruno
    await wbm.sendTo('5535988841854', 'Hey man');
    // Hey man
    await wbm.end();
}).catch(err => { console.log(err); });
```

### end()
This method must be used at the end of wbm.start() to finish the browser.

## Contributing

Feel free to create pull requests. For major changes, please open an issue first to discuss what you would like to change.

## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/wbm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
