Create client.coffee
Browse files- client.coffee +30 -0
client.coffee
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{ executablePath } = require "puppeteer"
|
| 2 |
+
{ Client, Events, LocalAuth } = require "whatsapp-web.js"
|
| 3 |
+
|
| 4 |
+
{ CHROME_BIN, GROUP_ID, PHONE_NUMBER } = process.env
|
| 5 |
+
unless GROUP_ID and PHONE_NUMBER
|
| 6 |
+
console.log "Set GROUP_ID and PHONE_NUMBER first (for bot) in env"
|
| 7 |
+
process.exit 1
|
| 8 |
+
|
| 9 |
+
PHONE_NUMBER = PHONE_NUMBER.replace /\D/g, ""
|
| 10 |
+
|
| 11 |
+
client = new Client
|
| 12 |
+
authStrategy: new LocalAuth
|
| 13 |
+
clientId: PHONE_NUMBER
|
| 14 |
+
puppeteer:
|
| 15 |
+
headless: "new",
|
| 16 |
+
args: ["--no-sandbox"],
|
| 17 |
+
executablePath: CHROME_BIN or executablePath()
|
| 18 |
+
|
| 19 |
+
pairingCodeRequested = false
|
| 20 |
+
client.on Events.QR_RECEIVED, (qr) ->
|
| 21 |
+
if not pairingCodeRequested
|
| 22 |
+
pairingCode = await client.requestPairingCode PHONE_NUMBER
|
| 23 |
+
console.log "Pairing code:", pairingCode
|
| 24 |
+
pairingCodeRequested = true
|
| 25 |
+
|
| 26 |
+
client.on Events.READY, () ->
|
| 27 |
+
debugWWebVersion = await client.getWWebVersion()
|
| 28 |
+
console.log "WWebVersion", debugWWebVersion
|
| 29 |
+
|
| 30 |
+
module.exports = client
|