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

This commit is contained in:
Rodrigo Rodriguez 2022-08-05 21:48:28 -03:00
parent 61183a3654
commit 08607e49bb

View file

@ -54,18 +54,28 @@ export class HearDialog {
const url = attachment.contentUrl; const url = attachment.contentUrl;
const localFolder = Path.join('work', 'dev-rodriguez.gbai', 'uploads'); const localFolder = Path.join('work'); // TODO: , '${botId}', 'uploads');
const localFileName = Path.join(localFolder, attachment.name); const localFileName = Path.join(localFolder, attachment.name);
try { try {
let response;
if (url.startsWith('data:')){
var regex = /^data:.+\/(.+);base64,(.*)$/;
var matches = url.match(regex);
var ext = matches[1];
var data = matches[2];
response = Buffer.from(data, 'base64');
}
else{
// arraybuffer is necessary for images // arraybuffer is necessary for images
const options = { const options = {
url: url, url: url,
method: 'GET', method: 'GET',
encoding: 'binary', encoding: 'binary',
}; };
let response = await request.get(options); response = await request.get(options);
}
fs.writeFile(localFileName, response, (fsError) => { fs.writeFile(localFileName, response, (fsError) => {
if (fsError) { if (fsError) {