- FIX: Packages updated.
- NEW: DATABASE_SYNC_ALTER environment parameter. - NEW: DATABASE_SYNC_FORCE environment parameter. - NEW: Define constraint names in MSSQL.
This commit is contained in:
parent
0955599855
commit
e4e331730d
24 changed files with 368 additions and 266 deletions
|
@ -1,5 +1,12 @@
|
|||
# Release History
|
||||
|
||||
## Version 0.0.30
|
||||
|
||||
- FIX: Packages updated.
|
||||
- NEW: DATABASE_SYNC_ALTER environment parameter.
|
||||
- NEW: DATABASE_SYNC_FORCE environment parameter.
|
||||
- NEW: Define constraint names in MSSQL.
|
||||
|
||||
## Version 0.0.29
|
||||
|
||||
- NEW: Added STT and TTS capabilities to default.gbui.
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
import { AzureSearch } from "pragmatismo-io-framework";
|
||||
import { Prompts, Session, UniversalBot } from 'botbuilder';
|
||||
import { GBMinInstance } from "botlib";
|
||||
|
|
|
@ -30,30 +30,31 @@
|
|||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
const UrlJoin = require('url-join');
|
||||
|
||||
const UrlJoin = require("url-join");
|
||||
import { AdminDialog } from './dialogs/AdminDialog';
|
||||
import { GBMinInstance, IGBPackage } from "botlib";
|
||||
import { GBMinInstance, IGBPackage, IGBCoreService } from 'botlib';
|
||||
import { Session } from 'botbuilder';
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { IGBCoreService } from 'botlib';
|
||||
|
||||
export class GBAdminPackage implements IGBPackage {
|
||||
|
||||
sysPackages: IGBPackage[] = null;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
}
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
AdminDialog.setup(min.bot, min);
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,29 +34,25 @@
|
|||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
|
||||
|
||||
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib";
|
||||
import { Session } from 'botbuilder';
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
|
||||
export class GBAnalyticsPackage implements IGBPackage {
|
||||
|
||||
sysPackages: IGBPackage[] = null;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
|
||||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,17 +30,17 @@
|
|||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
|
@ -56,13 +56,14 @@ import {
|
|||
PrimaryKey,
|
||||
AutoIncrement
|
||||
} from "sequelize-typescript";
|
||||
|
||||
import { GuaribasSubject } from "../../kb.gbapp/models";
|
||||
import { GuaribasUser } from "../../security.gblib/models";
|
||||
import { GuaribasChannel, GuaribasInstance } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
|
||||
@Table
|
||||
export class GuaribasConversation extends Model<GuaribasConversation> {
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
|
@ -81,15 +82,13 @@ export class GuaribasConversation extends Model<GuaribasConversation> {
|
|||
|
||||
@Column rateDate: Date;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
@Column(DataType.FLOAT)
|
||||
@Column
|
||||
rate: number;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
createdAt: Date;
|
||||
|
||||
@Column text: string;
|
||||
|
||||
|
@ -106,6 +105,7 @@ export class GuaribasConversation extends Model<GuaribasConversation> {
|
|||
|
||||
@Table
|
||||
export class GuaribasConversationMessage extends Model<GuaribasConversationMessage> {
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
|
@ -115,16 +115,16 @@ export class GuaribasConversationMessage extends Model<GuaribasConversationMessa
|
|||
@Column
|
||||
subjectId: number;
|
||||
|
||||
@Column({ type: DataType.TEXT })
|
||||
@Column(DataType.TEXT)
|
||||
content: string;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
@ForeignKey(() => GuaribasConversation)
|
||||
@Column
|
||||
|
|
|
@ -34,13 +34,11 @@
|
|||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
|
||||
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib";
|
||||
import { Session } from 'botbuilder';
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { ConsoleDirectLine } from "./services/ConsoleDirectLine";
|
||||
|
||||
|
||||
export class GBConsolePackage implements IGBPackage {
|
||||
sysPackages: IGBPackage[] = null;
|
||||
channel: ConsoleDirectLine;
|
||||
|
@ -49,7 +47,6 @@ export class GBConsolePackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
@ -57,9 +54,8 @@ export class GBConsolePackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import { Session } from 'botbuilder';
|
|||
import { WelcomeDialog } from "./dialogs/WelcomeDialog";
|
||||
import { WhoAmIDialog } from "./dialogs/WhoAmIDialog";
|
||||
import { IGBCoreService } from "botlib";
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { GuaribasInstance, GuaribasException, GuaribasPackage, GuaribasChannel } from "./models/GBModel";
|
||||
|
||||
export class GBCorePackage implements IGBPackage {
|
||||
|
@ -55,7 +55,6 @@ export class GBCorePackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
@ -64,9 +63,8 @@ export class GBCorePackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
|
@ -55,20 +56,20 @@ import {
|
|||
PrimaryKey,
|
||||
AutoIncrement
|
||||
} from "sequelize-typescript";
|
||||
import { IGBInstance } from "botlib";
|
||||
|
||||
import { IGBInstance } from "botlib";
|
||||
|
||||
@Table
|
||||
export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInstance {
|
||||
|
||||
@Column
|
||||
whoAmIVideo: string;
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@Column
|
||||
whoAmIVideo: string;
|
||||
|
||||
@Column botId: string;
|
||||
|
||||
@Column title: string;
|
||||
|
@ -111,9 +112,7 @@ export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInst
|
|||
|
||||
@Column kb: string;
|
||||
|
||||
@Column
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
nlpServerUrl: string;
|
||||
@Column(DataType.STRING(512)) nlpServerUrl: string;
|
||||
|
||||
@Column searchHost: string;
|
||||
|
||||
|
@ -125,28 +124,19 @@ export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInst
|
|||
|
||||
/* Settings section of bot.json */
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpVsSearch: number;
|
||||
@Column(DataType.FLOAT) nlpVsSearch: number;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
searchScore: number;
|
||||
@Column(DataType.FLOAT) searchScore: number;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpScore: number;
|
||||
@Column(DataType.FLOAT) nlpScore: number;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
@Table
|
||||
|
@ -163,16 +153,36 @@ export class GuaribasPackage extends Model<GuaribasPackage> {
|
|||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@BelongsTo(() => GuaribasInstance)
|
||||
instance: GuaribasInstance;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
@Table
|
||||
export class GuaribasChannel extends Model<GuaribasChannel> {
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
channelId: number;
|
||||
|
||||
@Column title: string;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
@Table
|
||||
|
@ -189,8 +199,14 @@ export class GuaribasException extends Model<GuaribasException> {
|
|||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@BelongsTo(() => GuaribasInstance)
|
||||
instance: GuaribasInstance;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
}
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ export class GBConfigService {
|
|||
}
|
||||
}
|
||||
|
||||
static get(key: string): any {
|
||||
static get(key: string): string | undefined {
|
||||
let value = process.env["container:" + key];
|
||||
|
||||
if (!value) {
|
||||
|
@ -71,9 +71,19 @@ export class GBConfigService {
|
|||
break;
|
||||
|
||||
case "DATABASE_SYNC":
|
||||
case "DATABASE_SYNC_ALTER":
|
||||
case "DATABASE_SYNC_FORCE":
|
||||
value = "false";
|
||||
break;
|
||||
|
||||
case "DATABASE_LOGGING":
|
||||
value = "false";
|
||||
break;
|
||||
|
||||
case "DATABASE_ENCRYPT":
|
||||
value = "true";
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.trace(
|
||||
`Guaribas General Error: Invalid key on .env file: '${key}'`
|
||||
|
|
|
@ -41,7 +41,7 @@ const UrlJoin = require("url-join");
|
|||
const Walk = require("fs-walk");
|
||||
const logger = require("../../../src/logger");
|
||||
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { Promise } from "bluebird";
|
||||
import { GBConfigService } from "./GBConfigService";
|
||||
import { DataTypeUUIDv1 } from "sequelize";
|
||||
|
@ -56,9 +56,13 @@ export class GBCoreService implements IGBCoreService {
|
|||
|
||||
public sequelize: Sequelize;
|
||||
|
||||
private queryGenerator: any;
|
||||
private createTableQuery: (tableName, attributes, options) => string;
|
||||
private changeColumnQuery: (tableName, attributes) => string;
|
||||
|
||||
/** Dialect used. Tested: mssql and sqlite. */
|
||||
|
||||
dialect: string;
|
||||
private dialect: string;
|
||||
|
||||
constructor() {
|
||||
this.dialect = GBConfigService.get("DATABASE_DIALECT");
|
||||
|
@ -67,11 +71,11 @@ export class GBCoreService implements IGBCoreService {
|
|||
/** Get config and connect to storage. */
|
||||
initDatabase(cb) {
|
||||
|
||||
let host = "";
|
||||
let database = "";
|
||||
let username = "";
|
||||
let password = "";
|
||||
let storage = "";
|
||||
let host: string | undefined;
|
||||
let database: string | undefined;
|
||||
let username: string | undefined;
|
||||
let password: string | undefined;
|
||||
let storage: string | undefined;
|
||||
|
||||
if (this.dialect === "mssql") {
|
||||
host = GBConfigService.get("DATABASE_HOST");
|
||||
|
@ -82,14 +86,11 @@ export class GBCoreService implements IGBCoreService {
|
|||
storage = GBConfigService.get("DATABASE_STORAGE");
|
||||
}
|
||||
|
||||
let value = GBConfigService.get("DATABASE_LOGGING");
|
||||
let logging: boolean | Function = false;
|
||||
let logging = (GBConfigService.get("DATABASE_LOGGING") === "true")
|
||||
? (str: string) => { logger.trace(str); }
|
||||
: false;
|
||||
|
||||
if (value && value == "1") {
|
||||
logging = (str) => {
|
||||
logger.trace(str);
|
||||
};
|
||||
}
|
||||
let encrypt = (GBConfigService.get("DATABASE_ENCRYPT") === "true");
|
||||
|
||||
this.sequelize = new Sequelize({
|
||||
host: host,
|
||||
|
@ -100,9 +101,8 @@ export class GBCoreService implements IGBCoreService {
|
|||
operatorsAliases: false,
|
||||
dialect: this.dialect,
|
||||
storage: storage,
|
||||
|
||||
dialectOptions: {
|
||||
encrypt: true
|
||||
encrypt: encrypt
|
||||
},
|
||||
pool: {
|
||||
max: 32,
|
||||
|
@ -110,26 +110,106 @@ export class GBCoreService implements IGBCoreService {
|
|||
idle: 40000,
|
||||
evict: 40000,
|
||||
acquire: 40000
|
||||
}
|
||||
},
|
||||
});
|
||||
cb();
|
||||
|
||||
if (this.dialect === "mssql") {
|
||||
this.queryGenerator = this.sequelize.getQueryInterface().QueryGenerator;
|
||||
this.createTableQuery = this.queryGenerator.createTableQuery;
|
||||
this.queryGenerator.createTableQuery = (tableName, attributes, options) =>
|
||||
this.createTableQueryOverride(tableName, attributes, options);
|
||||
this.changeColumnQuery = this.queryGenerator.changeColumnQuery;
|
||||
this.queryGenerator.changeColumnQuery = (tableName, attributes) =>
|
||||
this.changeColumnQueryOverride(tableName, attributes);
|
||||
}
|
||||
|
||||
setImmediate(cb);
|
||||
}
|
||||
|
||||
private createTableQueryOverride(tableName, attributes, options): string {
|
||||
let sql: string = this.createTableQuery.apply(this.queryGenerator,
|
||||
[tableName, attributes, options]);
|
||||
// let sql: string = '' +
|
||||
// 'IF OBJECT_ID(\'[UserGroup]\', \'U\') IS NULL\n' +
|
||||
// 'CREATE TABLE [UserGroup] (\n' +
|
||||
// ' [id] INTEGER NOT NULL IDENTITY(1,1),\n' +
|
||||
// ' [userId] INTEGER NULL,\n' +
|
||||
// ' [groupId] INTEGER NULL,\n' +
|
||||
// ' [instanceId] INTEGER NULL,\n' +
|
||||
// ' PRIMARY KEY ([id1], [id2]),\n' +
|
||||
// ' FOREIGN KEY ([userId1], [userId2], [userId3]) REFERENCES [User] ([userId1], [userId2], [userId3]) ON DELETE NO ACTION,\n' +
|
||||
// ' FOREIGN KEY ([groupId1], [groupId2]) REFERENCES [Group] ([groupId1], [groupId1]) ON DELETE NO ACTION,\n' +
|
||||
// ' FOREIGN KEY ([instanceId]) REFERENCES [Instance] ([instanceId]) ON DELETE NO ACTION);';
|
||||
const re1 = /CREATE\s+TABLE\s+\[([^\]]*)\]/;
|
||||
const matches = re1.exec(sql);
|
||||
if (matches) {
|
||||
const table = matches[1];
|
||||
const re2 = /PRIMARY\s+KEY\s+\(\[[^\]]*\](?:,\s*\[[^\]]*\])*\)/;
|
||||
sql = sql.replace(re2, (match: string, ...args: any[]): string => {
|
||||
return 'CONSTRAINT [' + table + '_pk] ' + match;
|
||||
});
|
||||
const re3 = /FOREIGN\s+KEY\s+\((\[[^\]]*\](?:,\s*\[[^\]]*\])*)\)/g;
|
||||
const re4 = /\[([^\]]*)\]/g;
|
||||
sql = sql.replace(re3, (match: string, ...args: any[]): string => {
|
||||
const fkcols = args[0];
|
||||
let fkname = table;
|
||||
let matches = re4.exec(fkcols);
|
||||
while (matches != null) {
|
||||
fkname += '_' + matches[1];
|
||||
matches = re4.exec(fkcols);
|
||||
}
|
||||
return 'CONSTRAINT [' + fkname + '_fk] FOREIGN KEY (' + fkcols + ')';
|
||||
});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
private changeColumnQueryOverride(tableName, attributes): string {
|
||||
let sql: string = this.changeColumnQuery.apply(this.queryGenerator,
|
||||
[tableName, attributes]);
|
||||
// let sql = '' +
|
||||
// 'ALTER TABLE [UserGroup]\n' +
|
||||
// ' ADD CONSTRAINT [invalid1] FOREIGN KEY ([userId1], [userId2], [userId3]) REFERENCES [User] ([userId1], [userId2], [userId3]) ON DELETE NO ACTION,\n' +
|
||||
// ' CONSTRAINT [invalid2] FOREIGN KEY ([groupId1], [groupId2]) REFERENCES [Group] ([groupId1], [groupId2]) ON DELETE NO ACTION, \n' +
|
||||
// ' CONSTRAINT [invalid3] FOREIGN KEY ([instanceId1]) REFERENCES [Instance] ([instanceId1]) ON DELETE NO ACTION;\n';
|
||||
const re1 = /ALTER\s+TABLE\s+\[([^\]]*)\]/;
|
||||
const matches = re1.exec(sql);
|
||||
if (matches) {
|
||||
const table = matches[1];
|
||||
const re2 = /(ADD\s+)?CONSTRAINT\s+\[([^\]]*)\]\s+FOREIGN\s+KEY\s+\((\[[^\]]*\](?:,\s*\[[^\]]*\])*)\)/g;
|
||||
const re3 = /\[([^\]]*)\]/g;
|
||||
sql = sql.replace(re2, (match: string, ...args: any[]): string => {
|
||||
const fkcols = args[2];
|
||||
let fkname = table;
|
||||
let matches = re3.exec(fkcols);
|
||||
while (matches != null) {
|
||||
fkname += '_' + matches[1];
|
||||
matches = re3.exec(fkcols);
|
||||
}
|
||||
return (args[0] ? args[0] : '') + 'CONSTRAINT [' + fkname + '_fk] FOREIGN KEY (' + fkcols + ')';
|
||||
});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
syncDatabaseStructure(cb) {
|
||||
if (GBConfigService.get("DATABASE_SYNC") === "true") {
|
||||
const alter = (GBConfigService.get("DATABASE_SYNC_ALTER") === "true");
|
||||
const force = (GBConfigService.get("DATABASE_SYNC_FORCE") === "true");
|
||||
logger.trace("Syncing database...");
|
||||
this.sequelize.sync().then(value => {
|
||||
this.sequelize.sync({
|
||||
alter: alter,
|
||||
force: force
|
||||
}).then(value => {
|
||||
logger.trace("Database synced.");
|
||||
cb();
|
||||
});
|
||||
}
|
||||
else {
|
||||
}, err => logger.error(err));
|
||||
} else {
|
||||
logger.trace("Database synchronization is disabled.");
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads all items to start several listeners.
|
||||
* @param cb Instances loaded or error info.
|
||||
|
@ -149,8 +229,8 @@ export class GBCoreService implements IGBCoreService {
|
|||
if (reason.message.indexOf("no such table: GuaribasInstance") != -1) {
|
||||
cb([], null);
|
||||
} else {
|
||||
cb(null, reason);
|
||||
logger.trace(`GuaribasServiceError: ${reason}`);
|
||||
cb(null, reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ import { KBService } from './../../kb.gbapp/services/KBService';
|
|||
import { GBImporter } from "./GBImporter";
|
||||
import { GBCoreService } from "./GBCoreService";
|
||||
import { GBServiceCallback, IGBCoreService, IGBInstance } from "botlib";
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { Promise } from "bluebird";
|
||||
import { GBConfigService } from "./GBConfigService";
|
||||
import { DataTypeUUIDv1 } from "sequelize";
|
||||
|
|
|
@ -41,7 +41,7 @@ const Walk = require("fs-walk");
|
|||
const logger = require("../../../src/logger");
|
||||
|
||||
import { KBService } from './../../kb.gbapp/services/KBService';
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { Promise } from "bluebird";
|
||||
import Fs = require("fs");
|
||||
import Path = require("path");
|
||||
|
|
|
@ -104,6 +104,13 @@ export class GBMinService {
|
|||
|
||||
_this_.core.loadInstances((instances: IGBInstance[], err) => {
|
||||
|
||||
// We are running empty !
|
||||
|
||||
if (!instances) {
|
||||
logger.error('The bot server is running empty.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Gets the authorization key for each instance from Bot Service.
|
||||
|
||||
instances.forEach(instance => {
|
||||
|
@ -350,20 +357,16 @@ export class GBMinService {
|
|||
dirs.forEach(element => {
|
||||
if (element.startsWith('.')) {
|
||||
logger.trace(`Ignoring ${element}...`);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (element.endsWith('.gbot')) {
|
||||
botPackages.push(element);
|
||||
}
|
||||
else if (element.endsWith('.gbapp')) {
|
||||
} else if (element.endsWith('.gbapp')) {
|
||||
gbappPackages.push(element);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
generalPackages.push(element);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
logger.trace(`Starting looking for generalPackages...`);
|
||||
|
@ -372,7 +375,6 @@ export class GBMinService {
|
|||
doIt(e);
|
||||
});
|
||||
|
||||
|
||||
/** Deploys all .gbapp files first. */
|
||||
|
||||
let appPackagesProcessed = 0;
|
||||
|
@ -382,11 +384,14 @@ export class GBMinService {
|
|||
// Skips .gbapp inside deploy folder.
|
||||
if (!e.startsWith('deploy')) {
|
||||
import(e).then(m => {
|
||||
let p = new m.Package();
|
||||
let p = new m.Package() as IGBPackage;
|
||||
p.loadPackage(core, core.sequelize);
|
||||
appPackages.push(p);
|
||||
logger.trace(`App (.gbapp) deployed: ${e}.`);
|
||||
appPackagesProcessed++;
|
||||
}, err => {
|
||||
logger.trace(`Error deploying App (.gbapp): ${e}: ${err}`);
|
||||
appPackagesProcessed++;
|
||||
}).catch(err => {
|
||||
logger.trace(`Error deploying App (.gbapp): ${e}: ${err}`);
|
||||
appPackagesProcessed++;
|
||||
|
@ -396,7 +401,6 @@ export class GBMinService {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
WaitUntil()
|
||||
.interval(1000)
|
||||
.times(10)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
"use strict";
|
||||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
import { GuaribasQuestionAlternate } from './models/index';
|
||||
import { QualityDialog } from './dialogs/QualityDialog';
|
||||
import { FeedbackDialog } from './dialogs/FeedbackDialog';
|
||||
|
@ -42,22 +43,24 @@ import { Sequelize } from 'sequelize-typescript';
|
|||
|
||||
export class GBCustomerSatisfactionPackage implements IGBPackage {
|
||||
sysPackages: IGBPackage[] = null;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
core.sequelize.addModels([
|
||||
GuaribasQuestionAlternate
|
||||
]);
|
||||
}
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
FeedbackDialog.setup(min.bot, min);
|
||||
QualityDialog.setup(min.bot, min);
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
|
@ -55,6 +56,7 @@ import {
|
|||
PrimaryKey,
|
||||
AutoIncrement
|
||||
} from "sequelize-typescript";
|
||||
|
||||
import { GuaribasInstance } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
@Table
|
||||
|
|
|
@ -44,7 +44,6 @@ import { Sequelize } from 'sequelize-typescript';
|
|||
import { IGBCoreService } from 'botlib';
|
||||
|
||||
export class GBKBPackage implements IGBPackage {
|
||||
|
||||
sysPackages: IGBPackage[] = null;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
|
@ -53,22 +52,20 @@ export class GBKBPackage implements IGBPackage {
|
|||
GuaribasQuestion,
|
||||
GuaribasSubject
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
AskDialog.setup(min.bot, min);
|
||||
FaqDialog.setup(min.bot, min);
|
||||
MenuDialog.setup(min.bot, min);
|
||||
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
|
@ -59,7 +60,6 @@ import {
|
|||
import { GuaribasUser } from "../../security.gblib/models";
|
||||
import { GuaribasInstance, GuaribasPackage } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
|
||||
@Table
|
||||
export class GuaribasSubject extends Model<GuaribasSubject> {
|
||||
@PrimaryKey
|
||||
|
@ -107,10 +107,8 @@ export class GuaribasSubject extends Model<GuaribasSubject> {
|
|||
|
||||
@BelongsTo(() => GuaribasPackage)
|
||||
package: GuaribasPackage;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Table
|
||||
export class GuaribasQuestion extends Model<GuaribasQuestion> {
|
||||
@PrimaryKey
|
||||
|
@ -118,42 +116,42 @@ export class GuaribasQuestion extends Model<GuaribasQuestion> {
|
|||
@Column
|
||||
questionId: number;
|
||||
|
||||
@Column({ type: DataType.STRING(64) })
|
||||
@Column(DataType.STRING(64))
|
||||
@Column
|
||||
subject1: string;
|
||||
|
||||
@Column({ type: DataType.STRING(64) })
|
||||
@Column(DataType.STRING(64))
|
||||
@Column
|
||||
subject2: string;
|
||||
|
||||
@Column({ type: DataType.STRING(64) })
|
||||
@Column(DataType.STRING(64))
|
||||
@Column
|
||||
subject3: string;
|
||||
|
||||
@Column({ type: DataType.STRING(64) })
|
||||
@Column(DataType.STRING(64))
|
||||
@Column
|
||||
subject4: string;
|
||||
|
||||
@Column({ type: DataType.STRING(1024) })
|
||||
@Column(DataType.STRING(1024))
|
||||
@Column
|
||||
keywords: string;
|
||||
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
@Column(DataType.STRING(512))
|
||||
from: string;
|
||||
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
@Column(DataType.STRING(512))
|
||||
to: string;
|
||||
|
||||
@Column({ type: DataType.TEXT })
|
||||
@Column(DataType.TEXT)
|
||||
content: string;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
@ForeignKey(() => GuaribasAnswer)
|
||||
@Column
|
||||
|
@ -189,16 +187,16 @@ export class GuaribasAnswer extends Model<GuaribasAnswer> {
|
|||
@Column
|
||||
format: string;
|
||||
|
||||
@Column({ type: DataType.TEXT })
|
||||
@Column(DataType.TEXT)
|
||||
content: string;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
createdAt: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
@HasMany(() => GuaribasQuestion)
|
||||
questions: GuaribasQuestion[];
|
||||
|
|
|
@ -44,7 +44,7 @@ const marked = require("marked");
|
|||
|
||||
|
||||
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { GBConfigService } from './../../core.gbapp/services/GBConfigService';
|
||||
import { GuaribasQuestion, GuaribasAnswer, GuaribasSubject } from "../models";
|
||||
import { GBServiceCallback, IGBCoreService, IGBConversationalService, IGBInstance } from "botlib";
|
||||
|
|
|
@ -34,14 +34,14 @@
|
|||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
|
||||
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib";
|
||||
import { Session } from 'botbuilder';
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { GuaribasUser, GuaribasGroup, GuaribasUserGroup } from "./models";
|
||||
|
||||
export class GBSecurityPackage implements IGBPackage {
|
||||
sysPackages: IGBPackage[] = null;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
core.sequelize.addModels([
|
||||
GuaribasGroup,
|
||||
|
@ -51,17 +51,14 @@ export class GBSecurityPackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,17 +30,17 @@
|
|||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
|
@ -56,8 +56,8 @@ import {
|
|||
PrimaryKey,
|
||||
AutoIncrement
|
||||
} from "sequelize-typescript";
|
||||
import { GuaribasInstance } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
import { GuaribasInstance } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
@Table
|
||||
export class GuaribasUser extends Model<GuaribasUser> {
|
||||
|
@ -75,18 +75,15 @@ export class GuaribasUser extends Model<GuaribasUser> {
|
|||
|
||||
@Column email: string;
|
||||
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
@Column
|
||||
@Column(DataType.STRING(512))
|
||||
internalAddress: string;
|
||||
|
||||
@ForeignKey(() =>
|
||||
GuaribasInstance)
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@BelongsTo(() => GuaribasInstance)
|
||||
instance: GuaribasInstance;
|
||||
|
||||
}
|
||||
|
||||
@Table
|
||||
|
@ -100,7 +97,6 @@ export class GuaribasGroup extends Model<GuaribasGroup> {
|
|||
@Column
|
||||
displayName: string;
|
||||
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
|
|
@ -34,15 +34,12 @@
|
|||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
|
||||
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib";
|
||||
import { Session } from 'botbuilder';
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { WhatsappDirectLine } from "./services/WhatsappDirectLine";
|
||||
|
||||
|
||||
export class GBWhatsappPackage implements IGBPackage {
|
||||
|
||||
sysPackages: IGBPackage[] = null;
|
||||
channel: WhatsappDirectLine;
|
||||
|
||||
|
@ -50,7 +47,6 @@ export class GBWhatsappPackage implements IGBPackage {
|
|||
}
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
}
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
|
@ -58,15 +54,20 @@ export class GBWhatsappPackage implements IGBPackage {
|
|||
// Only loads engine if it is defined on services.json.
|
||||
|
||||
if (min.instance.whatsappBotKey != "") {
|
||||
this.channel = new WhatsappDirectLine(min.botId, min.instance.whatsappBotKey, min.instance.whatsappServiceKey,
|
||||
min.instance.whatsappServiceNumber, min.instance.whatsappServiceUrl, min.instance.whatsappServiceWebhookUrl);
|
||||
this.channel = new WhatsappDirectLine(
|
||||
min.botId,
|
||||
min.instance.whatsappBotKey,
|
||||
min.instance.whatsappServiceKey,
|
||||
min.instance.whatsappServiceNumber,
|
||||
min.instance.whatsappServiceUrl,
|
||||
min.instance.whatsappServiceWebhookUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "botserver",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.30",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -597,9 +597,9 @@
|
|||
}
|
||||
},
|
||||
"botlib": {
|
||||
"version": "0.0.25",
|
||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.0.25.tgz",
|
||||
"integrity": "sha512-GRR4Hk+seayNzEoceoUYxE6MyAo4YjSH/54Cq+P2v0X2toT7jkdggL5ii2bTzJyHqbaiGYwyh0n8ZDInLk8+dg==",
|
||||
"version": "0.0.31",
|
||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.0.31.tgz",
|
||||
"integrity": "sha512-LgWZsgPnEj5kZx5Hp4yM4ntKKUGrx1ONLyhfHsl/gXX2Pz9AMTtskkMmy5llbV2wdipuD85lorDCNez+nZxFlw==",
|
||||
"requires": {
|
||||
"async": "2.6.1",
|
||||
"botbuilder": "3.15.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "botserver",
|
||||
"version": "0.0.29",
|
||||
"version": "0.0.30",
|
||||
"description": "General Bot Community Edition open-core server.",
|
||||
"main": "./src/app.ts",
|
||||
"homepage": "http://www.generalbot.com",
|
||||
|
@ -33,7 +33,7 @@
|
|||
"async": "^2.6.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"botbuilder": "^3.15.0",
|
||||
"botlib": "^0.0.28",
|
||||
"botlib": "^0.0.31",
|
||||
"chokidar": "^2.0.3",
|
||||
"csv-parse": "^2.4.0",
|
||||
"dotenv-extended": "^2.0.2",
|
||||
|
|
|
@ -37,8 +37,9 @@ const UrlJoin = require("url-join");
|
|||
const logger = require("./logger");
|
||||
const express = require("express");
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
import { UniversalBot } from "botbuilder";
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
import { GBConfigService } from "../deploy/core.gbapp/services/GBConfigService";
|
||||
import { GBConversationalService } from "../deploy/core.gbapp/services/GBConversationalService";
|
||||
import { GBMinService } from "../deploy/core.gbapp/services/GBMinService";
|
||||
|
@ -56,7 +57,6 @@ import { IGBPackage } from 'botlib';
|
|||
|
||||
let appPackages = new Array<IGBPackage>();
|
||||
|
||||
|
||||
/**
|
||||
* General Bots open-core entry point.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue