Briuor / wbm

wbm is an unofficial API to send bulk messages in whatsapp.
MIT License
203 stars 64 forks source link

add random interval for sending message #7

Closed vachzar closed 4 years ago

vachzar commented 4 years ago

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;
 }
Briuor commented 4 years ago

@vachzar I'm so sorry about your ban, maybe a lack of luck :disappointed:, i've already sent messages to more than 1000 contacts and wasn't banned. Feel free to create a pull request with this feature if you want. It's a very nice feature to prevent a ban. For sure it will be in a next release.

The delay in line 154 is necessary to prevent a page reload too fast(if it's fast maybe the message will not be sent). I think the change purposed can be applied before the line 154 like this:

// ...
await page.waitFor((6 * getRandomInt(1, 3)) * 10000); // wait random interval do send the message
await page.keyboard.press("Enter"); // send the message
await page.waitFor(1000); // wait 1 sec to go to next contact page
// ...

I think an interval by default in minutes to each message is too long, maybe it can be in seconds. In this feature we can have default interval in 2~6 seconds that be changed as an option.

// no interval options(send as fast as it can)
wbm.start({ interval: false }).then(...)

// default interval 2~6
wbm.start().then(...)

// interval between 10~60 seconds
wbm.start({ minInterval: 10, maxInterval: 60 }).then(...)

Change in the code purposed:

await page.waitFor(getRandomInt(minInterval, maxInterval) * 1000); // random interval in seconds
await page.keyboard.press("Enter"); // send the message
await page.waitFor(1000); // wait 1 sec to go to next contact page