fix(basic.gblib): Refactoring processInfo into all methods.
This commit is contained in:
parent
5166db205e
commit
50d3fccd0d
2 changed files with 38 additions and 22 deletions
|
@ -222,7 +222,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example x = TODAY
|
* @example x = TODAY
|
||||||
*/
|
*/
|
||||||
public async getToday({}) {
|
public async getToday({ }) {
|
||||||
let d = new Date(),
|
let d = new Date(),
|
||||||
month = '' + (d.getMonth() + 1),
|
month = '' + (d.getMonth() + 1),
|
||||||
day = '' + d.getDate(),
|
day = '' + d.getDate(),
|
||||||
|
@ -258,28 +258,28 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example EXIT
|
* @example EXIT
|
||||||
*/
|
*/
|
||||||
public async exit({}) {}
|
public async exit({ }) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get active tasks.
|
* Get active tasks.
|
||||||
*
|
*
|
||||||
* @example list = ACTIVE TASKS
|
* @example list = ACTIVE TASKS
|
||||||
*/
|
*/
|
||||||
public async getActiveTasks({ pid }) {}
|
public async getActiveTasks({ pid }) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new deal.
|
* Creates a new deal.
|
||||||
*
|
*
|
||||||
* @example CREATE DEAL dealname,contato,empresa,amount
|
* @example CREATE DEAL dealname,contato,empresa,amount
|
||||||
*/
|
*/
|
||||||
public async createDeal({ pid, dealName, contact, company, amount }) {}
|
public async createDeal({ pid, dealName, contact, company, amount }) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds contacts in XRM.
|
* Finds contacts in XRM.
|
||||||
*
|
*
|
||||||
* @example list = FIND CONTACT "Sandra"
|
* @example list = FIND CONTACT "Sandra"
|
||||||
*/
|
*/
|
||||||
public async fndContact({ pid, name }) {}
|
public async fndContact({ pid, name }) { }
|
||||||
|
|
||||||
public getContentLocaleWithCulture(contentLocale) {
|
public getContentLocaleWithCulture(contentLocale) {
|
||||||
switch (contentLocale) {
|
switch (contentLocale) {
|
||||||
|
@ -478,7 +478,7 @@ export class DialogKeywords {
|
||||||
* @example SAVE "contacts.xlsx", name, email, NOW
|
* @example SAVE "contacts.xlsx", name, email, NOW
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async getNow({}) {
|
public async getNow({ }) {
|
||||||
const contentLocale = this.min.core.getParam<string>(
|
const contentLocale = this.min.core.getParam<string>(
|
||||||
this.min.instance,
|
this.min.instance,
|
||||||
'Default Content Language',
|
'Default Content Language',
|
||||||
|
@ -656,14 +656,14 @@ export class DialogKeywords {
|
||||||
* @example MENU
|
* @example MENU
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async showMenu({}) {
|
public async showMenu({ }) {
|
||||||
// https://github.com/GeneralBots/BotServer/issues/237
|
// https://github.com/GeneralBots/BotServer/issues/237
|
||||||
// return await beginDialog('/menu');
|
// return await beginDialog('/menu');
|
||||||
}
|
}
|
||||||
private static async downloadAttachmentAndWrite(attachment) {
|
private static async downloadAttachmentAndWrite(attachment) {
|
||||||
const url = attachment.contentUrl;
|
const url = attachment.contentUrl;
|
||||||
// https://github.com/GeneralBots/BotServer/issues/195 - '${botId}','uploads');
|
// https://github.com/GeneralBots/BotServer/issues/195 - '${botId}','uploads');
|
||||||
const localFolder = Path.join('work');
|
const localFolder = Path.join('work');
|
||||||
const localFileName = Path.join(localFolder, attachment.name);
|
const localFileName = Path.join(localFolder, attachment.name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -719,8 +719,8 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async getHear({ pid, kind, arg }) {
|
public async getHear({ pid, kind, arg }) {
|
||||||
|
|
||||||
const process = GBServer.globals.processes[pid];
|
const process = GBServer.globals.processes[pid];
|
||||||
|
|
||||||
const min = GBServer.globals.minInstances.filter(p =>
|
const min = GBServer.globals.minInstances.filter(p =>
|
||||||
p.instance.instanceId == process.instanceId)[0];
|
p.instance.instanceId == process.instanceId)[0];
|
||||||
|
|
||||||
|
@ -736,13 +736,13 @@ export class DialogKeywords {
|
||||||
const isIntentYes = (locale, utterance) => {
|
const isIntentYes = (locale, utterance) => {
|
||||||
return utterance.toLowerCase().match(Messages[locale].affirmative_sentences);
|
return utterance.toLowerCase().match(Messages[locale].affirmative_sentences);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
|
|
||||||
if (this.hrOn) {
|
if (this.hrOn) {
|
||||||
user = await sec.getUserFromAgentSystemId(this.hrOn);
|
user = await sec.getUserFromAgentSystemId(this.hrOn);
|
||||||
} else {
|
} else {
|
||||||
user = await sec.getUserFromId (process.instanceId, process.userId);
|
user = await sec.getUserFromId(process.instanceId, process.userId);
|
||||||
}
|
}
|
||||||
const userId = user.userId;
|
const userId = user.userId;
|
||||||
let result;
|
let result;
|
||||||
|
@ -767,7 +767,7 @@ export class DialogKeywords {
|
||||||
// 'Please select a product'
|
// 'Please select a product'
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
// let i = 0;
|
// let i = 0;
|
||||||
// await CollectionUtil.asyncForEach(args, async arg => {
|
// await CollectionUtil.asyncForEach(args, async arg => {
|
||||||
// i++;
|
// i++;
|
||||||
|
@ -899,7 +899,7 @@ export class DialogKeywords {
|
||||||
} else if (kind === 'money') {
|
} else if (kind === 'money') {
|
||||||
const extractEntity = text => {
|
const extractEntity = text => {
|
||||||
// https://github.com/GeneralBots/BotServer/issues/307
|
// https://github.com/GeneralBots/BotServer/issues/307
|
||||||
if (user.locale === 'en') {
|
if (user.locale === 'en') {
|
||||||
return text.match(/(?:\d{1,3},)*\d{1,3}(?:\.\d+)?/gi);
|
return text.match(/(?:\d{1,3},)*\d{1,3}(?:\.\d+)?/gi);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -920,7 +920,7 @@ export class DialogKeywords {
|
||||||
let phoneNumber;
|
let phoneNumber;
|
||||||
try {
|
try {
|
||||||
// https://github.com/GeneralBots/BotServer/issues/307
|
// https://github.com/GeneralBots/BotServer/issues/307
|
||||||
phoneNumber = phone(text, { country: 'BRA' })[0];
|
phoneNumber = phone(text, { country: 'BRA' })[0];
|
||||||
phoneNumber = phoneUtil.parse(phoneNumber);
|
phoneNumber = phoneUtil.parse(phoneNumber);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.talk(Messages[locale].validation_enter_valid_mobile);
|
await this.talk(Messages[locale].validation_enter_valid_mobile);
|
||||||
|
@ -1035,15 +1035,31 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getProcessInfo(pid: number) {
|
||||||
|
const proc = GBServer.globals.processes[pid];
|
||||||
|
|
||||||
|
const min = GBServer.globals.minInstances.filter(p =>
|
||||||
|
p.instance.instanceId == proc.instanceId)[0];
|
||||||
|
const sec = new SecService();
|
||||||
|
const user = await sec.getUserFromId(min.instance.instanceId, proc.userId);
|
||||||
|
return {
|
||||||
|
min, user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Talks to the user by using the specified text.
|
* Talks to the user by using the specified text.
|
||||||
*/
|
*/
|
||||||
public async talk({ pid, text }) {
|
public async talk({ pid, text }) {
|
||||||
GBLog.info(`BASIC: TALK '${text}'.`);
|
GBLog.info(`BASIC: TALK '${text}'.`);
|
||||||
if (this.user) {
|
const {
|
||||||
const translate = this.user ? this.user.basicOptions.translatorOn : false;
|
min, user
|
||||||
|
} = await this.getProcessInfo(pid);
|
||||||
|
if (user) {
|
||||||
|
// TODO: const translate = this.user ? this.user.basicOptions.translatorOn : false;
|
||||||
|
|
||||||
await this.min.conversationalService['sendOnConversation'](this.min, this.user.systemUser, text);
|
await min.conversationalService['sendOnConversation'](min, user, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,11 +104,11 @@ export class GBDeployer implements IGBDeployer {
|
||||||
* Retrives token and initialize drive client API.
|
* Retrives token and initialize drive client API.
|
||||||
*/
|
*/
|
||||||
public static async internalGetDriveClient (min: GBMinInstance) {
|
public static async internalGetDriveClient (min: GBMinInstance) {
|
||||||
let token = await min.adminService.acquireElevatedToken(min.instance.instanceId);
|
const token = await min.adminService.acquireElevatedToken(min.instance.instanceId);
|
||||||
let siteId = process.env.STORAGE_SITE_ID;
|
const siteId = process.env.STORAGE_SITE_ID;
|
||||||
let libraryId = process.env.STORAGE_LIBRARY;
|
const libraryId = process.env.STORAGE_LIBRARY;
|
||||||
|
|
||||||
let client = MicrosoftGraph.Client.init({
|
const client = MicrosoftGraph.Client.init({
|
||||||
authProvider: done => {
|
authProvider: done => {
|
||||||
done(null, token);
|
done(null, token);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue