new(all): Vm isolated working with IPC BASIC 3.0;
This commit is contained in:
parent
765b3eddbc
commit
a26d659e29
6 changed files with 124 additions and 160 deletions
|
@ -76,7 +76,7 @@ export class GBBasicPackage implements IGBPackage {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
public async loadBot(min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
const backendRouter = createServerRouter(`/api/v2/${min.botId}/dialog`, new DialogKeywords(min, null, null, null));
|
const backendRouter = createServerRouter(`/api/v2/${min.botId}/dialog`, new DialogKeywords(min, null, null));
|
||||||
app.use(backendRouter.routes());
|
app.use(backendRouter.routes());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { GBDialogStep, GBLog, GBMinInstance } from 'botlib';
|
import { GBLog, GBMinInstance } from 'botlib';
|
||||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
|
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
|
||||||
import { ChartServices } from './ChartServices';
|
import { ChartServices } from './ChartServices';
|
||||||
const urlJoin = require('url-join');
|
const urlJoin = require('url-join');
|
||||||
|
@ -51,6 +51,7 @@ import { Messages } from '../strings';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||||
|
import { GuaribasUser } from '../../security.gbapp/models';
|
||||||
|
|
||||||
|
|
||||||
const DateDiff = require('date-diff');
|
const DateDiff = require('date-diff');
|
||||||
|
@ -64,8 +65,7 @@ var mammoth = require("mammoth");
|
||||||
const qrcode = require('qrcode');
|
const qrcode = require('qrcode');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base services of conversation to be called by BASIC which
|
* Base services of conversation to be called by BASIC.
|
||||||
* requries step variable to work.
|
|
||||||
*/
|
*/
|
||||||
export class DialogKeywords {
|
export class DialogKeywords {
|
||||||
|
|
||||||
|
@ -94,8 +94,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
hrOn: string;
|
hrOn: string;
|
||||||
|
|
||||||
step: GBDialogStep;
|
userId: GuaribasUser;
|
||||||
|
|
||||||
debugWeb: boolean;
|
debugWeb: boolean;
|
||||||
lastDebugWeb: Date;
|
lastDebugWeb: Date;
|
||||||
|
|
||||||
|
@ -112,20 +111,14 @@ export class DialogKeywords {
|
||||||
return this.min;
|
return this.min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getStep() {
|
|
||||||
return this.step;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When creating this keyword facade, a bot instance is
|
* When creating this keyword facade, a bot instance is
|
||||||
* specified among the deployer service.
|
* specified among the deployer service.
|
||||||
*/
|
*/
|
||||||
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep, user) {
|
constructor(min: GBMinInstance, deployer: GBDeployer, user) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.internalSys = new SystemKeywords(min, deployer, this);
|
this.internalSys = new SystemKeywords(min, deployer, this);
|
||||||
this.step = step;
|
|
||||||
|
|
||||||
this.debugWeb = this.min.core.getParam<boolean>(
|
this.debugWeb = this.min.core.getParam<boolean>(
|
||||||
this.min.instance,
|
this.min.instance,
|
||||||
|
@ -148,7 +141,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example x = GET PAGE
|
* @example x = GET PAGE
|
||||||
*/
|
*/
|
||||||
public async getPage(step, url, username, password) {
|
public async getPage(url, username, password) {
|
||||||
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
|
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
|
||||||
if (!this.browser) {
|
if (!this.browser) {
|
||||||
this.browser = await createBrowser(null);
|
this.browser = await createBrowser(null);
|
||||||
|
@ -161,7 +154,6 @@ export class DialogKeywords {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -175,7 +167,7 @@ export class DialogKeywords {
|
||||||
* @param legends
|
* @param legends
|
||||||
* @see https://www.npmjs.com/package/plot
|
* @see https://www.npmjs.com/package/plot
|
||||||
*/
|
*/
|
||||||
public async chart(step, type, data, legends, transpose) {
|
public async chart(type, data, legends, transpose) {
|
||||||
|
|
||||||
let table = [[]];
|
let table = [[]];
|
||||||
|
|
||||||
|
@ -298,7 +290,7 @@ export class DialogKeywords {
|
||||||
/**
|
/**
|
||||||
* Simulates a mouse hover an web page element.
|
* Simulates a mouse hover an web page element.
|
||||||
*/
|
*/
|
||||||
public async hover(step, page, idOrName) {
|
public async hover(page, idOrName) {
|
||||||
GBLog.info(`BASIC: Web Automation HOVER element: ${idOrName}.`);
|
GBLog.info(`BASIC: Web Automation HOVER element: ${idOrName}.`);
|
||||||
await this.getBySelector(page, idOrName);
|
await this.getBySelector(page, idOrName);
|
||||||
await page.hover(idOrName);
|
await page.hover(idOrName);
|
||||||
|
@ -310,7 +302,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example CLICK page, "#idElement"
|
* @example CLICK page, "#idElement"
|
||||||
*/
|
*/
|
||||||
public async click(step, page, frameOrSelector, selector) {
|
public async click(page, frameOrSelector, selector) {
|
||||||
GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
|
GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
|
||||||
if (selector) {
|
if (selector) {
|
||||||
await page.waitForSelector(frameOrSelector)
|
await page.waitForSelector(frameOrSelector)
|
||||||
|
@ -336,7 +328,7 @@ export class DialogKeywords {
|
||||||
if (this.debugWeb && refresh) {
|
if (this.debugWeb && refresh) {
|
||||||
const adminNumber = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null);
|
const adminNumber = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null);
|
||||||
if (adminNumber) {
|
if (adminNumber) {
|
||||||
await this.sendFileTo(this.step, adminNumber, page, "General Bots Debugger");
|
await this.sendFileTo(adminNumber, page, "General Bots Debugger");
|
||||||
}
|
}
|
||||||
this.lastDebugWeb = new Date();
|
this.lastDebugWeb = new Date();
|
||||||
}
|
}
|
||||||
|
@ -347,7 +339,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example PRESS ENTER ON page
|
* @example PRESS ENTER ON page
|
||||||
*/
|
*/
|
||||||
public async pressKey(step, page, char, frame) {
|
public async pressKey(page, char, frame) {
|
||||||
GBLog.info(`BASIC: Web Automation PRESS ${char} ON element: ${frame}.`);
|
GBLog.info(`BASIC: Web Automation PRESS ${char} ON element: ${frame}.`);
|
||||||
if (char.toLowerCase() === "enter") {
|
if (char.toLowerCase() === "enter") {
|
||||||
char = '\n';
|
char = '\n';
|
||||||
|
@ -363,7 +355,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async linkByText(step, page, text, index) {
|
public async linkByText(page, text, index) {
|
||||||
GBLog.info(`BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`);
|
GBLog.info(`BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`);
|
||||||
if (!index) {
|
if (!index) {
|
||||||
index = 1
|
index = 1
|
||||||
|
@ -380,7 +372,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example file = SCREENSHOT page
|
* @example file = SCREENSHOT page
|
||||||
*/
|
*/
|
||||||
public async screenshot(step, page, idOrName) {
|
public async screenshot(page, idOrName) {
|
||||||
GBLog.info(`BASIC: Web Automation SCREENSHOT ${idOrName}.`);
|
GBLog.info(`BASIC: Web Automation SCREENSHOT ${idOrName}.`);
|
||||||
|
|
||||||
const gbaiName = `${this.min.botId}.gbai`;
|
const gbaiName = `${this.min.botId}.gbai`;
|
||||||
|
@ -405,7 +397,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example SET page, "elementName", "text"
|
* @example SET page, "elementName", "text"
|
||||||
*/
|
*/
|
||||||
public async setElementText(step, page, idOrName, text) {
|
public async setElementText(page, idOrName, text) {
|
||||||
GBLog.info(`BASIC: Web Automation TYPE on ${idOrName}: ${text}.`);
|
GBLog.info(`BASIC: Web Automation TYPE on ${idOrName}: ${text}.`);
|
||||||
const e = await this.getBySelector(page, idOrName);
|
const e = await this.getBySelector(page, idOrName);
|
||||||
await e.click({ clickCount: 3 });
|
await e.click({ clickCount: 3 });
|
||||||
|
@ -419,7 +411,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example x = TODAY
|
* @example x = TODAY
|
||||||
*/
|
*/
|
||||||
public async getOCR(step, localFile) {
|
public async getOCR(localFile) {
|
||||||
GBLog.info(`BASIC: OCR processing on ${localFile}.`);
|
GBLog.info(`BASIC: OCR processing on ${localFile}.`);
|
||||||
const tesseract = require("node-tesseract-ocr")
|
const tesseract = require("node-tesseract-ocr")
|
||||||
|
|
||||||
|
@ -469,8 +461,8 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example EXIT
|
* @example EXIT
|
||||||
*/
|
*/
|
||||||
public async exit(step) {
|
public async exit() {
|
||||||
await step.endDialog();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -741,9 +733,9 @@ export class DialogKeywords {
|
||||||
* @example SEND FILE TO "+199988887777", "image.jpg", caption
|
* @example SEND FILE TO "+199988887777", "image.jpg", caption
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async sendFileTo(step, mobile, filename, caption) {
|
public async sendFileTo(mobile, filename, caption) {
|
||||||
GBLog.info(`BASIC: SEND FILE TO '${mobile}', filename '${filename}'.`);
|
GBLog.info(`BASIC: SEND FILE TO '${mobile}', filename '${filename}'.`);
|
||||||
return await this.internalSendFile(null, mobile, filename, caption);
|
return await this.internalSendFile(mobile, filename, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,10 +744,10 @@ export class DialogKeywords {
|
||||||
* @example SEND FILE "image.jpg"
|
* @example SEND FILE "image.jpg"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async sendFile(step, filename, caption) {
|
public async sendFile(filename, caption) {
|
||||||
const mobile = await this.userMobile(step);
|
const mobile = await this.userMobile();
|
||||||
GBLog.info(`BASIC: SEND FILE (current: ${mobile}, filename '${filename}'.`);
|
GBLog.info(`BASIC: SEND FILE (current: ${mobile}, filename '${filename}'.`);
|
||||||
return await this.internalSendFile(step, mobile, filename, caption);
|
return await this.internalSendFile(mobile, filename, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -764,14 +756,9 @@ export class DialogKeywords {
|
||||||
* @example SET LANGUAGE "pt"
|
* @example SET LANGUAGE "pt"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setLanguage(step, language) {
|
public async setLanguage(language) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
|
||||||
|
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
user.systemUser = await sec.updateUserLocale(user.systemUser.userId, language);
|
await sec.updateUserLocale(this.user.userId, language);
|
||||||
|
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -791,12 +778,9 @@ export class DialogKeywords {
|
||||||
* @example SET MAX LINES 5000
|
* @example SET MAX LINES 5000
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setMaxLines(step, count) {
|
public async setMaxLines(count) {
|
||||||
if (step) {
|
if (this.user) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
// TODO: PARAM user.basicOptions.maxLines = count;
|
||||||
user.basicOptions.maxLines = count;
|
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.maxLines = count;
|
this.maxLines = count;
|
||||||
|
@ -810,11 +794,9 @@ export class DialogKeywords {
|
||||||
* @example SET MAX COLUMNS 5000
|
* @example SET MAX COLUMNS 5000
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setMaxColumns(step, count) {
|
public async setMaxColumns(count) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
// TODO: user.basicOptions.maxColumns = count;
|
||||||
user.basicOptions.maxColumns = count;
|
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -824,11 +806,8 @@ export class DialogKeywords {
|
||||||
* @example SET WHOLE WORD ON
|
* @example SET WHOLE WORD ON
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setWholeWord(step, on) {
|
public async setWholeWord(on) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
// TODO: user.basicOptions.wholeWord = (on.trim() === "on");
|
||||||
user.basicOptions.wholeWord = (on.trim() === "on");
|
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -837,11 +816,8 @@ export class DialogKeywords {
|
||||||
* @example SET THEME "themename"
|
* @example SET THEME "themename"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setTheme(step, theme) {
|
public async setTheme(theme) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
// TODO: user.basicOptions.theme = theme.trim();
|
||||||
user.basicOptions.theme = theme.trim();
|
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -850,37 +826,24 @@ export class DialogKeywords {
|
||||||
* @example SET TRANSLATOR ON | OFF
|
* @example SET TRANSLATOR ON | OFF
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setTranslatorOn(step, on) {
|
public async setTranslatorOn(on) {
|
||||||
const user = await this.min.userProfile.get(step.context, {});
|
|
||||||
user.basicOptions.translatorOn = (on.trim() === "on");
|
// TODO: user.basicOptions.translatorOn = (on.trim() === "on");
|
||||||
await this.min.userProfile.set(step.context, user);
|
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the user acquired by WhatsApp API.
|
* Returns the name of the user acquired by WhatsApp API.
|
||||||
*/
|
*/
|
||||||
public async userName(step) {
|
public async userName() {
|
||||||
return step ? WhatsappDirectLine.usernames[await this.userMobile(step)] : 'N/A';
|
// TODO: WhatsappDirectLine.usernames[await this.userMobile()] : 'N/A';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* OBSOLETE.
|
|
||||||
*/
|
|
||||||
public async getFrom(step) {
|
|
||||||
return step ? await this.userMobile(step) : 'N/A';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current mobile number from user in conversation.
|
* Returns current mobile number from user in conversation.
|
||||||
*
|
|
||||||
* @example SAVE "file.xlsx", name, email, MOBILE
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public async userMobile(step) {
|
public async userMobile() {
|
||||||
return GBMinService.userMobile(step);
|
// TODO: return GBMinService.userMobile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -889,8 +852,8 @@ export class DialogKeywords {
|
||||||
* @example MENU
|
* @example MENU
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async showMenu(step) {
|
public async showMenu() {
|
||||||
return await step.beginDialog('/menu');
|
// TODO: return await beginDialog('/menu');
|
||||||
}
|
}
|
||||||
private static async downloadAttachmentAndWrite(attachment) {
|
private static async downloadAttachmentAndWrite(attachment) {
|
||||||
|
|
||||||
|
@ -942,8 +905,8 @@ export class DialogKeywords {
|
||||||
* @example TRANSFER
|
* @example TRANSFER
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async transferTo(step, to: string = null) {
|
public async transferTo(to: string = null) {
|
||||||
return await step.beginDialog('/t', { to: to });
|
// TODO: return await beginDialog('/t', { to: to });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -952,7 +915,7 @@ export class DialogKeywords {
|
||||||
* @example HEAR name
|
* @example HEAR name
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async hear(step, kind, ...args) {
|
public async hear(kind, ...args) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -992,7 +955,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
GBLog.info('BASIC: HEAR (Asking for input).');
|
GBLog.info('BASIC: HEAR (Asking for input).');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the user to answer.
|
// Wait for the user to answer.
|
||||||
|
|
||||||
let sleep = ms => {
|
let sleep = ms => {
|
||||||
|
@ -1010,32 +973,32 @@ export class DialogKeywords {
|
||||||
const text = this.min.cbMap[userId].promise;
|
const text = this.min.cbMap[userId].promise;
|
||||||
|
|
||||||
if (kind === "file") {
|
if (kind === "file") {
|
||||||
await step.prompt('attachmentPrompt', {});
|
// await prompt('attachmentPrompt', {});
|
||||||
|
|
||||||
// Prepare Promises to download each attachment and then execute each Promise.
|
// // Prepare Promises to download each attachment and then execute each Promise.
|
||||||
const promises = step.context.activity.attachments.map(
|
// const promises = step.context.activity.attachments.map(
|
||||||
DialogKeywords.downloadAttachmentAndWrite);
|
// DialogKeywords.downloadAttachmentAndWrite);
|
||||||
const successfulSaves = await Promise.all(promises);
|
// const successfulSaves = await Promise.all(promises);
|
||||||
|
|
||||||
async function replyForReceivedAttachments(localAttachmentData) {
|
// async function replyForReceivedAttachments(localAttachmentData) {
|
||||||
if (localAttachmentData) {
|
// if (localAttachmentData) {
|
||||||
// Because the TurnContext was bound to this function, the bot can call
|
// // Because the TurnContext was bound to this function, the bot can call
|
||||||
// `TurnContext.sendActivity` via `this.sendActivity`;
|
// // `TurnContext.sendActivity` via `this.sendActivity`;
|
||||||
await this.sendActivity(`Upload OK.`);
|
// await this.sendActivity(`Upload OK.`);
|
||||||
} else {
|
// } else {
|
||||||
await this.sendActivity('Error uploading file. Please, start again.');
|
// await this.sendActivity('Error uploading file. Please, start again.');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Prepare Promises to reply to the user with information about saved attachments.
|
// // Prepare Promises to reply to the user with information about saved attachments.
|
||||||
// The current TurnContext is bound so `replyForReceivedAttachments` can also send replies.
|
// // The current TurnContext is bound so `replyForReceivedAttachments` can also send replies.
|
||||||
const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context));
|
// const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context));
|
||||||
await Promise.all(replyPromises);
|
// await Promise.all(replyPromises);
|
||||||
|
|
||||||
result = {
|
// result = {
|
||||||
data: fs.readFileSync(successfulSaves[0]['localPath']),
|
// data: fs.readFileSync(successfulSaves[0]['localPath']),
|
||||||
filename: successfulSaves[0]['fileName']
|
// filename: successfulSaves[0]['fileName']
|
||||||
};
|
// };
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (kind === "boolean") {
|
else if (kind === "boolean") {
|
||||||
|
@ -1056,7 +1019,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
await this.talk("Por favor, digite um e-mail válido.");
|
await this.talk("Por favor, digite um e-mail válido.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
|
@ -1071,7 +1034,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite um nome válido.");
|
await this.talk("Por favor, digite um nome válido.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
|
@ -1086,7 +1049,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite um número válido.");
|
await this.talk("Por favor, digite um número válido.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
|
@ -1100,7 +1063,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite uma data no formato 12/12/2020.");
|
await this.talk("Por favor, digite uma data no formato 12/12/2020.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
|
@ -1115,7 +1078,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite um horário no formato hh:ss.");
|
await this.talk("Por favor, digite um horário no formato hh:ss.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
|
@ -1123,25 +1086,26 @@ export class DialogKeywords {
|
||||||
else if (kind === "money") {
|
else if (kind === "money") {
|
||||||
const extractEntity = text => {
|
const extractEntity = text => {
|
||||||
|
|
||||||
if (step.context.locale === 'en') { // TODO: Change to user.
|
// if (user.locale === 'en') { // TODO: Change to user.
|
||||||
return text.match(/(?:\d{1,3},)*\d{1,3}(?:\.\d+)?/gi);
|
// return text.match(/(?:\d{1,3},)*\d{1,3}(?:\.\d+)?/gi);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
return text.match(/(?:\d{1,3}.)*\d{1,3}(?:\,\d+)?/gi);
|
// return text.match(/(?:\d{1,3}.)*\d{1,3}(?:\,\d+)?/gi);
|
||||||
}
|
// }
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(text);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite um valor monetário.");
|
await this.talk("Por favor, digite um valor monetário.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
}
|
}
|
||||||
else if (kind === "mobile") {
|
else if (kind === "mobile") {
|
||||||
const locale = step.context.activity.locale;
|
|
||||||
let phoneNumber;
|
let phoneNumber;
|
||||||
try {
|
try {
|
||||||
phoneNumber = phone(text, 'BRA')[0]; // TODO: Use accordingly to the person.
|
phoneNumber = phone(text, 'BRA')[0]; // TODO: Use accordingly to the person.
|
||||||
|
@ -1149,11 +1113,11 @@ export class DialogKeywords {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.talk(Messages[locale].validation_enter_valid_mobile);
|
await this.talk(Messages[locale].validation_enter_valid_mobile);
|
||||||
|
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
if (!phoneUtil.isPossibleNumber(phoneNumber)) {
|
if (!phoneUtil.isPossibleNumber(phoneNumber)) {
|
||||||
await this.talk("Por favor, digite um número de telefone válido.");
|
await this.talk("Por favor, digite um número de telefone válido.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = phoneNumber;
|
result = phoneNumber;
|
||||||
|
@ -1164,7 +1128,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
text = text.replace(/\-/gi, '');
|
text = text.replace(/\-/gi, '');
|
||||||
|
|
||||||
if (step.context.locale === 'en') { // TODO: Change to user.
|
if (user.locale === 'en') { // TODO: Change to user.
|
||||||
return text.match(/\d{8}/gi);
|
return text.match(/\d{8}/gi);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1177,7 +1141,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk("Por favor, digite um valor monetário.");
|
await this.talk("Por favor, digite um valor monetário.");
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = value[0];
|
result = value[0];
|
||||||
|
@ -1195,7 +1159,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (result === null) {
|
if (result === null) {
|
||||||
await this.talk(`Escolha por favor um dos itens sugeridos.`);
|
await this.talk(`Escolha por favor um dos itens sugeridos.`);
|
||||||
return await this.hear(step, kind, args);
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (kind === "language") {
|
else if (kind === "language") {
|
||||||
|
@ -1218,7 +1182,8 @@ export class DialogKeywords {
|
||||||
{ name: 'alemão', code: 'de' }
|
{ name: 'alemão', code: 'de' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const text = step.context.activity['originalText'];
|
|
||||||
|
// TODO: const text = step.context.activity['originalText'];
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(list, async item => {
|
await CollectionUtil.asyncForEach(list, async item => {
|
||||||
if (GBConversationalService.kmpSearch(text.toLowerCase(), item.name.toLowerCase()) != -1 ||
|
if (GBConversationalService.kmpSearch(text.toLowerCase(), item.name.toLowerCase()) != -1 ||
|
||||||
|
@ -1228,8 +1193,9 @@ export class DialogKeywords {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result === null) {
|
if (result === null) {
|
||||||
await this.min.conversationalService.sendText(this.min, step, `Escolha por favor um dos idiomas sugeridos.`);
|
// TODO:
|
||||||
return await this.hear(step, kind, args);
|
await this.min.conversationalService.sendText(this.min, null, `Escolha por favor um dos idiomas sugeridos.`);
|
||||||
|
return await this.hear(kind, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1241,10 +1207,10 @@ export class DialogKeywords {
|
||||||
/**
|
/**
|
||||||
* Prepares the next dialog to be shown to the specified user.
|
* Prepares the next dialog to be shown to the specified user.
|
||||||
*/
|
*/
|
||||||
public async gotoDialog(step, fromOrDialogName: string, dialogName: string) {
|
public async gotoDialog(fromOrDialogName: string, dialogName: string) {
|
||||||
if (dialogName) {
|
if (dialogName) {
|
||||||
if (dialogName.charAt(0) === '/') {
|
if (dialogName.charAt(0) === '/') {
|
||||||
await step.beginDialog(fromOrDialogName);
|
// TODO: await step.beginDialog(fromOrDialogName);
|
||||||
} else {
|
} else {
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let user = await sec.getUserFromSystemId(fromOrDialogName);
|
let user = await sec.getUserFromSystemId(fromOrDialogName);
|
||||||
|
@ -1256,7 +1222,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await step.beginDialog(fromOrDialogName);
|
// TODO: await step.beginDialog(fromOrDialogName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,31 +1232,24 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async talk(text: string) {
|
public async talk(text: string) {
|
||||||
GBLog.info(`BASIC: TALK '${text}'.`);
|
GBLog.info(`BASIC: TALK '${text}'.`);
|
||||||
const translate = this.user ? this.user.basicOptions.translatorOn : false;
|
if (this.user) {
|
||||||
// TODO: Translate.
|
const translate = this.user ? this.user.basicOptions.translatorOn : false;
|
||||||
|
|
||||||
|
await this.min.conversationalService['sendOnConversation'](this.min,
|
||||||
await this.min.conversationalService['sendOnConversation'](this.min,
|
this.user.systemUser, text);
|
||||||
this.user.systemUser, text);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getChannel(step): string {
|
private static getChannel(): string {
|
||||||
if (!step) return 'whatsapp';
|
return 'whatsapp';
|
||||||
if (!isNaN(step.context.activity['mobile'])) {
|
// TODO:
|
||||||
return 'webchat';
|
|
||||||
} else {
|
|
||||||
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
|
|
||||||
return 'w}, 0);hatsapp';
|
|
||||||
}
|
|
||||||
return 'webchat';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the sending of the file.
|
* Processes the sending of the file.
|
||||||
*/
|
*/
|
||||||
private async internalSendFile(step, mobile, filename, caption) {
|
private async internalSendFile(mobile, filename, caption) {
|
||||||
|
|
||||||
// Handles SEND FILE TO mobile, element in Web Automation.
|
// Handles SEND FILE TO mobile, element in Web Automation.
|
||||||
|
|
||||||
|
@ -1309,7 +1268,7 @@ export class DialogKeywords {
|
||||||
);
|
);
|
||||||
|
|
||||||
GBLog.info(`BASIC: WebAutomation: Sending the file ${url} to mobile ${mobile}.`);
|
GBLog.info(`BASIC: WebAutomation: Sending the file ${url} to mobile ${mobile}.`);
|
||||||
await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption);
|
await this.min.conversationalService.sendFile(this.min, null, mobile, url, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles Markdown.
|
// Handles Markdown.
|
||||||
|
@ -1322,7 +1281,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.min.conversationalService['playMarkdown'](this.min, md,
|
await this.min.conversationalService['playMarkdown'](this.min, md,
|
||||||
DialogKeywords.getChannel(step), step, mobile);
|
DialogKeywords.getChannel(), mobile);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
GBLog.info(`BASIC: Sending the file ${filename} to mobile ${mobile}.`);
|
GBLog.info(`BASIC: Sending the file ${filename} to mobile ${mobile}.`);
|
||||||
|
@ -1341,7 +1300,7 @@ export class DialogKeywords {
|
||||||
url = filename;
|
url = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption);
|
await this.min.conversationalService.sendFile(this.min, null, mobile, url, caption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -754,7 +754,7 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
const user = step ? await min.userProfile.get(step.context, {}) : null;
|
const user = step ? await min.userProfile.get(step.context, {}) : null;
|
||||||
|
|
||||||
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user);
|
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, user.systemUser);
|
||||||
|
|
||||||
const contentLocale = min.core.getParam<string>(
|
const contentLocale = min.core.getParam<string>(
|
||||||
min.instance,
|
min.instance,
|
||||||
|
@ -782,7 +782,7 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
let code = min.sandBoxMap[text];
|
let code = min.sandBoxMap[text];
|
||||||
|
|
||||||
if (process.env.VM3) {
|
if (GBConfigService.get('VM3')==='true'){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const vm1 = new NodeVM({
|
const vm1 = new NodeVM({
|
||||||
|
|
|
@ -92,7 +92,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async callVM(text: string, min: GBMinInstance, step: GBDialogStep, deployer: GBDeployer) {
|
public async callVM(text: string, min: GBMinInstance, step, deployer: GBDeployer) {
|
||||||
return await GBVMService.callVM(text, min, step, deployer);
|
return await GBVMService.callVM(text, min, step, deployer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,8 +465,8 @@ export class SystemKeywords {
|
||||||
|
|
||||||
if (file._javascriptEnabled) {
|
if (file._javascriptEnabled) {
|
||||||
GBLog.info(`BASIC: Web automation setting ${file}' to '${value}' (SET). `);
|
GBLog.info(`BASIC: Web automation setting ${file}' to '${value}' (SET). `);
|
||||||
|
await this.dk.setElementText(file, address, value);
|
||||||
await this.dk.setElementText(null, file, address, value);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1684,7 +1684,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async tweet(step, text: string) {
|
public async tweet(text: string) {
|
||||||
|
|
||||||
const consumer_key = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key', null);
|
const consumer_key = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key', null);
|
||||||
const consumer_secret = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key Secret', null);
|
const consumer_secret = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key Secret', null);
|
||||||
|
|
|
@ -2,7 +2,7 @@ const { VMScript, NodeVM } = require('vm2');
|
||||||
const crypto1 = require('crypto');
|
const crypto1 = require('crypto');
|
||||||
const net1 = require('net');
|
const net1 = require('net');
|
||||||
|
|
||||||
const evaluate = (script, scope) => {
|
const evaluate = async (script, scope) => {
|
||||||
const vm = new NodeVM({
|
const vm = new NodeVM({
|
||||||
allowAsync: true,
|
allowAsync: true,
|
||||||
sandbox: {},
|
sandbox: {},
|
||||||
|
@ -17,7 +17,7 @@ const evaluate = (script, scope) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const s = new VMScript(script, scope);
|
const s = new VMScript(script, scope);
|
||||||
return vm.run(script, scope);
|
return await vm.run(script, scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
const socketName = crypto1.randomBytes(20).toString('hex');
|
const socketName = crypto1.randomBytes(20).toString('hex');
|
||||||
|
@ -25,16 +25,18 @@ const socketName = crypto1.randomBytes(20).toString('hex');
|
||||||
const server = net1.createServer((socket) => {
|
const server = net1.createServer((socket) => {
|
||||||
const buffer = [];
|
const buffer = [];
|
||||||
|
|
||||||
const sync = () => {
|
const sync = async () => {
|
||||||
const request = buffer.join('').toString();
|
const request = buffer.join('').toString();
|
||||||
if (request.includes('\n')) {
|
if (request.includes('\n')) {
|
||||||
try {
|
try {
|
||||||
const { code, scope } = JSON.parse(request);
|
const { code, scope } = JSON.parse(request);
|
||||||
const result = evaluate(code, {
|
const result = await evaluate(code, {
|
||||||
...scope,
|
...scope,
|
||||||
module: null
|
module: null
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(JSON.stringify({ result }));
|
||||||
|
debugger;
|
||||||
socket.write(JSON.stringify({ result }) + '\n');
|
socket.write(JSON.stringify({ result }) + '\n');
|
||||||
socket.end();
|
socket.end();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -329,6 +329,9 @@ export class GBMinService {
|
||||||
|
|
||||||
// Test code.
|
// Test code.
|
||||||
if (process.env.TEST_MESSAGE) {
|
if (process.env.TEST_MESSAGE) {
|
||||||
|
|
||||||
|
GBLog.info(`Starting auto test with '${process.env.TEST_MESSAGE}'.`);
|
||||||
|
|
||||||
const client = await new Swagger({
|
const client = await new Swagger({
|
||||||
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')), usePromise: true
|
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')), usePromise: true
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue