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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -579,9 +576,7 @@ export class DialogKeywords {
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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('/')))
|
|
||||||
, matchesNonPadded = (d&&(str==[d.getDate(),d.getMonth()+1,d.getFullYear()].join('/')));
|
|
||||||
return (matchesPadded || matchesNonPadded) ? d : null;
|
|
||||||
}
|
}
|
||||||
|
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);
|
let value = parseDate(answer);
|
||||||
|
|
||||||
|
@ -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,7 +1221,11 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentType = mime.lookup(url);
|
||||||
|
const reply = { type: ActivityTypes.Message, text: caption };
|
||||||
|
reply['attachments'] = [];
|
||||||
reply['attachments'].push({
|
reply['attachments'].push({
|
||||||
name: nameOnly,
|
name: nameOnly,
|
||||||
contentType: contentType,
|
contentType: contentType,
|
||||||
|
@ -1247,7 +1238,6 @@ export class DialogKeywords {
|
||||||
await min.conversationalService['sendOnConversation'](min, user, reply);
|
await min.conversationalService['sendOnConversation'](min, user, reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Generates a new QRCode.
|
* Generates a new QRCode.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue