Ignore unhandled rejections
This commit is contained in:
1 parent
6f2cf83425
commit
8cbed3b46d
3 files changed
+34
-25
No files matched your search
@@ -2,7 +2,7 @@ build:
|
||||
docker build . -t allburov/whatsapp-http-api
|
||||
|
||||
run:
|
||||
docker run -it -v `pwd`/tokens:/app/tokens -p 127.0.0.1:3000:3000/tcp allburov/whatsapp-http-api
|
||||
docker run --rm -v `pwd`/tokens:/app/tokens -p 127.0.0.1:3000:3000/tcp --name whatsapp-http-api allburov/whatsapp-http-api
|
||||
|
||||
push:
|
||||
docker push allburov/whatsapp-http-api
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"start:prod": "node --unhandled-rejections=none dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
|
||||
+32
-23
@@ -27,10 +27,11 @@ const HOOKS = [
|
||||
]
|
||||
const ENV_PREFIX = "WHATSAPP_HOOK_"
|
||||
|
||||
enum WhatsappStatus {
|
||||
export enum WhatsappStatus {
|
||||
STARTING = "STARTING",
|
||||
SCAN_QR_CODE = "SCAN_QR_CODE",
|
||||
WORKING = "WORKING",
|
||||
FAILED = "FAILED",
|
||||
}
|
||||
|
||||
export class WhatsappService {
|
||||
@@ -58,27 +59,35 @@ export class WhatsappService {
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.whatsapp = await create('sessionName',
|
||||
(base64Qrimg, asciiQR, attempts, urlCode) => {
|
||||
this.saveQRCode(base64Qrimg)
|
||||
this.status = WhatsappStatus.SCAN_QR_CODE
|
||||
console.log('Number of attempts to read the qrcode: ', attempts);
|
||||
console.log('Terminal qrcode: ', asciiQR);
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
headless: true,
|
||||
devtools: false,
|
||||
useChrome: true,
|
||||
debug: false,
|
||||
logQR: true,
|
||||
browserArgs: ["--no-sandbox"],
|
||||
autoClose: 60000,
|
||||
createPathFileToken: true,
|
||||
puppeteerOptions: {},
|
||||
multidevice: false,
|
||||
}
|
||||
)
|
||||
try {
|
||||
this.whatsapp = await create('sessionName',
|
||||
(base64Qrimg, asciiQR, attempts, urlCode) => {
|
||||
this.saveQRCode(base64Qrimg)
|
||||
this.status = WhatsappStatus.SCAN_QR_CODE
|
||||
console.log('Number of attempts to read the qrcode: ', attempts);
|
||||
console.log('Terminal qrcode: ', asciiQR);
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
headless: true,
|
||||
devtools: false,
|
||||
useChrome: true,
|
||||
debug: false,
|
||||
logQR: true,
|
||||
browserArgs: ["--no-sandbox"],
|
||||
autoClose: 60000,
|
||||
createPathFileToken: true,
|
||||
puppeteerOptions: {},
|
||||
multidevice: false,
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
this.status = WhatsappStatus.FAILED
|
||||
this.log.error(error)
|
||||
this.saveQRCode("")
|
||||
return
|
||||
}
|
||||
|
||||
this.saveQRCode("")
|
||||
this.configureWebhooks();
|
||||
this.status = WhatsappStatus.WORKING
|
||||
@@ -239,7 +248,7 @@ export class WhatsappSessionManager implements OnApplicationShutdown {
|
||||
async stopSession(name: string) {
|
||||
this.log.log(`Stopping ${name} session...`)
|
||||
const service = this.getService(name)
|
||||
await service.getWhatsapp().close()
|
||||
await service.whatsapp.close()
|
||||
this.log.log(`"${name}" has been stopped.`)
|
||||
delete this.sessions[name]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user