diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index cda1ec2e..70c37b8d 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -332,7 +332,7 @@ export class GBMinService { return; } - let chatapi = false; + let chatapi = GBConfigService.get('CHATAPI'); if (!chatapi) { if (req.body.type !== 'message') { @@ -386,13 +386,15 @@ export class GBMinService { const group = message.chatName; const botGroup = await this.core.loadInstanceByBotId(group); - if (user.instanceId !== botGroup.instanceId) { + if (botGroup && user.instanceId !== botGroup.instanceId) { await sec.updateUserInstance(id, botGroup.instanceId); } - activeMin = GBServer.globals.minInstances.filter - (p => p.instance.instanceId === botGroup.instanceId)[0]; - await (activeMin as any).whatsAppDirectLine.received(req, res); - return; // EXIT HERE. + 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. + } } } @@ -506,6 +508,7 @@ export class GBMinService { await minInstance.whatsAppDirectLine.received(req, res); } } catch (error) { + GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`); } } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 31e716a5..c75ba90a 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -42,6 +42,7 @@ import { GBConversationalService } from '../../core.gbapp/services/GBConversatio import { SecService } from '../../security.gbapp/services/SecService'; import { Messages } from '../strings'; import { GuaribasUser } from '../../security.gbapp/models'; +import { GBConfigService } from '../../core.gbapp/services/GBConfigService'; /** * Support for Whatsapp. @@ -85,7 +86,7 @@ export class WhatsappDirectLine extends GBService { this.whatsappServiceKey = whatsappServiceKey; this.whatsappServiceNumber = whatsappServiceNumber; this.whatsappServiceUrl = whatsappServiceUrl; - + this.chatapi = GBConfigService.get('CHATAPI'); } public static async asyncForEach(array, callback) {