| { executablePath } = require "puppeteer" |
| { Client, Events, LocalAuth } = require "whatsapp-web.js" |
|
|
| { CHROME_BIN, GROUP_ID, PHONE_NUMBER } = process.env |
| unless GROUP_ID and PHONE_NUMBER |
| console.log "Set GROUP_ID and PHONE_NUMBER first (for bot) in env" |
| process.exit 1 |
|
|
| PHONE_NUMBER = PHONE_NUMBER.replace /\D/g, "" |
|
|
| client = new Client |
| authStrategy: new LocalAuth |
| clientId: PHONE_NUMBER |
| puppeteer: |
| headless: "new", |
| args: ["--no-sandbox"], |
| executablePath: CHROME_BIN or executablePath() |
|
|
| pairingCodeRequested = false |
| client.on Events.QR_RECEIVED, (qr) -> |
| if not pairingCodeRequested |
| pairingCode = await client.requestPairingCode PHONE_NUMBER |
| console.log "Pairing code:", pairingCode |
| pairingCodeRequested = true |
|
|
| client.on Events.READY, () -> |
| debugWWebVersion = await client.getWWebVersion() |
| console.log "WWebVersion", debugWWebVersion |
|
|
| module.exports = client |