fix(all): Templates OK.
This commit is contained in:
parent
2a245f9530
commit
d62c227431
2 changed files with 19 additions and 6 deletions
|
@ -451,6 +451,14 @@ export class GBMinService {
|
||||||
|
|
||||||
GBServer.globals.server
|
GBServer.globals.server
|
||||||
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
||||||
|
|
||||||
|
const status = req.body?.entry?.[0]?.changes?.[0]?.value?.statuses?.[0];
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
GBLogEx.info(min, `WhatsApp: ${status.recipient_id} ${status.status}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (req.query['hub.mode'] === 'subscribe') {
|
if (req.query['hub.mode'] === 'subscribe') {
|
||||||
const val = req.query['hub.verify_token'];
|
const val = req.query['hub.verify_token'];
|
||||||
const challenge = (min.core['getParam'] as any)(min.instance, `Meta Challenge`, null, true);
|
const challenge = (min.core['getParam'] as any)(min.instance, `Meta Challenge`, null, true);
|
||||||
|
@ -1019,6 +1027,9 @@ export class GBMinService {
|
||||||
// Default activity processing and handler.
|
// Default activity processing and handler.
|
||||||
|
|
||||||
const handler = async context => {
|
const handler = async context => {
|
||||||
|
|
||||||
|
const member = context.activity.recipient ? context.activity.recipient : context.activity.from;
|
||||||
|
|
||||||
// Handle activity text issues.
|
// Handle activity text issues.
|
||||||
|
|
||||||
if (!context.activity.text) {
|
if (!context.activity.text) {
|
||||||
|
@ -1031,7 +1042,7 @@ export class GBMinService {
|
||||||
const step = await min.dialogs.createContext(context);
|
const step = await min.dialogs.createContext(context);
|
||||||
step.context.activity.locale = 'pt-BR';
|
step.context.activity.locale = 'pt-BR';
|
||||||
|
|
||||||
const member = context.activity.recipient ? context.activity.recipient : context.activity.from;
|
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
let user = await sec.ensureUser(min, member.id, member.name, '', 'web', member.name, null);
|
let user = await sec.ensureUser(min, member.id, member.name, '', 'web', member.name, null);
|
||||||
const userId = user.userId;
|
const userId = user.userId;
|
||||||
|
@ -1085,10 +1096,7 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pid = step.context.activity['pid'] ?
|
let pid = WhatsappDirectLine.pidByNumber[member.id];
|
||||||
step.context.activity['pid'] :
|
|
||||||
step.context.activity.from['pid'];
|
|
||||||
|
|
||||||
let recipient = context.activity?.recipient?.id;
|
let recipient = context.activity?.recipient?.id;
|
||||||
|
|
||||||
if (!pid && recipient !== min.botId) {
|
if (!pid && recipient !== min.botId) {
|
||||||
|
|
|
@ -65,6 +65,7 @@ import { createReadStream } from 'fs';
|
||||||
export class WhatsappDirectLine extends GBService {
|
export class WhatsappDirectLine extends GBService {
|
||||||
public static conversationIds = {};
|
public static conversationIds = {};
|
||||||
public static botsByNumber = {};
|
public static botsByNumber = {};
|
||||||
|
public static pidByNumber = {};
|
||||||
public static mobiles = {};
|
public static mobiles = {};
|
||||||
public static phones = {};
|
public static phones = {};
|
||||||
public static chatIds = {};
|
public static chatIds = {};
|
||||||
|
@ -530,11 +531,14 @@ export class WhatsappDirectLine extends GBService {
|
||||||
} else if (user.agentMode === 'bot' || user.agentMode === null || user.agentMode === undefined) {
|
} else if (user.agentMode === 'bot' || user.agentMode === null || user.agentMode === undefined) {
|
||||||
if (WhatsappDirectLine.conversationIds[botId + from + group] === undefined) {
|
if (WhatsappDirectLine.conversationIds[botId + from + group] === undefined) {
|
||||||
const pid = GBVMService.createProcessInfo(user, this.min, 'whatsapp', null);
|
const pid = GBVMService.createProcessInfo(user, this.min, 'whatsapp', null);
|
||||||
|
WhatsappDirectLine.pidByNumber[from] = pid;
|
||||||
GBLogEx.info(this.min, `GBWhatsapp: Starting new conversation on Bot (pid: ${pid}).`);
|
GBLogEx.info(this.min, `GBWhatsapp: Starting new conversation on Bot (pid: ${pid}).`);
|
||||||
let response;
|
let response;
|
||||||
if (GBConfigService.get('STORAGE_NAME')) {
|
if (GBConfigService.get('STORAGE_NAME')) {
|
||||||
response = await client.apis.Conversations.Conversations_StartConversation(
|
response = await client.apis.Conversations.Conversations_StartConversation(
|
||||||
|
{ userSystemId: user.userSystemId,
|
||||||
|
userName: user.userName,
|
||||||
|
pid: pid}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
response = await client.apis.Conversations.Conversations_StartConversation(
|
response = await client.apis.Conversations.Conversations_StartConversation(
|
||||||
|
@ -555,6 +559,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
WhatsappDirectLine.usernames[from] = fromName;
|
WhatsappDirectLine.usernames[from] = fromName;
|
||||||
WhatsappDirectLine.chatIds[generatedConversationId] = message?.chatId;
|
WhatsappDirectLine.chatIds[generatedConversationId] = message?.chatId;
|
||||||
|
|
||||||
|
|
||||||
this.pollMessages(client, generatedConversationId, from, fromName);
|
this.pollMessages(client, generatedConversationId, from, fromName);
|
||||||
this.inputMessage(client, generatedConversationId, text, from, fromName, group, attachments, pid);
|
this.inputMessage(client, generatedConversationId, text, from, fromName, group, attachments, pid);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue