new(core.gbapp): New OnExchangeData flexible interface and /publish fixing.
This commit is contained in:
parent
7bc83b8b60
commit
9600f890fc
18 changed files with 148 additions and 36 deletions
|
@ -49,6 +49,11 @@ ALTER TABLE dbo.GuaribasInstance ADD
|
|||
activationCode nvarchar(16) NULL
|
||||
GO
|
||||
|
||||
# 1.7.9
|
||||
|
||||
ALTER TABLE dbo.GuaribasInstance ADD
|
||||
params nvarchar(4000) NULL
|
||||
GO
|
||||
|
||||
|
||||
```
|
|
@ -179,9 +179,7 @@ export class AdminDialog extends IGBDialog {
|
|||
|
||||
let from = step.context.activity.from.id;
|
||||
|
||||
let canPublish = process.env.SECURITY_CAN_PUBLISH ?
|
||||
AdminDialog.canSendBroadcast(from) :
|
||||
|
||||
let canPublish = AdminDialog.canPublish(min, from);
|
||||
|
||||
if (canPublish) {
|
||||
|
||||
|
@ -216,7 +214,9 @@ export class AdminDialog extends IGBDialog {
|
|||
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
|
||||
});
|
||||
} catch (error) {
|
||||
await min.conversationalService.sendText(min, step, error.message);
|
||||
await min.conversationalService.sendText(min, step, `ERROR: ${error}` );
|
||||
GBLog.error(error);
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
}
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].publish_success);
|
||||
if (!step.activeDialog.state.options.confirm) {
|
||||
|
@ -240,12 +240,17 @@ export class AdminDialog extends IGBDialog {
|
|||
* the /broadcast command with specific phone numbers.
|
||||
* @param phone Phone number to check (eg.: +5521900002233)
|
||||
*/
|
||||
public static canSendBroadcast(phone: string): Boolean {
|
||||
return true; // TODO: REMOVE THIS.
|
||||
const list = process.env.SECURITY_CAN_PUBLISH.split(';');
|
||||
return list.includes(phone);
|
||||
}
|
||||
public static canPublish(min: GBMinInstance, phone: string): Boolean {
|
||||
|
||||
const list = process.env.SECURITY_CAN_PUBLISH.split(';');
|
||||
let result = list.includes(phone);
|
||||
|
||||
if (!result && min.instance.params) {
|
||||
const params = JSON.parse(min.instance.params);
|
||||
return list.includes(params['Can Publish']);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static setupSecurityDialogs(min: GBMinInstance) {
|
||||
min.dialogs.add(
|
||||
|
|
|
@ -59,6 +59,10 @@ export class GBAdminPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||
core.sequelize.addModels([GuaribasAdmin]);
|
||||
|
@ -67,4 +71,5 @@ export class GBAdminPackage implements IGBPackage {
|
|||
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||
AdminDialog.setup(min);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -212,8 +212,7 @@ export class GBAdminService implements IGBAdminService {
|
|||
return path.indexOf('sharepoint.com') > 0;
|
||||
}
|
||||
|
||||
public async publish(min: GBMinInstance, packageName: string, republish: boolean): Promise<void>
|
||||
{
|
||||
public async publish(min: GBMinInstance, packageName: string, republish: boolean): Promise<void> {
|
||||
|
||||
}
|
||||
public static async deployPackageCommand(min: GBMinInstance, text: string, deployer: IGBDeployer) {
|
||||
|
@ -227,18 +226,24 @@ export class GBAdminService implements IGBAdminService {
|
|||
await deployer.deployPackage(min, urlJoin(additionalPath, packageName));
|
||||
}
|
||||
else {
|
||||
let s = new GBSharePointService();
|
||||
let siteName = text.split(' ')[1];
|
||||
let folderName = text.split(' ')[2];
|
||||
|
||||
let localFolder = Path.join('work', Path.basename(folderName));
|
||||
GBLog.warn(`${GBConfigService.get('CLOUD_USERNAME')} must be authorized on SharePoint related site`);
|
||||
await s.downloadFolder(localFolder, siteName, folderName,
|
||||
GBConfigService.get('CLOUD_USERNAME'), GBConfigService.get('CLOUD_PASSWORD'))
|
||||
await deployer.deployPackage(min, localFolder);
|
||||
let packageType = Path.extname(folderName);
|
||||
if (packageType !== '.gbot') {
|
||||
let s = new GBSharePointService();
|
||||
|
||||
let localFolder = Path.join('work', Path.basename(folderName));
|
||||
GBLog.warn(`${GBConfigService.get('CLOUD_USERNAME')} must be authorized on SharePoint related site`);
|
||||
await s.downloadFolder(localFolder, siteName, folderName,
|
||||
GBConfigService.get('CLOUD_USERNAME'), GBConfigService.get('CLOUD_PASSWORD'))
|
||||
await deployer.deployPackage(min, localFolder);
|
||||
}
|
||||
else {
|
||||
await deployer.deployPackage(min, folderName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async rebuildIndexPackageCommand(min: GBMinInstance, deployer: IGBDeployer) {
|
||||
await deployer.rebuildIndex(
|
||||
min.instance,
|
||||
|
|
|
@ -65,4 +65,8 @@ export class GBAnalyticsPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,4 +62,8 @@ export class GBAzureDeployerPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,10 @@ export class GBConsolePackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||
this.channel = new ConsoleDirectLine(min.instance.webchatKey);
|
||||
|
|
|
@ -66,6 +66,10 @@ export class GBCorePackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||
WelcomeDialog.setup(min.bot, min);
|
||||
|
|
|
@ -238,6 +238,9 @@ export class GuaribasInstance extends Model<GuaribasInstance>
|
|||
@Column
|
||||
@UpdatedAt
|
||||
public updatedAt: Date;
|
||||
|
||||
@Column(DataType.STRING(4000))
|
||||
public params: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,6 +270,7 @@ export class GuaribasPackage extends Model<GuaribasPackage> {
|
|||
@Column
|
||||
@UpdatedAt
|
||||
public updatedAt: Date;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,6 @@ import { GBDeployer } from './GBDeployer';
|
|||
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
|
||||
import { Messages } from "../strings";
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { GBConversationalService } from './GBConversationalService';
|
||||
const request = require('request-promise-native');
|
||||
|
||||
/**
|
||||
|
@ -101,8 +100,8 @@ class SysClass {
|
|||
let token =
|
||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||
|
||||
let siteId = process.env.SAAS_SHAREPOINT_SITE_ID;
|
||||
let libraryId = process.env.SAAS_SHAREPOINT_LIBRARY_ID;
|
||||
let siteId = process.env.STORAGE_SITE_ID;
|
||||
let libraryId = process.env.STORAGE_LIBRARY;
|
||||
|
||||
let client = MicrosoftGraph.Client.init({
|
||||
authProvider: done => {
|
||||
|
@ -149,21 +148,17 @@ class SysClass {
|
|||
let token =
|
||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||
|
||||
let siteId = process.env.SAAS_SHAREPOINT_SITE_ID;
|
||||
let libraryId = process.env.SAAS_SHAREPOINT_LIBRARY_ID;
|
||||
|
||||
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();
|
||||
|
|
|
@ -210,13 +210,11 @@ export class GBCoreService implements IGBCoreService {
|
|||
* Loads all items to start several listeners.
|
||||
*/
|
||||
public async loadInstances(): Promise<IGBInstance[]> {
|
||||
if (process.env.LOAD_ONLY !== undefined)
|
||||
{
|
||||
if (process.env.LOAD_ONLY !== undefined) {
|
||||
const options = { where: { botId: process.env.LOAD_ONLY } };
|
||||
return GuaribasInstance.findAll(options);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return GuaribasInstance.findAll({});
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +316,11 @@ STORAGE_SYNC=true
|
|||
let instance = await GuaribasInstance.findOne(options);
|
||||
// tslint:disable-next-line:prefer-object-spread
|
||||
instance = Object.assign(instance, fullInstance);
|
||||
try {
|
||||
instance.params = JSON.stringify(JSON.parse(instance.params));
|
||||
} catch (err) {
|
||||
instance.params = JSON.stringify(instance.params);
|
||||
}
|
||||
return await instance.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ import { GBConfigService } from './GBConfigService';
|
|||
import { GBImporter } from './GBImporterService';
|
||||
import { GBVMService } from './GBVMService';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
|
||||
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -246,11 +246,60 @@ export class GBDeployer implements IGBDeployer {
|
|||
*/
|
||||
|
||||
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
||||
|
||||
const packageName = Path.basename(localPath);
|
||||
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
||||
this.deployBotFull(instance, publicAddress);
|
||||
}
|
||||
|
||||
public async loadParamsFromExcel(min: GBMinInstance): Promise<any> {
|
||||
|
||||
let token =
|
||||
await min.adminService.acquireElevatedToken(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 = min.instance.botId;
|
||||
const path = `/${botId}.gbai/${botId}.gbot`;
|
||||
|
||||
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 === "Config.xlsx"
|
||||
});
|
||||
if (document === undefined) {
|
||||
throw `Config.xlsx not found on .bot folder, check the package.`;
|
||||
}
|
||||
|
||||
// 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('General')/range(address='A7:B100')`)
|
||||
.get();
|
||||
|
||||
let index = 0;
|
||||
let obj = {};
|
||||
for (; index < results.text.length; index++) {
|
||||
if (results.text[index][0] === "") {
|
||||
return obj;
|
||||
}
|
||||
obj[results.text[index][0]] = results.text[index][1];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UndDeploys a bot to the storage.
|
||||
*/
|
||||
|
@ -298,7 +347,12 @@ export class GBDeployer implements IGBDeployer {
|
|||
|
||||
switch (packageType) {
|
||||
case '.gbot':
|
||||
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
|
||||
if (Fs.existsSync(localPath)) {
|
||||
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
|
||||
}
|
||||
min.instance.params = await this.loadParamsFromExcel(min);
|
||||
await this.core.saveInstance(min.instance);
|
||||
|
||||
break;
|
||||
|
||||
case '.gbkb':
|
||||
|
|
|
@ -61,6 +61,10 @@ export class GBCustomerSatisfactionPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||
core.sequelize.addModels([GuaribasQuestionAlternate]);
|
||||
|
|
|
@ -60,6 +60,10 @@ export class GBKBPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||
core.sequelize.addModels([GuaribasAnswer, GuaribasQuestion, GuaribasSubject]);
|
||||
|
|
|
@ -63,6 +63,10 @@ export class GBSecurityPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
|
||||
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||
core.sequelize.addModels([GuaribasGroup, GuaribasUser, GuaribasUserGroup]);
|
||||
|
|
|
@ -62,4 +62,8 @@ export class GBSharePointPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,4 +65,8 @@ export class GBWhatsappPackage implements IGBPackage {
|
|||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ STORAGE_DIALECT=mssql
|
|||
STORAGE_SERVER=dev-rodriguez-storage-server.database.windows.net
|
||||
STORAGE_NAME=dev-rodriguez-storage
|
||||
STORAGE_USERNAME=sanreaeffbpuydq
|
||||
STORAGE_PASSWORD=CGF#x%c#4I68
|
||||
STORAGE_PASSWORD=CGF#x%c#4
|
||||
STORAGE_SYNC=false
|
||||
GBAPP_DISABLE_COMPILE=true
|
||||
NLP_AUTHORING_KEY=59c157d348614cceaf041c1e06c65656
|
||||
|
|
Loading…
Add table
Reference in a new issue