new(basic.gblib): Video in WPP templates.

This commit is contained in:
Rodrigo Rodriguez 2024-09-05 15:03:38 -03:00
parent 14b833a580
commit 72a0950fdb

View file

@ -644,7 +644,7 @@ export class GBConversationalService {
public async fillAndBroadcastTemplate(min: GBMinInstance, template, mobile: string, text) { public async fillAndBroadcastTemplate(min: GBMinInstance, template, mobile: string, text) {
template = template.replace(/\-/gi, '_'); template = template.replace(/\-/gi, '_');
template = template.replace(/\./gi, '_'); template = template.replace(/\./gi, '_');
let isMedia = let isMedia =
text.toLowerCase().endsWith('.jpg') || text.toLowerCase().endsWith('.jpg') ||
text.toLowerCase().endsWith('.jpeg') || text.toLowerCase().endsWith('.jpeg') ||
@ -653,21 +653,21 @@ export class GBConversationalService {
text.toLowerCase().endsWith('.mov'); text.toLowerCase().endsWith('.mov');
let mediaType = text.toLowerCase().endsWith('.mp4') || text.toLowerCase().endsWith('.mov') ? 'video' : 'image'; let mediaType = text.toLowerCase().endsWith('.mp4') || text.toLowerCase().endsWith('.mov') ? 'video' : 'image';
let mediaFile = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text; let mediaFile = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text;
// Set folder based on media type // Set folder based on media type
const folder = mediaType === 'videos' ? 'videos' : 'images'; const folder = mediaType === 'videos' ? 'videos' : 'images';
const gbaiName = DialogKeywords.getGBAIPath(min.botId); const gbaiName = DialogKeywords.getGBAIPath(min.botId);
const fileUrl = urlJoin(process.env.BOT_URL, 'kb', gbaiName, `${min.botId}.gbkb`, folder, mediaFile); const fileUrl = urlJoin(process.env.BOT_URL, 'kb', gbaiName, `${min.botId}.gbkb`, folder, mediaFile);
let urlMedia = mediaFile.startsWith('http') ? mediaFile : fileUrl; let urlMedia = mediaFile.startsWith('http') ? mediaFile : fileUrl;
if (!isMedia) { if (!isMedia) {
text = text.substring(mediaFile.length + 1).trim(); text = text.substring(mediaFile.length + 1).trim();
text = text.replace(/\n/g, '\\n'); text = text.replace(/\n/g, '\\n');
} }
template = isMedia ? mediaFile.replace(/\.[^/.]+$/, '') : template; template = isMedia ? mediaFile.replace(/\.[^/.]+$/, '') : template;
let data: any = { let data: any = {
name: template, name: template,
components: [ components: [
@ -684,11 +684,13 @@ export class GBConversationalService {
} }
] ]
}; };
data['components'][0]['parameters'][0][mediaType] = {link: urlMedia};
await this.sendToMobile(min, mobile, data, null); await this.sendToMobile(min, mobile, data, null);
GBLogEx.info(min, `Sending answer file to mobile: ${mobile}. Header: ${urlMedia}`); GBLogEx.info(min, `Sending answer file to mobile: ${mobile}. Header: ${urlMedia}`);
} }
// tslint:enable:no-unsafe-any // tslint:enable:no-unsafe-any
public async sendMarkdownToMobile(min: GBMinInstance, step: GBDialogStep, mobile: string, text: string) { public async sendMarkdownToMobile(min: GBMinInstance, step: GBDialogStep, mobile: string, text: string) {