fix(whatsapp.gblib): Fix broadcasts.
This commit is contained in:
parent
7b2c9238d3
commit
32c5c004f3
1 changed files with 38 additions and 42 deletions
|
@ -642,59 +642,55 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fillAndBroadcastTemplate(min: GBMinInstance, mobile: string, text) {
|
public async fillAndBroadcastTemplate(min: GBMinInstance, mobile: string, text) {
|
||||||
if (text.startsWith('broadcastx')) {
|
let isMedia =
|
||||||
await this.sendToMobile(min, mobile, { name: text }, null);
|
text.toLowerCase().endsWith('.jpg') ||
|
||||||
} else {
|
text.toLowerCase().endsWith('.jpeg') ||
|
||||||
let isMedia =
|
text.toLowerCase().endsWith('.png');
|
||||||
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 gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const fileUrl = urlJoin(process.env.BOT_URL, 'kb', gbaiName, `${min.botId}.gbkb`, 'images', image);
|
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) {
|
if (!isMedia) {
|
||||||
text = text.substring(image.length + 1).trim();
|
text = text.substring(image.length + 1).trim();
|
||||||
text = text.replace(/\n/g, '\\n');
|
text = text.replace(/\n/g, '\\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
let template = isMedia ? image.replace(/\.[^/.]+$/, "") : 'broadcast1'
|
let template = isMedia ? image.replace(/\.[^/.]+$/, '') : 'broadcast1';
|
||||||
|
|
||||||
let data: any = {
|
let data: any = {
|
||||||
name: template ,
|
name: template,
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
type: 'header',
|
type: 'header',
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
image: {
|
|
||||||
link: urlImage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!isMedia) {
|
|
||||||
data.components.push({
|
|
||||||
type: 'body',
|
|
||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'image',
|
||||||
text: text
|
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
|
// tslint:enable:no-unsafe-any
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue