fix(basic.gbapp): AS IMAGE testing.
This commit is contained in:
parent
c4d7bdfc05
commit
fa156750b4
1 changed files with 43 additions and 53 deletions
|
@ -559,13 +559,10 @@ export class DialogKeywords {
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLog.info(`BASIC: ${name} = ${value} (botId: ${min.botId})`);
|
GBLog.info(`BASIC: ${name} = ${value} (botId: ${min.botId})`);
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
if (user)
|
if (user) {
|
||||||
{
|
await sec.setParam(user.userId, name, value);
|
||||||
await sec.setParam(user.userId, name , value);
|
|
||||||
return { min, user, params };
|
return { min, user, params };
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
min[name] = value;
|
min[name] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,12 +573,10 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
if (user){
|
if (user) {
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
return await sec.getParam(user, name);
|
return await sec.getParam(user, name);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return min[name];
|
return min[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -700,10 +695,8 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async userName({ pid }) {
|
public async userName({ pid }) {
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
if (user)
|
if (user) return user.userName;
|
||||||
return user.userName;
|
else return 'unattended';
|
||||||
else
|
|
||||||
return 'unattended';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -711,10 +704,8 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async userMobile({ pid }) {
|
public async userMobile({ pid }) {
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
if (user)
|
if (user) return user.userSystemId;
|
||||||
return user.userSystemId;
|
else return 'unattended';
|
||||||
else
|
|
||||||
return 'unattended';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -750,7 +741,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async hear({ pid, kind, args }) {
|
public async hear({ pid, kind, args }) {
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
// Handles first arg as an array of args.
|
// Handles first arg as an array of args.
|
||||||
|
|
||||||
|
@ -940,13 +931,15 @@ export class DialogKeywords {
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseDate = str => {
|
const parseDate = str => {
|
||||||
function pad(x){return (((''+x).length==2) ? '' : '0') + x; }
|
function pad(x) {
|
||||||
var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/)
|
return (('' + x).length == 2 ? '' : '0') + x;
|
||||||
, 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('/')))
|
var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),
|
||||||
, matchesNonPadded = (d&&(str==[d.getDate(),d.getMonth()+1,d.getFullYear()].join('/')));
|
d = m ? new Date(m[3], m[2] - 1, m[1]) : null,
|
||||||
return (matchesPadded || matchesNonPadded) ? d : 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);
|
let value = parseDate(answer);
|
||||||
|
|
||||||
|
@ -1136,7 +1129,7 @@ export class DialogKeywords {
|
||||||
const min = GBServer.globals.minInstances.filter(p => p.instance.instanceId == proc.instanceId)[0];
|
const min = GBServer.globals.minInstances.filter(p => p.instance.instanceId == proc.instanceId)[0];
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
const user = await sec.getUserFromId(min.instance.instanceId, proc.userId);
|
const user = await sec.getUserFromId(min.instance.instanceId, proc.userId);
|
||||||
const params = user? JSON.parse(user.params): {};
|
const params = user ? JSON.parse(user.params) : {};
|
||||||
return {
|
return {
|
||||||
min,
|
min,
|
||||||
user,
|
user,
|
||||||
|
@ -1190,13 +1183,11 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GBFILE object.
|
// GBFILE object.
|
||||||
|
|
||||||
else if (filename.url) {
|
else if (filename.url) {
|
||||||
url = filename.url;
|
url = filename.url;
|
||||||
nameOnly = Path.basename(filename.localName);
|
nameOnly = Path.basename(filename.localName);
|
||||||
}
|
}
|
||||||
// Handles Markdown.
|
// Handles Markdown.
|
||||||
|
|
||||||
else if (filename.indexOf('.md') > -1) {
|
else if (filename.indexOf('.md') > -1) {
|
||||||
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
||||||
const md = await min.kbService.getAnswerTextByMediaName(min.instance.instanceId, filename);
|
const md = await min.kbService.getAnswerTextByMediaName(min.instance.instanceId, filename);
|
||||||
|
@ -1213,19 +1204,15 @@ export class DialogKeywords {
|
||||||
if (!filename.startsWith('https://')) {
|
if (!filename.startsWith('https://')) {
|
||||||
url = urlJoin(GBServer.globals.publicAddress, 'kb', gbaiName, 'assets', filename);
|
url = urlJoin(GBServer.globals.publicAddress, 'kb', gbaiName, 'assets', filename);
|
||||||
} else {
|
} else {
|
||||||
url = filename
|
url = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
nameOnly = filename;
|
nameOnly = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url) {
|
if (!url) {
|
||||||
const reply = { type: ActivityTypes.Message, text: caption };
|
|
||||||
|
|
||||||
const imageData = await (await fetch(url)).arrayBuffer();
|
const imageData = await (await fetch(url)).arrayBuffer();
|
||||||
const contentType = mime.lookup(url);
|
const ext = mime.extension(Path.extname(filename.localName));
|
||||||
const ext = mime.extension( Path.extname(filename.localName));
|
|
||||||
reply['attachments'] = [];
|
|
||||||
|
|
||||||
// Prepare a cache to be referenced by Bot Framework.
|
// Prepare a cache to be referenced by Bot Framework.
|
||||||
|
|
||||||
|
@ -1234,18 +1221,21 @@ export class DialogKeywords {
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.${ext}`);
|
const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.${ext}`);
|
||||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
|
}
|
||||||
|
|
||||||
reply['attachments'].push({
|
const contentType = mime.lookup(url);
|
||||||
name: nameOnly,
|
const reply = { type: ActivityTypes.Message, text: caption };
|
||||||
contentType: contentType,
|
reply['attachments'] = [];
|
||||||
contentUrl: url
|
reply['attachments'].push({
|
||||||
});
|
name: nameOnly,
|
||||||
|
contentType: contentType,
|
||||||
|
contentUrl: url
|
||||||
|
});
|
||||||
|
|
||||||
if (channel === 'omnichannel') {
|
if (channel === 'omnichannel') {
|
||||||
await min.conversationalService.sendFile(min, null, mobile, url, caption);
|
await min.conversationalService.sendFile(min, null, mobile, url, caption);
|
||||||
} else {
|
} else {
|
||||||
await min.conversationalService['sendOnConversation'](min, user, reply);
|
await min.conversationalService['sendOnConversation'](min, user, reply);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue