File size: 879 Bytes
5453315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{ 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