new(core.gbapp): GET/POST for .gbdialog.
This commit is contained in:
parent
bf71d7f748
commit
dec76af1b9
5 changed files with 251 additions and 151 deletions
|
@ -40,8 +40,8 @@ import urlJoin = require('url-join');
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||||
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService';
|
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService';
|
||||||
import { GBDeployer } from './GBDeployer';
|
import { GBDeployer } from './GBDeployer';
|
||||||
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
|
const MicrosoftGraph = require('@microsoft/microsoft-graph-client');
|
||||||
import { Messages } from "../strings";
|
import { Messages } from '../strings';
|
||||||
import { GBServer } from '../../../src/app';
|
import { GBServer } from '../../../src/app';
|
||||||
const request = require('request-promise-native');
|
const request = require('request-promise-native');
|
||||||
|
|
||||||
|
@ -95,10 +95,10 @@ class SysClass {
|
||||||
await timeout(seconds * 1000);
|
await timeout(seconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async save(file: string, ...args): Promise<any> {
|
|
||||||
|
public async set(file: string, address:string, value: any): Promise<any> {
|
||||||
try {
|
try {
|
||||||
let token =
|
let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
|
||||||
|
|
||||||
let siteId = process.env.STORAGE_SITE_ID;
|
let siteId = process.env.STORAGE_SITE_ID;
|
||||||
let libraryId = process.env.STORAGE_LIBRARY;
|
let libraryId = process.env.STORAGE_LIBRARY;
|
||||||
|
@ -111,16 +111,59 @@ class SysClass {
|
||||||
const botId = this.min.instance.botId;
|
const botId = this.min.instance.botId;
|
||||||
const path = `/${botId}.gbai/${botId}.gbdata`;
|
const path = `/${botId}.gbai/${botId}.gbdata`;
|
||||||
|
|
||||||
let res = await client.api(
|
let res = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
.api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
let document = res.value.filter(m => {
|
let document = res.value.filter(m => {
|
||||||
return m.name === file
|
return m.name === file;
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.api(
|
if (document === undefined) {
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert`)
|
throw `File '${file}' specified on save GBasic command SET not found. Check the .gbdata or the .gbdialog associated.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let body = { values: [[]] };
|
||||||
|
body.values[0][0] = value;
|
||||||
|
|
||||||
|
let res2 = await client
|
||||||
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='${address}')`
|
||||||
|
)
|
||||||
|
.patch(body);
|
||||||
|
} catch (error) {
|
||||||
|
GBLog.error(`SAVE BASIC error: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async save(file: string, ...args): Promise<any> {
|
||||||
|
try {
|
||||||
|
let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||||
|
|
||||||
|
let siteId = process.env.STORAGE_SITE_ID;
|
||||||
|
let libraryId = process.env.STORAGE_LIBRARY;
|
||||||
|
|
||||||
|
let client = MicrosoftGraph.Client.init({
|
||||||
|
authProvider: done => {
|
||||||
|
done(null, token);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const botId = this.min.instance.botId;
|
||||||
|
const path = `/${botId}.gbai/${botId}.gbdata`;
|
||||||
|
|
||||||
|
let res = await client
|
||||||
|
.api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
let document = res.value.filter(m => {
|
||||||
|
return m.name === file;
|
||||||
|
});
|
||||||
|
|
||||||
|
await client
|
||||||
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert`
|
||||||
|
)
|
||||||
.post({});
|
.post({});
|
||||||
|
|
||||||
if (document === undefined) {
|
if (document === undefined) {
|
||||||
|
@ -130,27 +173,25 @@ class SysClass {
|
||||||
throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`;
|
throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body =
|
let body = { values: [[]] };
|
||||||
{ "values": [[]] };
|
|
||||||
|
|
||||||
for (let index = 0; index < 26; index++) {
|
for (let index = 0; index < 26; index++) {
|
||||||
body.values[0][index] = args[index];
|
body.values[0][index] = args[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
let res2 = await client.api(
|
let res2 = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')`)
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')`
|
||||||
|
)
|
||||||
.patch(body);
|
.patch(body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`SAVE BASIC error: ${error.message}`);
|
GBLog.error(`SAVE BASIC error: ${error.message}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async find(file: string, ...args): Promise<any> {
|
public async get(file: string, address: string): Promise<any> {
|
||||||
|
let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||||
let token =
|
|
||||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
|
||||||
|
|
||||||
let client = MicrosoftGraph.Client.init({
|
let client = MicrosoftGraph.Client.init({
|
||||||
authProvider: done => {
|
authProvider: done => {
|
||||||
|
@ -163,15 +204,55 @@ class SysClass {
|
||||||
const path = `/${botId}.gbai/${botId}.gbdata`;
|
const path = `/${botId}.gbai/${botId}.gbdata`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res = await client.api(
|
let res = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
.api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
|
||||||
// Performs validation.
|
// Performs validation.
|
||||||
|
|
||||||
let document = res.value.filter(m => {
|
let document = res.value.filter(m => {
|
||||||
return m.name === file
|
return m.name === file;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (document === undefined) {
|
||||||
|
throw `File '${file}' specified on save GBasic command GET not found. Check the .gbdata or the .gbdialog associated.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates workbook session that will be discarded.
|
||||||
|
|
||||||
|
let results = await client
|
||||||
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='${address}')`
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
return results.text[0][0];
|
||||||
|
} catch (error) {
|
||||||
|
GBLog.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async find(file: string, ...args): Promise<any> {
|
||||||
|
let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||||
|
|
||||||
|
let client = MicrosoftGraph.Client.init({
|
||||||
|
authProvider: done => {
|
||||||
|
done(null, token);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let siteId = process.env.STORAGE_SITE_ID;
|
||||||
|
let libraryId = process.env.STORAGE_LIBRARY;
|
||||||
|
const botId = this.min.instance.botId;
|
||||||
|
const path = `/${botId}.gbai/${botId}.gbdata`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let res = await client
|
||||||
|
.api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// Performs validation.
|
||||||
|
|
||||||
|
let document = res.value.filter(m => {
|
||||||
|
return m.name === file;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (document === undefined) {
|
if (document === undefined) {
|
||||||
|
@ -186,8 +267,10 @@ class SysClass {
|
||||||
const filter = args[0].split('=');
|
const filter = args[0].split('=');
|
||||||
const columnName = filter[0];
|
const columnName = filter[0];
|
||||||
const value = filter[1];
|
const value = filter[1];
|
||||||
let results = await client.api(
|
let results = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z100')`)
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z100')`
|
||||||
|
)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
let columnIndex = 0;
|
let columnIndex = 0;
|
||||||
|
@ -206,8 +289,7 @@ class SysClass {
|
||||||
}
|
}
|
||||||
if (foundIndex === results.text.length) {
|
if (foundIndex === results.text.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
let output = {};
|
let output = {};
|
||||||
const row = results.text[foundIndex];
|
const row = results.text[foundIndex];
|
||||||
for (let colIndex = 0; colIndex < row.length; colIndex++) {
|
for (let colIndex = 0; colIndex < row.length; colIndex++) {
|
||||||
|
@ -258,26 +340,40 @@ class SysClass {
|
||||||
/**
|
/**
|
||||||
* Generic function to call any REST API.
|
* Generic function to call any REST API.
|
||||||
*/
|
*/
|
||||||
public async httpGet(url: string, qs) {
|
public async httpGet(url: string) {
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
uri: urlJoin(url, qs)
|
uri: url
|
||||||
};
|
};
|
||||||
|
|
||||||
return await request.get(options);
|
let result = await request.get(options);
|
||||||
|
GBLog.info(`[GET]: ${url} : ${result}`);
|
||||||
|
return JSON.parse(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic function to call any REST API by POST.
|
||||||
|
*/
|
||||||
|
public async httpPost(url: string, data) {
|
||||||
|
const options = {
|
||||||
|
uri: url,
|
||||||
|
json: true,
|
||||||
|
body: data
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = await request.post(options);
|
||||||
|
GBLog.info(`[POST]: ${url} (${data}): ${result}`);
|
||||||
|
return JSON.parse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async numberOnly(text: string) {
|
public async numberOnly(text: string) {
|
||||||
return text.replace(/\D/gi, "");
|
return text.replace(/\D/gi, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base services of conversation to be called by BASIC.
|
* Base services of conversation to be called by BASIC.
|
||||||
*/
|
*/
|
||||||
export class DialogClass {
|
export class DialogClass {
|
||||||
|
|
||||||
public min: GBMinInstance;
|
public min: GBMinInstance;
|
||||||
public context: TurnContext;
|
public context: TurnContext;
|
||||||
public step: WaterfallStepContext;
|
public step: WaterfallStepContext;
|
||||||
|
@ -289,49 +385,47 @@ export class DialogClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static setup(bot: BotAdapter, min: GBMinInstance) {
|
public static setup(bot: BotAdapter, min: GBMinInstance) {
|
||||||
min.dialogs.add(new WaterfallDialog('/gbasic-email', [
|
min.dialogs.add(
|
||||||
|
new WaterfallDialog('/gbasic-email', [
|
||||||
async step => {
|
async step => {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
if ((step.options as any).ask) {
|
if ((step.options as any).ask) {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].whats_email);
|
await min.conversationalService.sendText(min, step, Messages[locale].whats_email);
|
||||||
}
|
}
|
||||||
return await step.prompt("textPrompt", {});
|
return await step.prompt('textPrompt', {});
|
||||||
},
|
},
|
||||||
async step => {
|
async step => {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
|
|
||||||
const extractEntity = (text) => {
|
const extractEntity = text => {
|
||||||
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
|
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
|
||||||
}
|
};
|
||||||
|
|
||||||
const value = extractEntity(step.result);
|
const value = extractEntity(step.result);
|
||||||
|
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].validation_enter_valid_email);
|
await min.conversationalService.sendText(min, step, Messages[locale].validation_enter_valid_email);
|
||||||
return await step.replaceDialog('/gbasic-email', { ask: true });
|
return await step.replaceDialog('/gbasic-email', { ask: true });
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return await step.endDialog(value[0]);
|
return await step.endDialog(value[0]);
|
||||||
}
|
}
|
||||||
}]));
|
}
|
||||||
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sys(): SysClass {
|
public sys(): SysClass {
|
||||||
return this.internalSys;
|
return this.internalSys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async getToday(step) {
|
public async getToday(step) {
|
||||||
var d = new Date(),
|
var d = new Date(),
|
||||||
month = '' + (d.getMonth() + 1),
|
month = '' + (d.getMonth() + 1),
|
||||||
day = '' + d.getDate(),
|
day = '' + d.getDate(),
|
||||||
year = d.getFullYear();
|
year = d.getFullYear();
|
||||||
|
|
||||||
if (month.length < 2)
|
if (month.length < 2) month = '0' + month;
|
||||||
month = '0' + month;
|
if (day.length < 2) day = '0' + day;
|
||||||
if (day.length < 2)
|
|
||||||
day = '0' + day;
|
|
||||||
|
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
switch (locale) {
|
switch (locale) {
|
||||||
|
@ -348,8 +442,7 @@ export class DialogClass {
|
||||||
|
|
||||||
public async sendFile(step, filename, caption) {
|
public async sendFile(step, filename, caption) {
|
||||||
let url = urlJoin(GBServer.globals.publicAddress, 'kb', this.min.botId + '.gbkb', 'assets', filename);
|
let url = urlJoin(GBServer.globals.publicAddress, 'kb', this.min.botId + '.gbkb', 'assets', filename);
|
||||||
await this.min.conversationalService.sendFile(this.min, step,
|
await this.min.conversationalService.sendFile(this.min, step, null, url, caption);
|
||||||
null, url, caption);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFrom(step) {
|
public async getFrom(step) {
|
||||||
|
@ -361,16 +454,11 @@ export class DialogClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getUserMobile(step) {
|
public async getUserMobile(step) {
|
||||||
|
if (isNaN(step.context.activity.from.id)) {
|
||||||
if (isNaN(step.context.activity.from.id))
|
return 'No mobile available.';
|
||||||
{
|
} else {
|
||||||
return ('No mobile available.');
|
return step.context.activity.from.id;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return (step.context.activity.from.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async askEmail(step) {
|
public async askEmail(step) {
|
||||||
|
@ -379,7 +467,7 @@ export class DialogClass {
|
||||||
|
|
||||||
public async hear(step, promise, previousResolve) {
|
public async hear(step, promise, previousResolve) {
|
||||||
function random(low, high) {
|
function random(low, high) {
|
||||||
return Math.random() * (high - low) + low
|
return Math.random() * (high - low) + low;
|
||||||
}
|
}
|
||||||
const idPromise = random(0, 120000000);
|
const idPromise = random(0, 120000000);
|
||||||
this.min.cbMap[idPromise] = {};
|
this.min.cbMap[idPromise] = {};
|
||||||
|
@ -388,8 +476,7 @@ export class DialogClass {
|
||||||
const opts = { id: idPromise, previousResolve: previousResolve };
|
const opts = { id: idPromise, previousResolve: previousResolve };
|
||||||
if (previousResolve !== undefined) {
|
if (previousResolve !== undefined) {
|
||||||
previousResolve(opts);
|
previousResolve(opts);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
await step.beginDialog('/hear', opts);
|
await step.beginDialog('/hear', opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,9 +250,7 @@ export class GBConversationalService {
|
||||||
const params = {
|
const params = {
|
||||||
audio: data,
|
audio: data,
|
||||||
contentType: 'audio/l16; rate=44100',
|
contentType: 'audio/l16; rate=44100',
|
||||||
model: "pt-BR_BroadbandModel",
|
model: "pt-BR_BroadbandModel"
|
||||||
keywords: ['azul', 'céu', 'sol'],
|
|
||||||
keywordsThreshold: 0.5
|
|
||||||
};
|
};
|
||||||
|
|
||||||
speechToText
|
speechToText
|
||||||
|
|
|
@ -55,7 +55,7 @@ import { GBConfigService } from './GBConfigService';
|
||||||
import { GBImporter } from './GBImporterService';
|
import { GBImporter } from './GBImporterService';
|
||||||
import { GBVMService } from './GBVMService';
|
import { GBVMService } from './GBVMService';
|
||||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
|
const MicrosoftGraph = require('@microsoft/microsoft-graph-client');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -74,13 +74,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getConnectionStringFromInstance(instance: IGBInstance) {
|
public static getConnectionStringFromInstance(instance: IGBInstance) {
|
||||||
return `Server=tcp:${instance.storageServer}.database.windows.net,1433;Database=${
|
return `Server=tcp:${instance.storageServer}.database.windows.net,1433;Database=${instance.storageName};User ID=${instance.storageUsername};Password=${instance.storagePassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`;
|
||||||
instance.storageName
|
|
||||||
};User ID=${
|
|
||||||
instance.storageUsername
|
|
||||||
};Password=${
|
|
||||||
instance.storagePassword
|
|
||||||
};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,9 +104,17 @@ export class GBDeployer implements IGBDeployer {
|
||||||
const dirs = getDirectories(path);
|
const dirs = getDirectories(path);
|
||||||
await CollectionUtil.asyncForEach(dirs, async element => {
|
await CollectionUtil.asyncForEach(dirs, async element => {
|
||||||
element = element.toLowerCase();
|
element = element.toLowerCase();
|
||||||
|
|
||||||
if (element === '.') {
|
if (element === '.') {
|
||||||
GBLog.info(`Ignoring ${element}...`);
|
GBLog.info(`Ignoring ${element}...`);
|
||||||
} else {
|
} else {
|
||||||
|
const name = Path.basename(element).toLowerCase();
|
||||||
|
|
||||||
|
if (process.env.GBAPP_SKIP && (process.env.GBAPP_SKIP.toLowerCase().indexOf(name) !== -1 ||
|
||||||
|
process.env.GBAPP_SKIP === "true")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (element.endsWith('.gbot')) {
|
if (element.endsWith('.gbot')) {
|
||||||
botPackages.push(element);
|
botPackages.push(element);
|
||||||
} else if (element.endsWith('.gbapp') || element.endsWith('.gblib')) {
|
} else if (element.endsWith('.gbapp') || element.endsWith('.gblib')) {
|
||||||
|
@ -148,34 +150,25 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
GBLog.info(`App Package deployment done.`);
|
GBLog.info(`App Package deployment done.`);
|
||||||
|
|
||||||
({ generalPackages } = await this.deployDataPackages(
|
({ generalPackages } = await this.deployDataPackages(core, botPackages, _this, generalPackages));
|
||||||
|
|
||||||
core,
|
|
||||||
botPackages,
|
|
||||||
_this,
|
|
||||||
generalPackages
|
|
||||||
));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployBlankBot(botId: string) {
|
public async deployBlankBot(botId: string) {
|
||||||
let instance = await this.importer.createBotInstance(botId);
|
let instance = await this.importer.createBotInstance(botId);
|
||||||
|
|
||||||
const bootInstance = GBServer.globals.bootInstance;
|
const bootInstance = GBServer.globals.bootInstance;
|
||||||
const accessToken = await GBServer.globals.minBoot.adminService
|
const accessToken = await GBServer.globals.minBoot.adminService.acquireElevatedToken(bootInstance.instanceId);
|
||||||
.acquireElevatedToken(bootInstance.instanceId);
|
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
let application = await service.createApplication(accessToken, botId);
|
let application = await service.createApplication(accessToken, botId);
|
||||||
|
|
||||||
instance.marketplaceId = (application as any).appId;
|
instance.marketplaceId = (application as any).appId;
|
||||||
instance.marketplacePassword = await service.createApplicationSecret(
|
instance.marketplacePassword = await service.createApplicationSecret(accessToken, (application as any).id);
|
||||||
accessToken, (application as any).id);
|
|
||||||
instance.adminPass = GBAdminService.getRndPassword();
|
instance.adminPass = GBAdminService.getRndPassword();
|
||||||
instance.title = botId;
|
instance.title = botId;
|
||||||
instance.activationCode = instance.botId;
|
instance.activationCode = instance.botId;
|
||||||
instance.state = 'active';
|
instance.state = 'active';
|
||||||
instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx.
|
instance.nlpScore = 0.8; // TODO: Migrate to Excel Config.xlsx.
|
||||||
instance.searchScore = 0.45;
|
instance.searchScore = 0.45;
|
||||||
instance.whatsappServiceKey = bootInstance.whatsappServiceKey;
|
instance.whatsappServiceKey = bootInstance.whatsappServiceKey;
|
||||||
instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber;
|
instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber;
|
||||||
|
@ -195,7 +188,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<IGBInstance> {
|
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<IGBInstance> {
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
|
@ -211,9 +203,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
instance.description,
|
instance.description,
|
||||||
`${publicAddress}/api/messages/${instance.botId}`
|
`${publicAddress}/api/messages/${instance.botId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let botId = GBConfigService.get('BOT_ID');
|
let botId = GBConfigService.get('BOT_ID');
|
||||||
let bootInstance = await this.core.loadInstanceByBotId(botId);
|
let bootInstance = await this.core.loadInstanceByBotId(botId);
|
||||||
|
|
||||||
|
@ -251,7 +241,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
await GBServer.globals.minService.mountBot(instance);
|
await GBServer.globals.minService.mountBot(instance);
|
||||||
}
|
}
|
||||||
return await this.core.saveInstance(instance);
|
return await this.core.saveInstance(instance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,16 +248,13 @@ export class GBDeployer implements IGBDeployer {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
||||||
|
|
||||||
const packageName = Path.basename(localPath);
|
const packageName = Path.basename(localPath);
|
||||||
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
||||||
this.deployBotFull(instance, publicAddress);
|
this.deployBotFull(instance, publicAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadParamsFromExcel(min: GBMinInstance): Promise<any> {
|
public async loadParamsFromExcel(min: GBMinInstance): Promise<any> {
|
||||||
|
let token = await min.adminService.acquireElevatedToken(min.instance.instanceId);
|
||||||
let token =
|
|
||||||
await min.adminService.acquireElevatedToken(min.instance.instanceId);
|
|
||||||
|
|
||||||
let siteId = process.env.STORAGE_SITE_ID;
|
let siteId = process.env.STORAGE_SITE_ID;
|
||||||
let libraryId = process.env.STORAGE_LIBRARY;
|
let libraryId = process.env.STORAGE_LIBRARY;
|
||||||
|
@ -281,15 +267,14 @@ export class GBDeployer implements IGBDeployer {
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = `/${botId}.gbai/${botId}.gbot`;
|
const path = `/${botId}.gbai/${botId}.gbot`;
|
||||||
|
|
||||||
let res = await client.api(
|
let res = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
.api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
|
||||||
// Performs validation.
|
// Performs validation.
|
||||||
|
|
||||||
let document = res.value.filter(m => {
|
let document = res.value.filter(m => {
|
||||||
return m.name === "Config.xlsx"
|
return m.name === 'Config.xlsx';
|
||||||
});
|
});
|
||||||
if (document === undefined || document.length === 0) {
|
if (document === undefined || document.length === 0) {
|
||||||
GBLog.info(`Config.xlsx not found on .bot folder, check the package.`);
|
GBLog.info(`Config.xlsx not found on .bot folder, check the package.`);
|
||||||
|
@ -298,14 +283,16 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
// Creates workbook session that will be discarded.
|
// Creates workbook session that will be discarded.
|
||||||
|
|
||||||
let results = await client.api(
|
let results = await client
|
||||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('General')/range(address='A7:B100')`)
|
.api(
|
||||||
|
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('General')/range(address='A7:B100')`
|
||||||
|
)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
let index = 0;
|
let index = 0;
|
||||||
let obj = {};
|
let obj = {};
|
||||||
for (; index < results.text.length; index++) {
|
for (; index < results.text.length; index++) {
|
||||||
if (results.text[index][0] === "") {
|
if (results.text[index][0] === '') {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
obj[results.text[index][0]] = results.text[index][1];
|
obj[results.text[index][0]] = results.text[index][1];
|
||||||
|
@ -313,7 +300,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UndDeploys a bot to the storage.
|
* UndDeploys a bot to the storage.
|
||||||
*/
|
*/
|
||||||
|
@ -324,11 +310,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
const group = GBConfigService.get('CLOUD_GROUP');
|
const group = GBConfigService.get('CLOUD_GROUP');
|
||||||
|
|
||||||
if (await service.botExists(botId)) {
|
if (await service.botExists(botId)) {
|
||||||
|
await service.deleteBot(botId, group);
|
||||||
await service.deleteBot(
|
|
||||||
botId, group
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
GBServer.globals.minService.unmountBot(botId);
|
GBServer.globals.minService.unmountBot(botId);
|
||||||
await this.core.deleteInstance(botId);
|
await this.core.deleteInstance(botId);
|
||||||
|
@ -366,20 +348,22 @@ export class GBDeployer implements IGBDeployer {
|
||||||
// .gbapp package or platform package checking.
|
// .gbapp package or platform package checking.
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
if (pck = await e.onExchangeData(min, "handlePackage", {
|
if (
|
||||||
|
(pck = await e.onExchangeData(min, 'handlePackage', {
|
||||||
name: localPath,
|
name: localPath,
|
||||||
createPackage: async (packageName) => {
|
createPackage: async packageName => {
|
||||||
return await _this.deployPackageToStorage(min.instance.instanceId, packageName);
|
return await _this.deployPackageToStorage(min.instance.instanceId, packageName);
|
||||||
}, updatePackage: async (p: GuaribasPackage) => {
|
},
|
||||||
|
updatePackage: async (p: GuaribasPackage) => {
|
||||||
p.save();
|
p.save();
|
||||||
}
|
}
|
||||||
})) {
|
}))
|
||||||
|
) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (handled) {
|
if (handled) {
|
||||||
|
|
||||||
return pck;
|
return pck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +429,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
return await service.undeployKbFromStorage(instance, this, p.packageId);
|
return await service.undeployKbFromStorage(instance, this, p.packageId);
|
||||||
|
|
||||||
case '.gbui':
|
case '.gbui':
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.gbtheme':
|
case '.gbtheme':
|
||||||
|
@ -457,10 +440,8 @@ export class GBDeployer implements IGBDeployer {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.gblib':
|
case '.gblib':
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case '.gbapp':
|
case '.gbapp':
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
const err = GBError.create(`Unhandled package type: ${packageType}.`);
|
const err = GBError.create(`Unhandled package type: ${packageType}.`);
|
||||||
|
@ -531,7 +512,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deployDataPackages(
|
private async deployDataPackages(
|
||||||
|
|
||||||
core: IGBCoreService,
|
core: IGBCoreService,
|
||||||
botPackages: string[],
|
botPackages: string[],
|
||||||
_this: this,
|
_this: this,
|
||||||
|
@ -557,16 +537,18 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
const instances = core.loadInstances();
|
const instances = core.loadInstances();
|
||||||
await CollectionUtil.asyncForEach(instances, async instance => {
|
await CollectionUtil.asyncForEach(instances, async instance => {
|
||||||
|
|
||||||
this.mountGBKBAssets(`{instance.botId}.gbkb`, instance.botId, `{instance.botId}.gbkb`);
|
this.mountGBKBAssets(`{instance.botId}.gbkb`, instance.botId, `{instance.botId}.gbkb`);
|
||||||
});
|
});
|
||||||
|
|
||||||
GBLog.info(`Package deployment done.`);
|
GBLog.info(`Package deployment done.`);
|
||||||
return { generalPackages};
|
return { generalPackages };
|
||||||
}
|
}
|
||||||
|
|
||||||
public mountGBKBAssets(packageName: any, botId: string, filename: string) {
|
public mountGBKBAssets(packageName: any, botId: string, filename: string) {
|
||||||
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/subjects`, express.static(urlJoin(filename, 'subjects')));
|
GBServer.globals.server.use(
|
||||||
|
`/kb/${botId}.gbai/${packageName}/subjects`,
|
||||||
|
express.static(urlJoin(filename, 'subjects'))
|
||||||
|
);
|
||||||
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/assets`, express.static(urlJoin(filename, 'assets')));
|
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/assets`, express.static(urlJoin(filename, 'assets')));
|
||||||
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/images`, express.static(urlJoin(filename, 'images')));
|
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/images`, express.static(urlJoin(filename, 'images')));
|
||||||
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/audios`, express.static(urlJoin(filename, 'audios')));
|
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/audios`, express.static(urlJoin(filename, 'audios')));
|
||||||
|
@ -575,7 +557,18 @@ export class GBDeployer implements IGBDeployer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private isSystemPackage(name: string): Boolean {
|
private isSystemPackage(name: string): Boolean {
|
||||||
const names = ['analytics.gblib', 'console.gblib', 'security.gbapp', 'whatsapp.gblib', 'sharepoint.gblib', 'core.gbapp', 'admin.gbapp', 'azuredeployer.gbapp', 'customer-satisfaction.gbapp', 'kb.gbapp'];
|
const names = [
|
||||||
|
'analytics.gblib',
|
||||||
|
'console.gblib',
|
||||||
|
'security.gbapp',
|
||||||
|
'whatsapp.gblib',
|
||||||
|
'sharepoint.gblib',
|
||||||
|
'core.gbapp',
|
||||||
|
'admin.gbapp',
|
||||||
|
'azuredeployer.gbapp',
|
||||||
|
'customer-satisfaction.gbapp',
|
||||||
|
'kb.gbapp'
|
||||||
|
];
|
||||||
|
|
||||||
return names.indexOf(name) > -1;
|
return names.indexOf(name) > -1;
|
||||||
}
|
}
|
||||||
|
@ -587,7 +580,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
// Skips .gbapp inside deploy folder.
|
// Skips .gbapp inside deploy folder.
|
||||||
if (this.isSystemPackage(filenameOnly) === false) {
|
if (this.isSystemPackage(filenameOnly) === false) {
|
||||||
|
|
||||||
appPackagesProcessed = await this.callGBAppCompiler(e, core, appPackages, appPackagesProcessed);
|
appPackagesProcessed = await this.callGBAppCompiler(e, core, appPackages, appPackagesProcessed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -595,11 +587,15 @@ export class GBDeployer implements IGBDeployer {
|
||||||
return appPackagesProcessed;
|
return appPackagesProcessed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async callGBAppCompiler(gbappPath: string, core: IGBCoreService,
|
public async callGBAppCompiler(
|
||||||
appPackages: any[] = undefined, appPackagesProcessed: number = 0) {
|
gbappPath: string,
|
||||||
|
core: IGBCoreService,
|
||||||
|
appPackages: any[] = undefined,
|
||||||
|
appPackagesProcessed: number = 0
|
||||||
|
) {
|
||||||
GBLog.info(`Deploying General Bots Application (.gbapp) or Library (.gblib): ${Path.basename(gbappPath)}...`);
|
GBLog.info(`Deploying General Bots Application (.gbapp) or Library (.gblib): ${Path.basename(gbappPath)}...`);
|
||||||
let folder = Path.join(gbappPath, 'node_modules');
|
let folder = Path.join(gbappPath, 'node_modules');
|
||||||
if (process.env.GBAPP_DISABLE_COMPILE !== "true") {
|
if (process.env.GBAPP_DISABLE_COMPILE !== 'true') {
|
||||||
if (!Fs.existsSync(folder)) {
|
if (!Fs.existsSync(folder)) {
|
||||||
GBLog.info(`Installing modules for ${gbappPath}...`);
|
GBLog.info(`Installing modules for ${gbappPath}...`);
|
||||||
child_process.execSync('npm install', { cwd: gbappPath });
|
child_process.execSync('npm install', { cwd: gbappPath });
|
||||||
|
@ -607,7 +603,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
}
|
}
|
||||||
folder = Path.join(gbappPath, 'dist');
|
folder = Path.join(gbappPath, 'dist');
|
||||||
try {
|
try {
|
||||||
if (process.env.GBAPP_DISABLE_COMPILE !== "true") {
|
if (process.env.GBAPP_DISABLE_COMPILE !== 'true') {
|
||||||
GBLog.info(`Compiling: ${gbappPath}.`);
|
GBLog.info(`Compiling: ${gbappPath}.`);
|
||||||
child_process.execSync(Path.join(process.env.PWD, 'node_modules/.bin/tsc'), { cwd: gbappPath });
|
child_process.execSync(Path.join(process.env.PWD, 'node_modules/.bin/tsc'), { cwd: gbappPath });
|
||||||
}
|
}
|
||||||
|
@ -623,8 +619,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
GBLog.info(`.gbapp or .gblib deployed: ${gbappPath}.`);
|
GBLog.info(`.gbapp or .gblib deployed: ${gbappPath}.`);
|
||||||
appPackagesProcessed++;
|
appPackagesProcessed++;
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
GBLog.error(`Error compiling package, message: ${error.message}\n${error.stack}`);
|
GBLog.error(`Error compiling package, message: ${error.message}\n${error.stack}`);
|
||||||
if (error.stdout) {
|
if (error.stdout) {
|
||||||
GBLog.error(`Error compiling package, stdout: ${gbappPath}:\n${error.stdout.toString()}`);
|
GBLog.error(`Error compiling package, stdout: ${gbappPath}:\n${error.stdout.toString()}`);
|
||||||
|
|
|
@ -519,8 +519,18 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance) {
|
private async invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance) {
|
||||||
await CollectionUtil.asyncForEach(sysPackages, async e => {
|
await CollectionUtil.asyncForEach(sysPackages, async p => {
|
||||||
await e.loadBot(min);
|
p.sysPackages = sysPackages;
|
||||||
|
if (p.getDialogs !== undefined) {
|
||||||
|
const dialogs = await p.getDialogs(min);
|
||||||
|
if (dialogs !== undefined) {
|
||||||
|
dialogs.forEach(dialog => {
|
||||||
|
min.dialogs.add(new WaterfallDialog(dialog.id, dialog.waterfall));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await p.loadBot(min);
|
||||||
});
|
});
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(appPackages, async p => {
|
await CollectionUtil.asyncForEach(appPackages, async p => {
|
||||||
|
|
|
@ -137,6 +137,12 @@ export class GBVMService extends GBService {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
text = text.replace('“', '\"');
|
||||||
|
text = text.replace('”', '\"');
|
||||||
|
text = text.replace('‘', '\'');
|
||||||
|
text = text.replace('’', '\'');
|
||||||
|
|
||||||
|
|
||||||
resolve(text);
|
resolve(text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -157,8 +163,8 @@ export class GBVMService extends GBService {
|
||||||
from = this.getFrom(step)
|
from = this.getFrom(step)
|
||||||
today = this.getToday(step)
|
today = this.getToday(step)
|
||||||
id = sys().getRandomId()
|
id = sys().getRandomId()
|
||||||
username = this.getUserName();
|
username = this.getUserName(step);
|
||||||
mobile = this.getUserMobile();
|
mobile = this.getUserMobile(step);
|
||||||
|
|
||||||
${code}
|
${code}
|
||||||
`;
|
`;
|
||||||
|
@ -183,8 +189,12 @@ export class GBVMService extends GBService {
|
||||||
return `let stock = sys().getStock(${$2})`;
|
return `let stock = sys().getStock(${$2})`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/(get)(\s)(.*)/gi, ($0, $1, $2) => {
|
code = code.replace(/(\w+)\s*\=\s*get\s(.*)/gi, ($0, $1, $2) => {
|
||||||
return `sys().httpGet (${$2})`;
|
return `let ${$1} = sys().httpGet (${$2})`;
|
||||||
|
});
|
||||||
|
|
||||||
|
code = code.replace(/(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
|
return `let ${$1} = sys().httpPost (${$2}, ${$3})`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/(create a bot farm using)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(create a bot farm using)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue