new(basic.gblib): CHART PROMPT and chart mode.

This commit is contained in:
Rodrigo Rodriguez 2024-09-05 14:26:08 -03:00
parent 1217660442
commit 2007dc072c
2 changed files with 19 additions and 17 deletions

View file

@ -341,7 +341,6 @@ export class GBConversationalService {
} }
public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> { public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
if (step.context.activity.channelId !== 'msteams' && step.context.activity.channelId !== 'omnichannel') { if (step.context.activity.channelId !== 'msteams' && step.context.activity.channelId !== 'omnichannel') {
GBLogEx.info( GBLogEx.info(
min, min,
@ -642,30 +641,32 @@ 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') ||
text.toLowerCase().endsWith('.png'); text.toLowerCase().endsWith('.png') ||
text.toLowerCase().endsWith('.mp4') ||
text.toLowerCase().endsWith('.mov');
let image = !isMedia ? /(.*)\n/gim.exec(text)[0].trim() : text; let mediaFile = !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`, 'media', mediaFile);
let urlImage = image.startsWith('http') ? image : fileUrl; let urlMedia = mediaFile.startsWith('http') ? mediaFile : fileUrl;
if (!isMedia) { if (!isMedia) {
text = text.substring(image.length + 1).trim(); text = text.substring(mediaFile.length + 1).trim();
text = text.replace(/\n/g, '\\n'); text = text.replace(/\n/g, '\\n');
} }
template = isMedia ? image.replace(/\.[^/.]+$/, '') : template; template = isMedia ? mediaFile.replace(/\.[^/.]+$/, '') : template;
let mediaType = text.toLowerCase().endsWith('.mp4') || text.toLowerCase().endsWith('.mov') ? 'video' : 'image';
let data: any = { let data: any = {
name: template, name: template,
@ -674,9 +675,9 @@ export class GBConversationalService {
type: 'header', type: 'header',
parameters: [ parameters: [
{ {
type: 'image', type: mediaType,
image: { media: {
link: urlImage link: urlMedia
} }
} }
] ]
@ -685,8 +686,9 @@ export class GBConversationalService {
}; };
await this.sendToMobile(min, mobile, data, null); await this.sendToMobile(min, mobile, data, null);
GBLogEx.info(min, `Sending answer file to mobile: ${mobile}. Header: ${urlImage}`); 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) {

View file

@ -16,5 +16,5 @@ POST TO INSTAGRAM username, password, image, caption
# Postar no Facebook # Postar no Facebook
POST TO FACEBOOK username, password, image, caption POST TO FACEBOOK username, password, image, caption
# Postar no Twitter # Postar no BlueSky
TWEET username, password, image, caption BLUESKY username, password, image, caption