fix(DialogKeywords): update file writing method and adjust WhatsApp file sending logic
All checks were successful
GBCI / build (push) Successful in 37s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-04-19 14:27:23 -03:00
parent 7c05a95054
commit 638534e31f
2 changed files with 16 additions and 15 deletions

View file

@ -1542,7 +1542,7 @@ export class DialogKeywords {
accessKey: process.env.DRIVE_ACCESSKEY,
secretKey: process.env.DRIVE_SECRET,
});
const bucketName = (process.env.DRIVE_ORG_PREFIX + min.botId + '.gbai').toLowerCase();
localName = path.join(
'work',
@ -1553,8 +1553,9 @@ export class DialogKeywords {
await minioClient.fGetObject(bucketName, fileUrl, localName);
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', path.basename(localName));
GBLogEx.info(min, `Exposing ${localName} to ${url}...`);
}
@ -1608,7 +1609,6 @@ export class DialogKeywords {
const localName = path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.${ext}`);
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', path.basename(localName));
GBLogEx.info(min, `Exposing ${localName} to ${url}...`);
await fs.writeFile(localName, new Uint8Array(buf), { encoding: null });
}

View file

@ -734,8 +734,17 @@ export class WhatsappDirectLine extends GBService {
await this.sendImageViewOnce(to, url, caption);
}
else {
const driver = createBot(whatsappServiceNumber, whatsappServiceKey);
await driver.sendImage(to, url, { caption: caption });
const driver = createBot(whatsappServiceNumber, whatsappServiceKey);
const fileExtension = path.extname(url).toLowerCase();
if (['.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.txt', '.ods', '.csv'].includes(fileExtension)) {
await driver.sendDocument(to, url, { caption: caption });
} else if (['.mp3', '.wav', '.ogg', '.aac', '.m4a'].includes(fileExtension)) {
await driver.sendAudio(to, url);
} else {
await driver.sendImage(to, url, { caption: caption });
}
}
break;
@ -753,16 +762,8 @@ export class WhatsappDirectLine extends GBService {
await this.customClient.sendMessage(to, attachment, { caption: caption, isViewOnce });
break;
}
if (options) {
try {
// tslint:disable-next-line: await-promise
const result = await fetch(url, options);
GBLogEx.info(this.min, `File ${url} sent to ${to}: ${result}`);
} catch (error) {
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
}
}
GBLogEx.info(this.min, `File ${url} sent to ${to}.`);
}
public async sendAudioToDevice(to, url) {