fix(whatsapp.gblib): SEND FILE sending bug.

This commit is contained in:
Rodrigo Rodriguez 2022-08-05 21:26:23 -03:00
parent c0ab88eb0f
commit 9cb285214c

View file

@ -262,6 +262,7 @@ export class WhatsappDirectLine extends GBService {
let message, from, fromName, text; let message, from, fromName, text;
let group = ""; let group = "";
let answerText = null; let answerText = null;
let attachments = null;
switch (provider) { switch (provider) {
case 'GeneralBots': case 'GeneralBots':
@ -270,6 +271,17 @@ export class WhatsappDirectLine extends GBService {
from = message.from.split('@')[0]; from = message.from.split('@')[0];
fromName = message._data.notifyName; fromName = message._data.notifyName;
if (message.hasMedia) {
const base64Image = await message.downloadMedia();
attachments = [];
attachments.push(
{
name: 'uploaded.png',
contentType: 'image/png',
contentUrl: `data:image/png;base64,${base64Image}`
});
}
break; break;
case 'chatapi': case 'chatapi':
@ -500,16 +512,16 @@ export class WhatsappDirectLine extends GBService {
this.pollMessages(client, generatedConversationId, from, fromName); this.pollMessages(client, generatedConversationId, from, fromName);
this.inputMessage(client, generatedConversationId, text, from, fromName, group); this.inputMessage(client, generatedConversationId, text, from, fromName, group, attachments);
} else { } else {
this.inputMessage(client, conversationId, text, from, fromName, group); this.inputMessage(client, conversationId, text, from, fromName, group, attachments);
} }
} else { } else {
GBLog.warn(`Inconsistencty found: Invalid agentMode on User Table: ${user.agentMode}`); GBLog.warn(`Inconsistencty found: Invalid agentMode on User Table: ${user.agentMode}`);
} }
if (res){ if (res) {
res.end(); res.end();
} }
} }
@ -528,7 +540,7 @@ export class WhatsappDirectLine extends GBService {
await sec.updateHumanAgent(id, this.min.instance.instanceId, null); await sec.updateHumanAgent(id, this.min.instance.instanceId, null);
} }
public inputMessage(client, conversationId, text, from, fromName, group) { public inputMessage(client, conversationId, text, from, fromName, group, attachments) {
return client.Conversations.Conversations_PostActivity({ return client.Conversations.Conversations_PostActivity({
conversationId: conversationId, conversationId: conversationId,
activity: { activity: {
@ -537,6 +549,7 @@ export class WhatsappDirectLine extends GBService {
type: 'message', type: 'message',
mobile: from, mobile: from,
group: group, group: group,
attachments: attachments,
from: { from: {
id: from, id: from,
name: fromName name: fromName