new(all): Paralel bot loading.
This commit is contained in:
parent
6d21bd1803
commit
633a7cb0ea
3 changed files with 43 additions and 33 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
| Feature | BF | GB |
|
| Feature | BF | GB |
|
||||||
|----------------------------------------------------------------------------|----|----|
|
|----------------------------------------------------------------------------|----|----|
|
||||||
| Use of conversational administration to manage bot packages (Talk to admin | - | X |
|
| Use of conversational administration to manage bot packages (Talk to admin)| - | X |
|
||||||
| F5 to run on VSCode | - | X |
|
| F5 to run on VSCode | - | X |
|
||||||
| Isolated code on packages | - | X |
|
| Isolated code on packages | - | X |
|
||||||
| Breaking changes protected | - | X |
|
| Breaking changes protected | - | X |
|
||||||
|
|
|
@ -116,7 +116,9 @@ export class ScheduleServices extends GBService {
|
||||||
p => p.instance.instanceId === item.instanceId
|
p => p.instance.instanceId === item.instanceId
|
||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
this.ScheduleItem(item, min);
|
if (min){
|
||||||
|
this.ScheduleItem(item, min);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Cannot schedule: ${error.message}.`);
|
throw new Error(`Cannot schedule: ${error.message}.`);
|
||||||
|
|
|
@ -141,7 +141,6 @@ 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 = async (browserWSEndpoint) => {
|
||||||
let puppeteer: any = {
|
let puppeteer: any = {
|
||||||
headless: false, args: [
|
headless: false, args: [
|
||||||
|
@ -151,7 +150,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
'--disable-accelerated-2d-canvas',
|
'--disable-accelerated-2d-canvas',
|
||||||
'--no-first-run',
|
'--no-first-run',
|
||||||
'--no-zygote',
|
'--no-zygote',
|
||||||
'--single-process', // <- this one doesn't works in Windows
|
'--single-process',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--disable-infobars',
|
'--disable-infobars',
|
||||||
'--disable-features=site-per-process',
|
'--disable-features=site-per-process',
|
||||||
|
@ -185,25 +184,21 @@ export class WhatsappDirectLine extends GBService {
|
||||||
GBLog.info(msg);
|
GBLog.info(msg);
|
||||||
qrcode.generate(qr, { small: true, scale: 0.5 });
|
qrcode.generate(qr, { small: true, scale: 0.5 });
|
||||||
|
|
||||||
|
|
||||||
// While handling other bots uses boot instance of this class to send QR Codes.
|
// While handling other bots uses boot instance of this class to send QR Codes.
|
||||||
|
|
||||||
if (this.botId !== GBServer.globals.minBoot.botId) {
|
const s = new DialogKeywords(null, null, null, null);
|
||||||
|
const qrBuf = await s.getQRCode(qr);
|
||||||
const s = new DialogKeywords(null, null, null, null);
|
const gbaiName = `${this.min.botId}.gbai`;
|
||||||
const qrBuf = await s.getQRCode(qr);
|
const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||||
const gbaiName = `${this.min.botId}.gbai`;
|
fs.writeFileSync(localName, qrBuf);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
|
const url = urlJoin(
|
||||||
fs.writeFileSync(localName, qrBuf);
|
GBServer.globals.publicAddress,
|
||||||
const url = urlJoin(
|
this.min.botId,
|
||||||
GBServer.globals.publicAddress,
|
'cache',
|
||||||
this.min.botId,
|
Path.basename(localName)
|
||||||
'cache',
|
);
|
||||||
Path.basename(localName)
|
GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
|
||||||
);
|
s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg);
|
||||||
GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
|
|
||||||
s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
|
|
||||||
|
@ -930,12 +925,13 @@ export class WhatsappDirectLine extends GBService {
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case "GeneralBots":
|
case "GeneralBots":
|
||||||
|
|
||||||
|
// Ignore E2E messages used during initialization.
|
||||||
|
|
||||||
if (req.type && req.type === 'e2e_notification') {
|
if (req.type && req.type === 'e2e_notification') {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
id = req.from.split('@')[0];
|
id = req.from.split('@')[0];
|
||||||
senderName = req._data.notifyName;
|
senderName = req._data.notifyName;
|
||||||
text = req.body;
|
text = req.body;
|
||||||
|
@ -1000,24 +996,36 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
text = text.replace(/\@\d+ /gi, '');
|
text = text.replace(/\@\d+ /gi, '');
|
||||||
|
|
||||||
|
let group;
|
||||||
if (provider === "chatapi") {
|
if (provider === "chatapi") {
|
||||||
|
|
||||||
// Ensures that the bot group is the active bot for the user (like switching).
|
// Ensures that the bot group is the active bot for the user (like switching).
|
||||||
|
|
||||||
const message = req.body.messages[0];
|
const message = req.body.messages[0];
|
||||||
if (message.chatName.charAt(0) !== '+') {
|
if (message.chatName.charAt(0) !== '+') {
|
||||||
const group = message.chatName;
|
group = message.chatName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (provider === "GeneralBots") {
|
||||||
|
|
||||||
const botGroup = await this.min.core.loadInstanceByBotId(group);
|
// Ensures that the bot group is the active bot for the user (like switching).
|
||||||
if (botGroup && user.instanceId !== botGroup.instanceId) {
|
|
||||||
await sec.updateUserInstance(id, botGroup.instanceId);
|
const message = req.group;
|
||||||
}
|
if (message.chatName.charAt(0) !== '+') {
|
||||||
if (botGroup) {
|
group = message.chatName;
|
||||||
activeMin = GBServer.globals.minInstances.filter
|
}
|
||||||
(p => p.instance.instanceId === botGroup.instanceId)[0];
|
}
|
||||||
await (activeMin as any).whatsAppDirectLine.received(req, res);
|
|
||||||
return; // EXIT HERE.
|
if (group) {
|
||||||
}
|
const botGroup = await this.min.core.loadInstanceByBotId(group);
|
||||||
|
if (botGroup && user.instanceId !== botGroup.instanceId) {
|
||||||
|
await sec.updateUserInstance(id, botGroup.instanceId);
|
||||||
|
}
|
||||||
|
if (botGroup) {
|
||||||
|
activeMin = GBServer.globals.minInstances.filter
|
||||||
|
(p => p.instance.instanceId === botGroup.instanceId)[0];
|
||||||
|
await (activeMin as any).whatsAppDirectLine.received(req, res);
|
||||||
|
return; // EXIT HERE.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue