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);
}
public static isChatAPI(req) {
return req.body.phone_id ? false : true;
}
private async WhatsAppCallback(req, res) {
try {
@ -330,16 +334,16 @@ export class GBMinService {
return;
}
let chatapi = GBConfigService.get('CHATAPI') === 'true';
let chatapi = GBMinService.isChatAPI(req);
if (chatapi) {
if (req.body.ack){
if (req.body.ack) {
res.status(200);
res.end();
return;
}
}else{
} else {
if (req.body.type !== 'message') {
res.status(200);
res.end();
@ -379,7 +383,7 @@ export class GBMinService {
botId = GBConfigService.get('BOT_ID');
}
}
else {
else {
botId = WhatsappDirectLine.phones[req.body.phoneId];
}

View file

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