From 32c5c004f35f0422767d0e0d5058c00c99fb26d0 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 9 Jul 2024 16:42:38 -0300 Subject: [PATCH] fix(whatsapp.gblib): Fix broadcasts. --- .../services/GBConversationalService.ts | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index 5e5b1bed..9f87e945 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -642,59 +642,55 @@ export class GBConversationalService { } public async fillAndBroadcastTemplate(min: GBMinInstance, mobile: string, text) { - if (text.startsWith('broadcastx')) { - await this.sendToMobile(min, mobile, { name: text }, null); - } else { - let isMedia = - text.toLowerCase().endsWith('.jpg') || - text.toLowerCase().endsWith('.jpeg') || - text.toLowerCase().endsWith('.png'); + let isMedia = + text.toLowerCase().endsWith('.jpg') || + text.toLowerCase().endsWith('.jpeg') || + text.toLowerCase().endsWith('.png'); - let image = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text; + let image = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text; - const gbaiName = DialogKeywords.getGBAIPath(min.botId); - const fileUrl = urlJoin(process.env.BOT_URL, 'kb', gbaiName, `${min.botId}.gbkb`, 'images', image); + const gbaiName = DialogKeywords.getGBAIPath(min.botId); + const fileUrl = urlJoin(process.env.BOT_URL, 'kb', gbaiName, `${min.botId}.gbkb`, 'images', image); - let urlImage = image.startsWith('http') ? image : fileUrl; + let urlImage = image.startsWith('http') ? image : fileUrl; - if (!isMedia) { - text = text.substring(image.length + 1).trim(); - text = text.replace(/\n/g, '\\n'); - } + if (!isMedia) { + text = text.substring(image.length + 1).trim(); + text = text.replace(/\n/g, '\\n'); + } - let template = isMedia ? image.replace(/\.[^/.]+$/, "") : 'broadcast1' + let template = isMedia ? image.replace(/\.[^/.]+$/, '') : 'broadcast1'; - let data: any = { - name: template , - components: [ - { - type: 'header', - parameters: [ - { - type: 'image', - image: { - link: urlImage - } - } - ] - } - ] - }; - - if (!isMedia) { - data.components.push({ - type: 'body', + let data: any = { + name: template, + components: [ + { + type: 'header', parameters: [ { - type: 'text', - text: text + type: 'image', + image: { + link: urlImage + } } ] - }); - } - await this.sendToMobile(min, mobile, data, null); - GBLogEx.info(min, `Sending answer file to mobile: ${mobile}. Header: ${urlImage}`); + } + ] + }; + + if (!isMedia) { + data.components.push({ + type: 'body', + parameters: [ + { + type: 'text', + text: text + } + ] + }); } + await this.sendToMobile(min, mobile, data, null); + GBLogEx.info(min, `Sending answer file to mobile: ${mobile}. Header: ${urlImage}`); } // tslint:enable:no-unsafe-any