new(whatsapp.gblib): New provider.

This commit is contained in:
Rodrigo Rodriguez 2022-06-07 23:48:12 -03:00
parent c39618c182
commit 736490dd94
2 changed files with 11 additions and 7 deletions

View file

@ -332,7 +332,7 @@ export class GBMinService {
return; return;
} }
let chatapi = false; let chatapi = GBConfigService.get('CHATAPI');
if (!chatapi) { if (!chatapi) {
if (req.body.type !== 'message') { if (req.body.type !== 'message') {
@ -386,13 +386,15 @@ export class GBMinService {
const group = message.chatName; const group = message.chatName;
const botGroup = await this.core.loadInstanceByBotId(group); const botGroup = await this.core.loadInstanceByBotId(group);
if (user.instanceId !== botGroup.instanceId) { if (botGroup && user.instanceId !== botGroup.instanceId) {
await sec.updateUserInstance(id, botGroup.instanceId); await sec.updateUserInstance(id, botGroup.instanceId);
} }
activeMin = GBServer.globals.minInstances.filter if (botGroup) {
(p => p.instance.instanceId === botGroup.instanceId)[0]; activeMin = GBServer.globals.minInstances.filter
await (activeMin as any).whatsAppDirectLine.received(req, res); (p => p.instance.instanceId === botGroup.instanceId)[0];
return; // EXIT HERE. await (activeMin as any).whatsAppDirectLine.received(req, res);
return; // EXIT HERE.
}
} }
} }
@ -506,6 +508,7 @@ export class GBMinService {
await minInstance.whatsAppDirectLine.received(req, res); await minInstance.whatsAppDirectLine.received(req, res);
} }
} catch (error) { } catch (error) {
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`); GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`);
} }
} }

View file

@ -42,6 +42,7 @@ import { GBConversationalService } from '../../core.gbapp/services/GBConversatio
import { SecService } from '../../security.gbapp/services/SecService'; import { SecService } from '../../security.gbapp/services/SecService';
import { Messages } from '../strings'; import { Messages } from '../strings';
import { GuaribasUser } from '../../security.gbapp/models'; import { GuaribasUser } from '../../security.gbapp/models';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
/** /**
* Support for Whatsapp. * Support for Whatsapp.
@ -85,7 +86,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');
} }
public static async asyncForEach(array, callback) { public static async asyncForEach(array, callback) {