fix(basic.gbapp): AS IMAGE testing.

This commit is contained in:
Rodrigo Rodriguez 2023-08-13 17:42:16 -03:00
parent c4d7bdfc05
commit fa156750b4

View file

@ -559,13 +559,10 @@ export class DialogKeywords {
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
GBLog.info(`BASIC: ${name} = ${value} (botId: ${min.botId})`);
const sec = new SecService();
if (user)
{
if (user) {
await sec.setParam(user.userId, name, value);
return { min, user, params };
}
else
{
} else {
min[name] = value;
}
}
@ -579,9 +576,7 @@ export class DialogKeywords {
if (user) {
const sec = new SecService();
return await sec.getParam(user, name);
}
else
{
} else {
return min[name];
}
}
@ -700,10 +695,8 @@ export class DialogKeywords {
*/
public async userName({ pid }) {
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
if (user)
return user.userName;
else
return 'unattended';
if (user) return user.userName;
else return 'unattended';
}
/**
@ -711,10 +704,8 @@ export class DialogKeywords {
*/
public async userMobile({ pid }) {
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
if (user)
return user.userSystemId;
else
return 'unattended';
if (user) return user.userSystemId;
else return 'unattended';
}
/**
@ -940,13 +931,15 @@ export class DialogKeywords {
};
const parseDate = str => {
function pad(x){return (((''+x).length==2) ? '' : '0') + x; }
var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/)
, d = (m) ? new Date(m[3], m[2]-1, m[1]) : null
, matchesPadded = (d&&(str==[pad(d.getDate()),pad(d.getMonth()+1),d.getFullYear()].join('/')))
, matchesNonPadded = (d&&(str==[d.getDate(),d.getMonth()+1,d.getFullYear()].join('/')));
return (matchesPadded || matchesNonPadded) ? d : null;
function pad(x) {
return (('' + x).length == 2 ? '' : '0') + x;
}
var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),
d = m ? new Date(m[3], m[2] - 1, m[1]) : null,
matchesPadded = d && str == [pad(d.getDate()), pad(d.getMonth() + 1), d.getFullYear()].join('/'),
matchesNonPadded = d && str == [d.getDate(), d.getMonth() + 1, d.getFullYear()].join('/');
return matchesPadded || matchesNonPadded ? d : null;
};
let value = parseDate(answer);
@ -1190,13 +1183,11 @@ export class DialogKeywords {
}
// GBFILE object.
else if (filename.url) {
url = filename.url;
nameOnly = Path.basename(filename.localName);
}
// Handles Markdown.
else if (filename.indexOf('.md') > -1) {
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
const md = await min.kbService.getAnswerTextByMediaName(min.instance.instanceId, filename);
@ -1213,19 +1204,15 @@ export class DialogKeywords {
if (!filename.startsWith('https://')) {
url = urlJoin(GBServer.globals.publicAddress, 'kb', gbaiName, 'assets', filename);
} else {
url = filename
url = filename;
}
nameOnly = filename;
}
if (url) {
const reply = { type: ActivityTypes.Message, text: caption };
if (!url) {
const imageData = await (await fetch(url)).arrayBuffer();
const contentType = mime.lookup(url);
const ext = mime.extension(Path.extname(filename.localName));
reply['attachments'] = [];
// Prepare a cache to be referenced by Bot Framework.
@ -1234,7 +1221,11 @@ export class DialogKeywords {
const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.${ext}`);
Fs.writeFileSync(localName, buf, { encoding: null });
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
}
const contentType = mime.lookup(url);
const reply = { type: ActivityTypes.Message, text: caption };
reply['attachments'] = [];
reply['attachments'].push({
name: nameOnly,
contentType: contentType,
@ -1247,7 +1238,6 @@ export class DialogKeywords {
await min.conversationalService['sendOnConversation'](min, user, reply);
}
}
}
/**
* Generates a new QRCode.
*