Merge remote-tracking branch 'remotes/origin/master' into MigrationToBotFmwV4
2
.github/ISSUE_TEMPLATE/requirement
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
**Description**
|
||||
A clear and concise description of what the requirement is.
|
34
README.md
|
@ -1,5 +1,6 @@
|
|||

|
||||
|
||||
|
||||
Welcome to General Bot Community Edition
|
||||
----------------
|
||||
|
||||
|
@ -11,6 +12,17 @@ Everyone can create bots by just copying and pasting some files and using their
|
|||
favorite tools like Excel (or any text editor) or Photoshop (or any image
|
||||
editor).
|
||||
|
||||
Package Quick Reference
|
||||
------------
|
||||
|Whatsapp|Web|Core|KB|
|
||||
|----|-----|----|----|
|
||||
|[whatsapp.gblib](https://github.com/pragmatismo-io/BotServer/tree/master/deploy/whatsapp.gblib)|[default.gbui](https://github.com/pragmatismo-io/BotServer/tree/master/deploy/default.gbui)|[core.gbapp](https://github.com/pragmatismo-io/BotServer/tree/master/deploy/core.gbapp)|[kb.gbapp](https://github.com/pragmatismo-io/BotServer/tree/master/deploy/kb.gbapp)|
|
||||
|
||||
Package Architecture
|
||||
--------------------
|
||||
|
||||

|
||||
|
||||
### What is Bot Server?
|
||||
|
||||
Bot Server accelerates the process of developing a bot. It provisions all code
|
||||
|
@ -21,11 +33,23 @@ a zip file, editing and uploading it back to the server (deploying process) with
|
|||
no code. The Bot Server also provides a framework to develop bot packages in a more
|
||||
advanced fashion writing custom code in editors like Visual Studio Code, Atom or Brackets.
|
||||
|
||||

|
||||
|
||||
### The same build process for everyone
|
||||
|
||||
GeneralBots aims to delivery bots in azure in a very easy and fast fashion. Use
|
||||
Office tools like Word or Excel to edit your Bot - using code (JavaScript or TypeScript) just to empower custom requirements.
|
||||
|
||||
|
||||
#### Use Excel for Quick edits
|
||||
|
||||

|
||||
|
||||
#### Use Visual Studio for a complete .gbai package building system
|
||||
|
||||

|
||||
|
||||
|
||||
How To
|
||||
------
|
||||
|
||||
|
@ -72,6 +96,11 @@ Note:
|
|||
|
||||
* Whenever you are ready to turn your open-source bot ideas in form of .gbapp (source-code) and artifacts like .gbkb, .gbtheme, .gbot or the .gbai full package read [CONTRIBUTING.md](https://github.com/pragmatismo-io/BotServer/blob/master/CONTRIBUTING.md) about performing Pull Requests (PR) and creating other public custom packages repositories of your own personal or organization General Bot Community Edition powered packages.
|
||||
|
||||
### Running unit tests
|
||||
|
||||
1. Enter the BotServer root folder.
|
||||
2. Run tests by `npm test`.
|
||||
|
||||
### Just copy the source code to your machine
|
||||
|
||||
1. [Download] the Zip file of (https://codeload.github.com/pragmatismo-io/BotServer/zip/master)
|
||||
|
@ -89,6 +118,7 @@ the UI application itself (HTML & JS).
|
|||
Package Types
|
||||
-------------
|
||||
|
||||
|
||||
### .gbai
|
||||
|
||||
Embraces all packages types (content, logic & conversation) into a pluggable bot
|
||||
|
@ -166,8 +196,8 @@ here is a list of admin commands related to deploying .gb* files.
|
|||
### Credits & Inspiration
|
||||
|
||||
* Rodrigo Rodriguez (me@rodrigorodriguez.com) - Coding, Docs & Architecture.
|
||||
* David Lerner (david.lerner@hotmail.com) - UI, UX & Theming
|
||||
* Eduardo Romeiro (eromeirosp@outlook.com) - Content & UX
|
||||
* David Lerner (david.lerner@hotmail.com) - UI, UX & Theming.
|
||||
* Eduardo Romeiro (eromeirosp@outlook.com) - Content & UX.
|
||||
* Jorge Ramos (jramos@pobox.com) - Coding, Docs & Architecture.
|
||||
|
||||
Powered by Microsoft [BOT Framework](https://dev.botframework.com/) and [Azure](http://www.azure.com).
|
||||
|
|
11
VERSION.md
|
@ -1,5 +1,16 @@
|
|||
# Release History
|
||||
|
||||
## Version 0.0.31
|
||||
|
||||
- FIX: Updated dependencies versions.
|
||||
|
||||
## 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.
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
"use strict";
|
||||
|
||||
const UrlJoin = require("url-join");
|
||||
|
||||
import { AzureSearch } from "pragmatismo-io-framework";
|
||||
const { DialogSet, TextPrompt, NumberPrompt } = require('botbuilder-dialogs');
|
||||
const { createTextPrompt, createNumberPrompt } = require('botbuilder-prompts');
|
||||
|
|
|
@ -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 { 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, dc: any): void {
|
||||
|
||||
onNewSession(min: GBMinInstance, dc: any): 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 { 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, dc: any): void {
|
||||
|
||||
onNewSession(min: GBMinInstance, dc: any): 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,6 +112,8 @@ export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInst
|
|||
|
||||
@Column kb: string;
|
||||
|
||||
@Column(DataType.STRING(512)) nlpServerUrl: string;
|
||||
|
||||
@Column
|
||||
nlpAppId: string;
|
||||
|
||||
|
@ -131,28 +134,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
|
||||
|
@ -169,16 +163,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
|
||||
|
@ -195,8 +209,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");
|
||||
|
|
|
@ -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
|
||||
|
|
22
deploy/default.gbui/package-lock.json
generated
|
@ -1430,21 +1430,21 @@
|
|||
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24="
|
||||
},
|
||||
"botframework-directlinejs": {
|
||||
"version": "0.9.15",
|
||||
"resolved": "https://registry.npmjs.org/botframework-directlinejs/-/botframework-directlinejs-0.9.15.tgz",
|
||||
"integrity": "sha512-uDD5LMCckFKCl8Qr6TMnHjEcl1bKp/MTvlvzRsthvEoNTlzSLo7j8wHLlNYcisr3vPaMx+XAcBniUQjwBLImjQ==",
|
||||
"version": "0.9.16",
|
||||
"resolved": "https://registry.npmjs.org/botframework-directlinejs/-/botframework-directlinejs-0.9.16.tgz",
|
||||
"integrity": "sha512-HcIgeGUBH8zYy2ydlNTgS5GaOkK2BFcfkfSxgVWnF2nV0eIIE2nOepHfAYVtv70zQSX0dU9CedUNgQW343AA6Q==",
|
||||
"requires": {
|
||||
"rxjs": "5.4.3"
|
||||
}
|
||||
},
|
||||
"botframework-webchat": {
|
||||
"version": "0.13.1",
|
||||
"resolved": "https://registry.npmjs.org/botframework-webchat/-/botframework-webchat-0.13.1.tgz",
|
||||
"integrity": "sha512-hF80h8xxvic8vgH0FnLY+zAgs17mAf4YKG8+Z0EP8MGXE4KhwCnLwntklhc0WUUY7afoOu+14yc4NBksVOSWuA==",
|
||||
"version": "0.14.3-master.2cc3c75",
|
||||
"resolved": "https://registry.npmjs.org/botframework-webchat/-/botframework-webchat-0.14.3-master.2cc3c75.tgz",
|
||||
"integrity": "sha512-aJmxAd2oPef9Jih1Ws+ebWJi1lHnCkC3OKawaAVCL6+yu7YeTqrCcPws9G2d8uUiqUzLJ9bvfKdCA2kDlpAe/A==",
|
||||
"requires": {
|
||||
"adaptivecards": "1.0.0",
|
||||
"bluebird": "3.5.1",
|
||||
"botframework-directlinejs": "0.9.15",
|
||||
"botframework-directlinejs": "0.9.16",
|
||||
"core-js": "2.4.1",
|
||||
"jspeech": "0.1.1",
|
||||
"markdown-it": "8.3.1",
|
||||
|
@ -1455,7 +1455,7 @@
|
|||
"redux": "3.7.2",
|
||||
"redux-observable": "0.13.0",
|
||||
"rxjs": "5.4.3",
|
||||
"simple-update-in": "1.2.0",
|
||||
"simple-update-in": "1.3.0",
|
||||
"tslib": "1.7.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -9876,9 +9876,9 @@
|
|||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
|
||||
},
|
||||
"simple-update-in": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-in/-/simple-update-in-1.2.0.tgz",
|
||||
"integrity": "sha512-a6s2H/Px+TXHlJG6FvBpVQU4qnz2BFjMzPfuzdqnGabKUntbIeRknTasCwlWKrXhD1QBSPZ9XoiGF8EpRLjpiQ=="
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-in/-/simple-update-in-1.3.0.tgz",
|
||||
"integrity": "sha512-XQdzyPAjHeqcBDJfUBKgfnurtE9Z/PC7Jh73DAiNlS4vMkdVTrtNpg5GJEGSDOtJ5LPQdZ/BWTx5GNzsP89mlA=="
|
||||
},
|
||||
"slash": {
|
||||
"version": "1.0.0",
|
||||
|
|
|
@ -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
|
||||
|
@ -84,7 +84,7 @@ export class GuaribasSubject extends Model<GuaribasSubject> {
|
|||
@BelongsTo(() => GuaribasSubject, "parentSubjectId")
|
||||
parentSubject: GuaribasSubject;
|
||||
|
||||
@HasMany(() => GuaribasSubject, {foreignKey: "parentSubjectId"})
|
||||
@HasMany(() => GuaribasSubject, { foreignKey: "parentSubjectId" })
|
||||
childrenSubjects: GuaribasSubject[];
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
|
@ -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[];
|
||||
|
|
|
@ -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,12 +97,11 @@ export class GuaribasGroup extends Model<GuaribasGroup> {
|
|||
@Column
|
||||
displayName: string;
|
||||
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@BelongsTo(() => GuaribasInstance )
|
||||
@BelongsTo(() => GuaribasInstance)
|
||||
instance: GuaribasInstance;
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
// Ignore own messages.
|
||||
// TODO: this.botId instead of "general-bot-9672a8d3"
|
||||
activities = activities.filter((m) => { return m.from.id === "general-bot-9672a8d3" && m.type === "message" });
|
||||
activities = activities.filter((m) => { return (m.from.id === "GeneralBot-Netshoes") && m.type === "message" });
|
||||
|
||||
if (activities.length) {
|
||||
|
||||
|
|
BIN
docs/images/general-bots-block-architecture.png
Normal file
After Width: | Height: | Size: 1 MiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 78 KiB |
BIN
docs/images/general-bots-stack.png
Normal file
After Width: | Height: | Size: 1,013 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 480 B After Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 855 B After Width: | Height: | Size: 855 B |