Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can be upgraded for sending messages in Whatsapp groups #23

Open
manankarani opened this issue Jul 6, 2021 · 2 comments
Open

Can be upgraded for sending messages in Whatsapp groups #23

manankarani opened this issue Jul 6, 2021 · 2 comments

Comments

@manankarani
Copy link

Hey, I found this API very interesting, I am a newbie to node.js, but I was wondering if there was a way to send Messages from a saved contact or a Whatsapp Group.
Regards,

@Briuor
Copy link
Owner

Briuor commented Jul 14, 2021

Yes there are ways to do it, wbm uses puppeteer(web automation library). So in background wbm access whatsapp web in a browser and do all the steps to send a message.

In these steps you can add a step to search for a user on the whatsapp web search contact field.

I suggest you to have some fun with puppeteer to get the idea. Hope it helped you!

@asdat3
Copy link

asdat3 commented Aug 17, 2022

Hey, here is an example
it is just using the open contacts on the left but it should get you the idea
you have to replace the function inside the api.js

async function sendTo(phoneOrContact, message) {
    let phone = phoneOrContact;
    if (typeof phoneOrContact === "object") {
        phone = phoneOrContact.phone;
        message = generateCustomMessage(phoneOrContact, message);
    }
    try {
        process.stdout.write("Sending Message...\r");
        // await page.waitForSelector(SELECTORS.LOADING, { hidden: true, timeout: 60000 });

        await page.waitForXPath(`//*[contains(text(), '${phone}')]`, { visible: true }); //Search input
        const elementToClick = await page.$x(`//*[contains(text(), '${phone}')]`);
        await elementToClick[0].click();


        await page.waitForXPath(`//div[@title='Type a message']`, { visible: true }); //Search input
        const elementToClick2 = await page.$x(`//div[@title='Type a message']`);
        await elementToClick2[0].click();

        await page.keyboard.type(message);
        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 (err) {
        process.stdout.clearLine();
        process.stdout.cursorTo(0);
        process.stdout.write(`${phone} Failed\n`);
        counter.fails++;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants