whatsapp bot with nodejs
#javascript #教程 #bot

`
const puppeteer = require('puppeteer');

(async函数(){

try{

    const browser = await puppeteer.launch({ headless:false })
    const page = await browser.newPage()

    await page.setUserAgent(
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
      );

    await page.goto("https://web.whatsapp.com/")
    await page.waitForSelector("._13NKt");
    await delay(5000)


    const contactName = "Corona Bot";
    await page.click(`span[title='${contactName}']`);
    await page.waitForSelector('.fd365im1')


    const amountOfMessages = 10;

    for(var i =0; i<amountOfMessages; i++){

        await page.type(".p3_M1", "Hi, how are you, I hope you are good!");
        delay(2000)
        await page.keyboard.press("Enter");
        await delay(500)
    }


}catch(err){
    console.log(err)
}

})();

功能延迟(时间){
返回新的承诺(函数(解决){
settimeout(解决,时间)
})
}