new(whatsapp.gblib): Multiple providers can be loaded at once.

This commit is contained in:
Rodrigo Rodriguez 2022-07-07 11:14:02 -03:00
parent 17616c636e
commit a6c3d7db6a
2 changed files with 12 additions and 9 deletions

View file

@ -320,6 +320,10 @@ export class GBMinService {
this.createCheckHealthAddress(GBServer.globals.server, min, min.instance); this.createCheckHealthAddress(GBServer.globals.server, min, min.instance);
} }
public static isChatAPI(req) {
return req.body.phone_id ? false : true;
}
private async WhatsAppCallback(req, res) { private async WhatsAppCallback(req, res) {
try { try {
@ -330,16 +334,16 @@ export class GBMinService {
return; return;
} }
let chatapi = GBConfigService.get('CHATAPI') === 'true'; let chatapi = GBMinService.isChatAPI(req);
if (chatapi) { if (chatapi) {
if (req.body.ack){ if (req.body.ack) {
res.status(200); res.status(200);
res.end(); res.end();
return; return;
} }
}else{ } else {
if (req.body.type !== 'message') { if (req.body.type !== 'message') {
res.status(200); res.status(200);
res.end(); res.end();
@ -379,7 +383,7 @@ export class GBMinService {
botId = GBConfigService.get('BOT_ID'); botId = GBConfigService.get('BOT_ID');
} }
} }
else { else {
botId = WhatsappDirectLine.phones[req.body.phoneId]; botId = WhatsappDirectLine.phones[req.body.phoneId];
} }

View file

@ -87,7 +87,7 @@ export class WhatsappDirectLine extends GBService {
this.whatsappServiceKey = whatsappServiceKey; this.whatsappServiceKey = whatsappServiceKey;
this.whatsappServiceNumber = whatsappServiceNumber; this.whatsappServiceNumber = whatsappServiceNumber;
this.whatsappServiceUrl = whatsappServiceUrl; this.whatsappServiceUrl = whatsappServiceUrl;
this.chatapi = GBConfigService.get('CHATAPI') === 'true'; this.chatapi = whatsappServiceNumber.indexOf(':') > -1 ? true : false;
} }
public static async asyncForEach(array, callback) { public static async asyncForEach(array, callback) {
@ -281,7 +281,7 @@ export class WhatsappDirectLine extends GBService {
const botId = this.min.instance.botId; const botId = this.min.instance.botId;
const state = WhatsappDirectLine.state[botId + from]; const state = WhatsappDirectLine.state[botId + from];
if ( state) { if (state) {
WhatsappDirectLine.state[botId + from] = null; WhatsappDirectLine.state[botId + from] = null;
await state.promise(null, message.text); await state.promise(null, message.text);
@ -305,7 +305,6 @@ export class WhatsappDirectLine extends GBService {
await this.sendToDeviceEx(user.userSystemId, answerText, locale, null); await this.sendToDeviceEx(user.userSystemId, answerText, locale, null);
return; // Exit here. return; // Exit here.
} }
if (message.type === 'ptt') { if (message.type === 'ptt') {