diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 473ea229..80973cd9 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -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]; } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 6cd3eab8..43dd2bb5 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -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') {