Giter VIP home page Giter VIP logo

wbm's Introduction

npm version

wbm

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

Note

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

Installation

> npm install wbm

Usage

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

Send same message to every contact

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

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

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
    Object containing optional parameters as attribute.
    Type: object
    • showBrowser
      Show browser running the script.
      Default: false
      Type: boolean
    • qrCodeData
      Instead of generate the QR Code, returns the data used to generate the QR Code as promise.
      Default: false
      Type: boolean
    • session
      Keep user session, so the user must scan the QR Code once.
      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.
      Default: true
      Type: boolean
// 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
    Array of phone numbers: ['5535988841854', ...].
    Or
    Array of contacts: [{phone: '5535988841854', name: 'Will', group: 'partner', age: 22', any: 'anything', ...}, ...]
    Type: array

  • message
    Message to send to every phone number.
    Text inside curly braces like {{attribute}} will be replaced by the contact object respective attribute.
    Type: string

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
    Phone number. Example '5535988841854'.
    Type: string
    Or Contact object. Example: {phone: '5535988841854', name: 'Will', group: 'partner'}
    Type: object

  • message
    Message to send to phone number.
    Text inside curly braces like {{attribute}} will be replaced by the contact object respective attribute.
    Type: string

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

wbm's People

Contributors

amit4cult avatar balataca avatar briuor avatar bruno-irc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wbm's Issues

How can I send files along with text?

I used your technique, and now I can send texts. How do I send attachments of files?
What is the format or structure of the attachment parameter in the WhatsApp Web URL? Is it a separate URL, a file path, or some other format?
Are there any alternative methods or libraries within the Puppeteer ecosystem that can simplify the process of attaching files to WhatsApp message

Error !

hello,
when i try to install wbm it shows me this error :

image

can you please tell me why ?
thanks.

stopped working

My application runs correct, connects but does not send msg.

In test.js mode it loops, loses the connection after authentication is done and doesn't send the message.


Minha aplicação esta rodando corretamente, mas ela conecta e não envia as mensagens;
No modo test.js, o navegador é aberto, autenticado, fica em loop (reiniciando) e não envia a mensagem.

Alguma dica?

[features] Sending an image or audio

I'm not good at programming. I'm trying to adapt the code to send an attachment or audio. I'm not getting. Any tips?

const message = fs.readFileSync('photo.jpg');

it's not the expected result.

Cannot Send Messages

I think there is a recent change, worked few days ago, but right now it fails.

Bug is on line 162
await page.waitForSelector(SELECTORS.SEND_BUTTON, { timeout: 5000 });

I think that the Selector value needs to be updated:
SEND_BUTTON: 'div:nth-child(3) > button > span[data-icon="send"]'
this one fails currently

NO QR code on terminal

  • wbm.start() is not generating QR code on terminal.
    I am using the code on official documentation

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));

unauthenticated despite using session : true

I used this method to use session saver, recently it keeps failing and generating new qr and the new qr code can't be scanned

wbm.start({showBrowser: false, qrCodeData: true, session: true})
.then(async qrCodeData => {
console.log(qrCodeData);
await wbm.waitQRCode();
// ...
await wbm.end();
} ).catch(err => { console.log(err); });

Session not saving

Requiring me to re-authenticate through QR code every message sent. Already tried turning session argument to false, then back to true; did not work. Also reinstalled dependency. Application currently hosted on Amazon AWS EC2 Instance.

Any thoughts would be greatly appreciated.

Sending Voice Messages

Dear Briuor,

Please advise if your npm wbm package sends automated voice notes. I successfully tested the message sending.

Thanks ahead,
Mohamad

Not linking to whatsapp

QR code is being generated but on scanning through WhatsApp, I am unable to login. It says that can't linked the device. It is not working

process.stdout.clearLine is not a function

Authenticating...
TypeError: process.stdout.clearLine is not a function
at sendTo (D:\Work\Gtion\DiscordBotSimple\node_modules\wbm\src\api.js:170:24)
at async Object.send (D:\Work\Gtion\DiscordBotSimple\node_modules\wbm\src\api.js:184:9)
at async D:\Work\Gtion\DiscordBotSimple\index.js:59:3

im trying to make a simple bot integrated from discord to WA

Seems like it does not work.

I tried this with my electron-vue app. I see QR code in console log but my WhatsApp web can't scan it. Is there a specific way to make this work?
Screenshot 2020-03-18 at 2 53 30 AM

now i cant message again

const wbm = require('wbm');

wbm.start().then(async () => {
const phones = ['target number'];
const message = 'test';
await wbm.send(phones, message);
await wbm.end();
}).catch(err => console.log(err));

first time use this module i can send message, but now i cant send message again

Enter button is not working after sending message to first contact

Hi,
I'm using version 1.1.16
Node version v11.12.0
Mac os big surr 11.2.1

Message sent successfully in logs but not showing in app. just first contact get the message.
I open the browser (showBrowser:true), I see the message initialisation for second contact and onwards but send button in not clicking

I check SEND_BUTTON in node_modules/wbm/src/api.js
SEND_BUTTON: 'div:nth-child(2) > button > span[data-icon="send"]'

I also try with delay page.waitFor(5000) but not working

message didn't broadcast to clients

I was using the standard sample template given in the README , even after the message was send succesfully (message sent in the terminal) my client didn't recieve any message.

Need help with posting output to browser instead of console

Hi,
How to use it for multiple account on same server? Is there any solution?

Also Can anybody help me with the sample code for setting it on server for browser output i have tried many ways but it didn't work?

app.get('/myQR', (req, res) => {
wbm.start({showBrowser: false, qrCodeData: false, session: true}).then(async () => {
res.send(<!DOCTYPE html> <html> <body> <script> ${wbm.generateQRCode()}; </script> </body> </html>);
await wbm.end();
}).catch(err => console.log(err));
})

I tried using express also but not working.

multiple users at the same time

I created an api for many people to use at the same time but it error and using same session.

app.post('/sendtext',jsonParser,(req, res) => {
wbm.start({showBrowser: false, qrCodeData: true, session: false})
.then(async qrCodeData => {
//.................................................
await wbm.send(arraynumber, text);
await wbm.end();
})
})

Can you help me the method for this?

add random interval for sending message

I got banned for sending to more than 20 contacts. lol.
I thought it because of the interval for every message seems to fast.

so I add randomInt() function
and replace line 154 with:

await page.waitFor((6 * getRandomInt(1, 3)) * 10000);

so the msg would be sent randomly between 1-3 minutes.
I think it will be good feature if you want to add it as an option.

just my two cents 😃

the randomInt() function

function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min)) + min;
 }

Sessions

It would be nice to be able to log in through QR once and then reuse the session.
A similar solution is used in pedroslopez/whatsapp-web.js

It’s also good to be able to use multiple sessions at the same time.

Is this possible now?

Send message in interval

Hi I am trying to send messages to all the contacts after specified interval of time. But as soon I add setInterval in then block send is failing

Got an error when I tried to start

I want to test from your example, but I got an error. can you help me?

$ node index.js
E:\project\wagela\node_modules\wbm\src\api.js:110
    } catch {
            ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (E:\project\wagela\node_modules\wbm\src\index.js:1:8
0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.