new(all): Custom Domain support per bot.

This commit is contained in:
rodrigorodriguez 2022-10-04 18:34:15 -03:00
parent 8687a4258b
commit 08d8570af1

View file

@ -138,7 +138,7 @@ export class WhatsappDirectLine extends GBService {
const gbaiName = `${this.min.botId}.gbai`; const gbaiName = `${this.min.botId}.gbai`;
const localName = Path.join('work', gbaiName, 'profile'); const localName = Path.join('work', gbaiName, 'profile');
const createClient = async (browserWSEndpoint) => { const createClient = (browserWSEndpoint) => {
let puppeteer: any = { let puppeteer: any = {
headless: false, args: ['--disable-features=site-per-process', headless: false, args: ['--disable-features=site-per-process',
`--user-data-dir=${localName}`] `--user-data-dir=${localName}`]
@ -155,6 +155,7 @@ export class WhatsappDirectLine extends GBService {
puppeteer: puppeteer puppeteer: puppeteer
}); });
client.initialize();
client.on('message', (async message => { client.on('message', (async message => {
await this.WhatsAppCallback(message, null); await this.WhatsAppCallback(message, null);
@ -195,24 +196,25 @@ export class WhatsappDirectLine extends GBService {
client.on('authenticated', () => { client.on('authenticated', () => {
this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); this.browserWSEndpoint = client.pupBrowser.wsEndpoint();
client.pupBrowser.on('disconnected', (async () => {
GBLog.info(`Browser crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
await (createClient.bind(this))(null);
}).bind(this));
client.pupPage.on('error', (async () => {
GBLog.info(`Page crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
if (!client.pupPage.isClosed()){
client.pupPage.close();
} await (createClient.bind(this))(null);
}).bind(this));
GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`); GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`);
}); });
}; };
client.pupBrowser.on('disconnected', (async () => {
GBLog.info(`Browser crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
await (createClient.bind(this))(null);
}).bind(this));
client.pupPage.on('error', (async () => {
GBLog.info(`Page crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
if (!client.pupPage.isClosed()){
client.pupPage.close();
} await (createClient.bind(this))(null);
}).bind(this));
(createClient.bind(this))(this.browserWSEndpoint);
await (createClient.bind(this))(this.browserWSEndpoint);
await client.initialize();
setUrl = false; setUrl = false;
} }