fix(basic.gblib): Refactoring processInfo into all methods.

This commit is contained in:
Daniel Lima 2023-01-17 11:03:25 -03:00
parent 5166db205e
commit 50d3fccd0d
2 changed files with 38 additions and 22 deletions

View file

@ -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,7 +656,7 @@ 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');
} }
@ -742,7 +742,7 @@ export class DialogKeywords {
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;
@ -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);
} }
} }

View file

@ -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);
} }