Skip to content

Commit

Permalink
fix(whatsapp.gblib): SEND FILE sending bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Aug 6, 2022
1 parent c0ab88e commit 9cb2852
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class WhatsappDirectLine extends GBService {
let message, from, fromName, text;
let group = "";
let answerText = null;
let attachments = null;

switch (provider) {
case 'GeneralBots':
Expand All @@ -270,6 +271,17 @@ export class WhatsappDirectLine extends GBService {
from = message.from.split('@')[0];
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;

case 'chatapi':
Expand Down Expand Up @@ -500,16 +512,16 @@ export class WhatsappDirectLine extends GBService {


this.pollMessages(client, generatedConversationId, from, fromName);
this.inputMessage(client, generatedConversationId, text, from, fromName, group);
this.inputMessage(client, generatedConversationId, text, from, fromName, group, attachments);
} else {

this.inputMessage(client, conversationId, text, from, fromName, group);
this.inputMessage(client, conversationId, text, from, fromName, group, attachments);
}
} else {
GBLog.warn(`Inconsistencty found: Invalid agentMode on User Table: ${user.agentMode}`);
}

if (res){
if (res) {
res.end();
}
}
Expand All @@ -528,7 +540,7 @@ export class WhatsappDirectLine extends GBService {
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({
conversationId: conversationId,
activity: {
Expand All @@ -537,6 +549,7 @@ export class WhatsappDirectLine extends GBService {
type: 'message',
mobile: from,
group: group,
attachments: attachments,
from: {
id: from,
name: fromName
Expand Down

0 comments on commit 9cb2852

Please sign in to comment.