fix(whatsapp.gblib): SEND FILE sending bug.
This commit is contained in:
parent
61183a3654
commit
08607e49bb
1 changed files with 13 additions and 3 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue