new(whatsapp.gblib): New provider.

This commit is contained in:
Rodrigo Rodriguez 2022-06-09 14:19:09 -03:00
parent 562beca57b
commit 0c967a9f71
3 changed files with 10 additions and 10 deletions

View file

@ -700,7 +700,7 @@ export class DialogKeywords {
}
sleep(5000);
}
const result = WhatsappDirectLine.lastMessage[mobile];
const result = WhatsappDirectLine.lastMessage[this.min.instance.botId + mobile];
opts = await promise(step, result);
if (previousResolve !== undefined) {

View file

@ -468,7 +468,7 @@ export class GBMinService {
const instance = await this.core.loadInstanceByBotId(activeMin.botId);
await sec.updateUserInstance(id, instance.instanceId);
await (activeMin as any).whatsAppDirectLine.resetConversationId(id, '');
await (activeMin as any).whatsAppDirectLine.resetConversationId(activeMin.botId, id, '');
const startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null);

View file

@ -133,7 +133,7 @@ export class WhatsappDirectLine extends GBService {
let productId = this.whatsappServiceNumber.split(';')[1]
let url = `${this.INSTANCE_URL}/${productId}/setWebhook`;
let webhook = `${GBServer.globals.publicAddress}/webhooks/whatsapp/${this.botId}`;
let webhook = `${GBServer.globals.publicAddress}/webhooks/whatsapp`;
WhatsappDirectLine.phones[phoneId] = this.botId;
options = {
@ -162,8 +162,8 @@ export class WhatsappDirectLine extends GBService {
}
public async resetConversationId(number, group = '') {
WhatsappDirectLine.conversationIds[number + group] = undefined;
public async resetConversationId(botId, number, group = '') {
WhatsappDirectLine.conversationIds[botId + number + group] = undefined;
}
public async check() {
@ -316,12 +316,12 @@ export class WhatsappDirectLine extends GBService {
`No momento estou apenas conseguindo ler mensagens de texto.`, null);
}
}
const conversationId = WhatsappDirectLine.conversationIds[from + group];
const botId = this.min.instance.botId;
const conversationId = WhatsappDirectLine.conversationIds[botId + from + group];
const client = await this.directLineClient;
WhatsappDirectLine.lastMessage[from] = message;
WhatsappDirectLine.lastMessage[botId + from] = message;
// Check if this message is from a Human Agent itself.
@ -393,12 +393,12 @@ export class WhatsappDirectLine extends GBService {
} else if (user.agentMode === 'bot' || user.agentMode === null || user.agentMode === undefined) {
if (WhatsappDirectLine.conversationIds[from + group] === undefined) {
if (WhatsappDirectLine.conversationIds[botId + from + group] === undefined) {
GBLog.info(`GBWhatsapp: Starting new conversation on Bot.`);
const response = await client.Conversations.Conversations_StartConversation();
const generatedConversationId = response.obj.conversationId;
WhatsappDirectLine.conversationIds[from + group] = generatedConversationId;
WhatsappDirectLine.conversationIds[botId + from + group] = generatedConversationId;
WhatsappDirectLine.mobiles[generatedConversationId] = from;
WhatsappDirectLine.usernames[from] = fromName;
WhatsappDirectLine.chatIds[generatedConversationId] = message.chatId;