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
|
||||
.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') {
|
||||
const val = req.query['hub.verify_token'];
|
||||
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.
|
||||
|
||||
const handler = async context => {
|
||||
|
||||
const member = context.activity.recipient ? context.activity.recipient : context.activity.from;
|
||||
|
||||
// Handle activity text issues.
|
||||
|
||||
if (!context.activity.text) {
|
||||
|
@ -1031,7 +1042,7 @@ export class GBMinService {
|
|||
const step = await min.dialogs.createContext(context);
|
||||
step.context.activity.locale = 'pt-BR';
|
||||
|
||||
const member = context.activity.recipient ? context.activity.recipient : context.activity.from;
|
||||
|
||||
const sec = new SecService();
|
||||
let user = await sec.ensureUser(min, member.id, member.name, '', 'web', member.name, null);
|
||||
const userId = user.userId;
|
||||
|
@ -1085,10 +1096,7 @@ export class GBMinService {
|
|||
}
|
||||
}
|
||||
|
||||
let pid = step.context.activity['pid'] ?
|
||||
step.context.activity['pid'] :
|
||||
step.context.activity.from['pid'];
|
||||
|
||||
let pid = WhatsappDirectLine.pidByNumber[member.id];
|
||||
let recipient = context.activity?.recipient?.id;
|
||||
|
||||
if (!pid && recipient !== min.botId) {
|
||||
|
|
|
@ -65,6 +65,7 @@ import { createReadStream } from 'fs';
|
|||
export class WhatsappDirectLine extends GBService {
|
||||
public static conversationIds = {};
|
||||
public static botsByNumber = {};
|
||||
public static pidByNumber = {};
|
||||
public static mobiles = {};
|
||||
public static phones = {};
|
||||
public static chatIds = {};
|
||||
|
@ -530,11 +531,14 @@ export class WhatsappDirectLine extends GBService {
|
|||
} else if (user.agentMode === 'bot' || user.agentMode === null || user.agentMode === undefined) {
|
||||
if (WhatsappDirectLine.conversationIds[botId + from + group] === undefined) {
|
||||
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}).`);
|
||||
let response;
|
||||
if (GBConfigService.get('STORAGE_NAME')) {
|
||||
response = await client.apis.Conversations.Conversations_StartConversation(
|
||||
|
||||
{ userSystemId: user.userSystemId,
|
||||
userName: user.userName,
|
||||
pid: pid}
|
||||
);
|
||||
} else {
|
||||
response = await client.apis.Conversations.Conversations_StartConversation(
|
||||
|
@ -554,6 +558,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
WhatsappDirectLine.mobiles[generatedConversationId] = from;
|
||||
WhatsappDirectLine.usernames[from] = fromName;
|
||||
WhatsappDirectLine.chatIds[generatedConversationId] = message?.chatId;
|
||||
|
||||
|
||||
this.pollMessages(client, generatedConversationId, from, fromName);
|
||||
this.inputMessage(client, generatedConversationId, text, from, fromName, group, attachments, pid);
|
||||
|
|
Loading…
Add table
Reference in a new issue