@ebenos/framework
Advanced tools
Comparing version 3.4.5 to 4.0.0-alpha.1
@@ -1,7 +0,4 @@ | ||
import { Router } from 'express'; | ||
import PostbackRouter from './routers/PostbackRouter'; | ||
import ReferralsRouter from './routers/ReferralsRouter'; | ||
import TextMatcher from './routers/TextMatcher'; | ||
import User from './models/User'; | ||
import { IUser } from './models/UserSchema'; | ||
import { GenericAttachment } from './interfaces/attachment'; | ||
@@ -11,6 +8,2 @@ import { WitNLP } from './interfaces/nlp'; | ||
import { IInteraction } from './interfaces/interactions'; | ||
export interface UserModel<U extends User> { | ||
new (...params: any): U; | ||
findByProviderId: (id: string) => Promise<IUser | null>; | ||
} | ||
export interface IRouters { | ||
@@ -21,4 +14,4 @@ PostbackRouter?: PostbackRouter; | ||
} | ||
export interface EbonyHandlers<U extends User> { | ||
attachment?: (user: User, attachment: GenericAttachment) => Promise<any>; | ||
export interface EbonyHandlers<U> { | ||
attachment?: (user: U, attachment: GenericAttachment) => Promise<any>; | ||
text?: (message: { | ||
@@ -39,17 +32,14 @@ text: string; | ||
} | ||
export default abstract class GenericAdapter<U extends User = User, Operations = { | ||
export default abstract class GenericAdapter<Operations = { | ||
handover: (id: string) => Promise<any>; | ||
}> { | ||
webhook: Router; | ||
protected handlers: EbonyHandlers<U>; | ||
protected handlers: EbonyHandlers<any>; | ||
protected routers: IRouters; | ||
protected userModel: UserModel<U | User>; | ||
abstract operations: Operations; | ||
abstract sender: (actions: Array<IInteraction<any>>, type: 'ORDERED' | 'UNORDERED') => Promise<void>; | ||
constructor(userModel?: UserModel<U | User>); | ||
constructor(); | ||
setRouters(routers: IRouters): void; | ||
setHandlers(handlers: EbonyHandlers<U>): void; | ||
abstract initWebhook(): void; | ||
userLoader(...args: any): (id: string) => Promise<U>; | ||
init(routers: InitOptionsRouters, handlers: InitOptionsHandlers<U>): void; | ||
setHandlers<U>(handlers: EbonyHandlers<U>): void; | ||
abstract initialization(): void; | ||
init<U>(routers: InitOptionsRouters, handlers: InitOptionsHandlers<U>): void; | ||
} | ||
@@ -61,3 +51,3 @@ interface InitOptionsRouters { | ||
} | ||
interface InitOptionsHandlers<U extends User> { | ||
interface InitOptionsHandlers<U> { | ||
text: (message: { | ||
@@ -64,0 +54,0 @@ text: string; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const express_1 = require("express"); | ||
const User_1 = __importDefault(require("./models/User")); | ||
class GenericAdapter { | ||
constructor(userModel = User_1.default) { | ||
this.webhook = express_1.Router(); | ||
constructor() { | ||
this.handlers = {}; | ||
this.routers = {}; | ||
this.userModel = userModel; | ||
} | ||
@@ -30,21 +14,2 @@ setRouters(routers) { | ||
} | ||
// Available Actions | ||
userLoader(...args) { | ||
return (id) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const userData = yield this.userModel.findByProviderId(id); | ||
if (!userData) { | ||
const newUser = new this.userModel({ | ||
id | ||
}); | ||
newUser.save(); | ||
return newUser; | ||
} | ||
return new this.userModel(userData); | ||
} | ||
catch (err) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
init(routers, handlers) { | ||
@@ -59,3 +24,3 @@ this.setRouters({ | ||
}); | ||
this.initWebhook(); | ||
this.initialization(); | ||
} | ||
@@ -62,0 +27,0 @@ } |
@@ -16,4 +16,3 @@ /** | ||
*/ | ||
export default class Bot<U extends User> { | ||
readonly app: import("express-serve-static-core").Express; | ||
export default class Bot<U extends User<any>> { | ||
private postbackRouter; | ||
@@ -24,3 +23,2 @@ private referralsRouter; | ||
actions: Actions<U>; | ||
private mongodbUri; | ||
private adapter; | ||
@@ -32,16 +30,10 @@ private yesNoAnswer; | ||
*/ | ||
constructor(adapter: GenericAdapter<U>, options: BotOptions<U>); | ||
constructor(adapter: GenericAdapter, options: BotOptions<U>); | ||
/** | ||
* This initiates the webhook and the bot starts listening | ||
*/ | ||
start({ port, route }: { | ||
port?: number | undefined; | ||
route?: string | undefined; | ||
}): Promise<void>; | ||
/** | ||
* Adds a Module to the chatbot | ||
*/ | ||
addModule(module: Module<U>): void; | ||
scenario(user: U): Scenario<GenericAdapter<U>, U>; | ||
scenario(user: U): Scenario<GenericAdapter>; | ||
private compileRules; | ||
} | ||
//# sourceMappingURL=bot.d.ts.map |
@@ -10,11 +10,2 @@ "use strict"; | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -24,4 +15,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const mongoose_1 = require("mongoose"); | ||
const express_1 = __importDefault(require("express")); | ||
const attachment_1 = __importDefault(require("./handlers/attachment")); | ||
@@ -37,3 +26,2 @@ const text_1 = __importDefault(require("./handlers/text")); | ||
const scenario_1 = __importDefault(require("./utilities/scenario")); | ||
const server_1 = require("./utilities/server"); | ||
/** | ||
@@ -47,3 +35,2 @@ * The Bot Class | ||
constructor(adapter, options) { | ||
this.app = express_1.default(); | ||
// Routers | ||
@@ -54,5 +41,4 @@ this.postbackRouter = new PostbackRouter_1.default(); | ||
this.textMatcher = new TextMatcher_1.default(); | ||
const { preSendMiddlewares = [], postSendMiddlewares = [], mongodbUri } = options; | ||
const { preSendMiddlewares = [], postSendMiddlewares = [] } = options; | ||
this.actions = new actions_1.default(preSendMiddlewares, postSendMiddlewares); | ||
this.mongodbUri = mongodbUri; | ||
this.adapter = adapter; | ||
@@ -73,25 +59,11 @@ this.complexNlp = defaultNlpHandler; | ||
/** | ||
* This initiates the webhook and the bot starts listening | ||
*/ | ||
start({ port = 3000, route = '/bot' }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Connect to database | ||
yield mongoose_1.connect(this.mongodbUri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
useFindAndModify: false | ||
}); | ||
server_1.start(this.app, port, route, this.adapter); | ||
console.log(`Bot is listening on port: ${port}`); | ||
}); | ||
} | ||
/** | ||
* Adds a Module to the chatbot | ||
*/ | ||
addModule(module) { | ||
const { routes = {}, actions = {}, intents = {}, referrals = {}, text = [], nlp = () => Promise.resolve(), preMiddlewares = [], postMiddlewares = [] } = module; | ||
const { routes = { stringPayloads: {}, objectPayloads: {} }, actions = {}, intents = {}, referrals = {}, text = [], nlp = () => Promise.resolve(), preMiddlewares = [], postMiddlewares = [] } = module; | ||
this.actions.importActions(actions); | ||
this.actions.addMiddlewares('pre', preMiddlewares); | ||
this.actions.addMiddlewares('post', postMiddlewares); | ||
this.postbackRouter.importRoutes(routes); | ||
const postbackRoutes = this.compileRules(routes); | ||
this.postbackRouter.importRoutes(postbackRoutes); | ||
this.intentRouter.importRoutes(intents); | ||
@@ -106,2 +78,20 @@ this.referralsRouter.importRoutes(referrals); | ||
} | ||
compileRules(routes) { | ||
const bot = this; | ||
if (routes === undefined) { | ||
return {}; | ||
} | ||
const postbackRules = { stringPayloads: {}, objectPayloads: {} }; | ||
for (const r in routes.stringPayloads) { | ||
if (postbackRules.stringPayloads) { | ||
postbackRules.stringPayloads[r] = (user, payload) => bot.actions.exec(routes.stringPayloads[r], user, payload); | ||
} | ||
} | ||
for (const r in routes.objectPayloads) { | ||
if (postbackRules.objectPayloads) { | ||
postbackRules.objectPayloads[r] = (user, payload) => bot.actions.exec(routes.objectPayloads[r], user, payload); | ||
} | ||
} | ||
return postbackRules; | ||
} | ||
} | ||
@@ -108,0 +98,0 @@ exports.default = Bot; |
@@ -13,7 +13,4 @@ /** | ||
declare type yes_noAnswerF = (...params: any) => Promise<any>; | ||
declare function attachmentHandler<U extends User>( | ||
yes_noAnswer?: yes_noAnswerF, | ||
messages?: any | ||
): (user: U, attachment: GenericAttachment) => any; | ||
declare function attachmentHandler<U extends User<any>>(yes_noAnswer?: yes_noAnswerF, messages?: any): (user: U, attachment: GenericAttachment) => any; | ||
export default attachmentHandler; | ||
//# sourceMappingURL=attachment.d.ts.map | ||
//# sourceMappingURL=attachment.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,3 +11,3 @@ * ebony-framework | ||
*/ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function defaultYesNo() { | ||
@@ -23,2 +23,2 @@ return Promise.resolve(); | ||
exports.default = attachmentHandler; | ||
//# sourceMappingURL=attachment.js.map | ||
//# sourceMappingURL=attachment.js.map |
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
declare function nlpHandlerFactory<U extends User>(intentRouter: IntentRouter, options?: INLPHandlerOptions): (this: Bot<U>, user: U, message: { | ||
declare function nlpHandlerFactory<U extends User<any>>(intentRouter: IntentRouter, options?: INLPHandlerOptions): (this: Bot<U>, user: U, message: { | ||
text: string; | ||
@@ -25,0 +25,0 @@ }, nlp: WitNLP) => any; |
@@ -19,6 +19,6 @@ /** | ||
*/ | ||
declare type nlpHandlerF<U extends User> = (user: U, message: { | ||
declare type nlpHandlerF<U> = (user: U, message: { | ||
text: string; | ||
}, nlp: WitNLP) => Promise<any>; | ||
export default function textHandlerFactory<U extends User>(matcher?: TextMatcher, nlpHandler?: nlpHandlerF<U>): (this: Bot<U>, message: { | ||
export default function textHandlerFactory<U extends User<any>>(matcher?: TextMatcher, nlpHandler?: nlpHandlerF<U>): (this: Bot<U>, message: { | ||
text: string; | ||
@@ -25,0 +25,0 @@ }, nlp: WitNLP | undefined, user: U) => any; |
@@ -12,11 +12,15 @@ /** | ||
import User from './models/User'; | ||
import DatabaseUser, { userLoader as databaseUserLoader } from './models/DatabaseUser'; | ||
import InMemoryUser, { userLoader as inMemoryUserLoader } from './models/InMemoryUser'; | ||
import GenericAdapter from './adapter'; | ||
import TestAdapter from './tests/test-adapter'; | ||
export { Module, BotOptions, Scenario } from './interfaces/bot'; | ||
export { ISerializable } from './interfaces/elements'; | ||
export { ActionMiddleware } from './utilities/actions'; | ||
export { UserModel, IRouters, EbonyHandlers, IBaseMessage, IBaseMessageOptions } from './adapter'; | ||
export { IRouters, EbonyHandlers, IBaseMessage, IBaseMessageOptions } from './adapter'; | ||
export { WitNLP } from './interfaces/nlp'; | ||
export { GenericAttachment } from './interfaces/attachment'; | ||
export * from './interfaces/interactions'; | ||
export { Bot, User, GenericAdapter }; | ||
export * from './modules'; | ||
export { Bot, User, GenericAdapter, DatabaseUser, databaseUserLoader, InMemoryUser, inMemoryUserLoader, TestAdapter }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -18,2 +18,14 @@ "use strict"; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
@@ -26,3 +38,3 @@ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GenericAdapter = exports.User = exports.Bot = void 0; | ||
exports.TestAdapter = exports.inMemoryUserLoader = exports.InMemoryUser = exports.databaseUserLoader = exports.DatabaseUser = exports.GenericAdapter = exports.User = exports.Bot = void 0; | ||
const bot_1 = __importDefault(require("./bot")); | ||
@@ -32,5 +44,14 @@ exports.Bot = bot_1.default; | ||
exports.User = User_1.default; | ||
const DatabaseUser_1 = __importStar(require("./models/DatabaseUser")); | ||
exports.DatabaseUser = DatabaseUser_1.default; | ||
Object.defineProperty(exports, "databaseUserLoader", { enumerable: true, get: function () { return DatabaseUser_1.userLoader; } }); | ||
const InMemoryUser_1 = __importStar(require("./models/InMemoryUser")); | ||
exports.InMemoryUser = InMemoryUser_1.default; | ||
Object.defineProperty(exports, "inMemoryUserLoader", { enumerable: true, get: function () { return InMemoryUser_1.userLoader; } }); | ||
const adapter_1 = __importDefault(require("./adapter")); | ||
exports.GenericAdapter = adapter_1.default; | ||
const test_adapter_1 = __importDefault(require("./tests/test-adapter")); | ||
exports.TestAdapter = test_adapter_1.default; | ||
__exportStar(require("./interfaces/interactions"), exports); | ||
__exportStar(require("./modules"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,2 @@ export interface GenericAttachment { | ||
} | ||
//# sourceMappingURL=attachment.d.ts.map | ||
//# sourceMappingURL=attachment.d.ts.map |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
//# sourceMappingURL=attachment.js.map | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=attachment.js.map |
import { GenericAdapter, User } from '..'; | ||
import { ActionMiddleware } from '../utilities/actions'; | ||
import { PostbackRoutes } from '../routers/PostbackRouter'; | ||
export interface BotOptions<T extends User> { | ||
export interface BotOptions<T extends User<any>> { | ||
preSendMiddlewares?: Array<ActionMiddleware<T>>; | ||
postSendMiddlewares?: Array<ActionMiddleware<T>>; | ||
mongodbUri: string; | ||
} | ||
export interface Scenario<A extends GenericAdapter<U>, U extends User> { | ||
export interface Scenario<A extends GenericAdapter> { | ||
adapter: A; | ||
@@ -14,10 +12,10 @@ id: string; | ||
_actions: Action[]; | ||
types: () => Scenario<A, U>; | ||
typeAndWait: (millis: number) => Scenario<A, U>; | ||
wait: (millis: number) => Scenario<A, U>; | ||
types: () => Scenario<A>; | ||
typeAndWait: (millis: number) => Scenario<A>; | ||
wait: (millis: number) => Scenario<A>; | ||
end: () => Promise<void>; | ||
send: (message: any, options?: any) => Scenario<A, U>; | ||
seen: () => Scenario<A, U>; | ||
stopTyping: () => Scenario<A, U>; | ||
notify: (...params: any[]) => Scenario<A, U>; | ||
send: (message: any, options?: any) => Scenario<A>; | ||
seen: () => Scenario<A>; | ||
stopTyping: () => Scenario<A>; | ||
notify: (...params: any[]) => Scenario<A>; | ||
} | ||
@@ -28,4 +26,7 @@ export interface Action { | ||
} | ||
export interface Module<T extends User> { | ||
routes?: PostbackRoutes<T>; | ||
export interface Module<T extends User<any>> { | ||
routes?: { | ||
stringPayloads: Record<string, string>; | ||
objectPayloads: Record<string, string>; | ||
}; | ||
actions?: { | ||
@@ -44,2 +45,3 @@ [key: string]: (user: T, ...params: any) => Promise<any>; | ||
nlp?: (...params: any) => Promise<any>; | ||
name: string; | ||
} | ||
@@ -46,0 +48,0 @@ export interface TextRule<T> { |
export interface ISerializable { | ||
serialize: () => any; | ||
} | ||
//# sourceMappingURL=elements.d.ts.map | ||
//# sourceMappingURL=elements.d.ts.map |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
//# sourceMappingURL=elements.js.map | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=elements.js.map |
@@ -11,2 +11,2 @@ export interface WitNLP { | ||
} | ||
//# sourceMappingURL=nlp.d.ts.map | ||
//# sourceMappingURL=nlp.d.ts.map |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
//# sourceMappingURL=nlp.js.map | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=nlp.js.map |
@@ -1,3 +0,3 @@ | ||
import { UserModel, IUser } from './UserSchema'; | ||
export default class User extends UserModel { | ||
import { IUser } from './UserSchema'; | ||
export default class User<DataModel extends IUser> implements IUser { | ||
id: string; | ||
@@ -10,9 +10,9 @@ firstName: string; | ||
handovered: boolean; | ||
private _context; | ||
constructor(data: IUser); | ||
doc: DataModel; | ||
protected _context: any; | ||
constructor(data: DataModel); | ||
get fullname(): string; | ||
get context(): any; | ||
setContext(context: any): Promise<any>; | ||
static findByProviderId(id: string): Promise<IUser | null>; | ||
get context(): Record<string, any>; | ||
} | ||
export declare function userLoader(): Promise<User<any>>; | ||
//# sourceMappingURL=User.d.ts.map |
@@ -12,6 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const UserSchema_1 = require("./UserSchema"); | ||
class User extends UserSchema_1.UserModel { | ||
exports.userLoader = void 0; | ||
class User { | ||
constructor(data) { | ||
super(data); | ||
this.doc = data; | ||
const { firstName = '', lastName = '', gender = 'male', active = true, handovered = false, data: userData = null } = data; | ||
@@ -43,16 +43,10 @@ this.id = data.id; | ||
} | ||
setContext(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this._context = context; | ||
yield UserSchema_1.UserModel.collection.updateOne({ id: this.id }, { $set: { context } }); | ||
return context; | ||
}); | ||
} | ||
static findByProviderId(id) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield UserSchema_1.UserModel.findOne({ id }); | ||
}); | ||
} | ||
} | ||
exports.default = User; | ||
function userLoader() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
throw new Error('Not Implemented!'); | ||
}); | ||
} | ||
exports.userLoader = userLoader; | ||
//# sourceMappingURL=User.js.map |
@@ -12,3 +12,3 @@ import { Document } from 'mongoose'; | ||
} | ||
export declare const UserModel: import('mongoose').Model<IUser & Document, {}>; | ||
//# sourceMappingURL=UserSchema.d.ts.map | ||
export declare const UserModel: import("mongoose").Model<IUser & Document, {}>; | ||
//# sourceMappingURL=UserSchema.d.ts.map |
@@ -1,19 +0,16 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UserModel = void 0; | ||
const mongoose_1 = require('mongoose'); | ||
const userSchema = new mongoose_1.Schema( | ||
{ | ||
id: String, | ||
firstName: String, | ||
lastName: String, | ||
gender: String, | ||
context: mongoose_1.Schema.Types.Mixed, | ||
active: Boolean, | ||
handovered: Boolean, | ||
data: mongoose_1.Schema.Types.Mixed | ||
}, | ||
{ timestamps: { createdAt: 'registeredOn', updatedAt: 'lastUpdate' } } | ||
); | ||
const mongoose_1 = require("mongoose"); | ||
const userSchema = new mongoose_1.Schema({ | ||
id: String, | ||
firstName: String, | ||
lastName: String, | ||
gender: String, | ||
context: mongoose_1.Schema.Types.Mixed, | ||
active: Boolean, | ||
handovered: Boolean, | ||
data: mongoose_1.Schema.Types.Mixed | ||
}, { timestamps: { createdAt: 'registeredOn', updatedAt: 'lastUpdate' } }); | ||
exports.UserModel = mongoose_1.model('User', userSchema); | ||
//# sourceMappingURL=UserSchema.js.map | ||
//# sourceMappingURL=UserSchema.js.map |
@@ -22,4 +22,4 @@ /** | ||
*/ | ||
getRoute(route: string): false | ((...args: any[]) => any); | ||
getRoute(route: string): ((...args: any[]) => any) | false; | ||
} | ||
//# sourceMappingURL=BasicRouter.d.ts.map | ||
//# sourceMappingURL=BasicRouter.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,3 +11,3 @@ * ebony-framework | ||
*/ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -37,2 +37,2 @@ * A Basic Router Class | ||
exports.default = BasicRouter; | ||
//# sourceMappingURL=BasicRouter.js.map | ||
//# sourceMappingURL=BasicRouter.js.map |
@@ -10,3 +10,2 @@ /** | ||
*/ | ||
import User from '../models/User'; | ||
import BasicRouter from './BasicRouter'; | ||
@@ -23,3 +22,5 @@ /** | ||
*/ | ||
constructor({ field }: { field?: string | undefined }); | ||
constructor({ field }: { | ||
field: string; | ||
}); | ||
/** | ||
@@ -31,4 +32,4 @@ * | ||
*/ | ||
getContextRoute<U extends User = User>(user: U, ...params: any[]): any; | ||
getContextRoute<U>(user: U, ...params: any[]): any | false; | ||
} | ||
//# sourceMappingURL=ContextRouter.d.ts.map | ||
//# sourceMappingURL=ContextRouter.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,10 +11,8 @@ * ebony-framework | ||
*/ | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const lodash_1 = require('lodash'); | ||
const BasicRouter_1 = __importDefault(require('./BasicRouter')); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = require("lodash"); | ||
const BasicRouter_1 = __importDefault(require("./BasicRouter")); | ||
/** | ||
@@ -46,3 +44,3 @@ * A ContextRouter | ||
if (func) { | ||
return func(user.id, user, ...params); | ||
return func(user, ...params); | ||
} | ||
@@ -53,2 +51,2 @@ return false; | ||
exports.default = ContextRouter; | ||
//# sourceMappingURL=ContextRouter.js.map | ||
//# sourceMappingURL=ContextRouter.js.map |
@@ -16,4 +16,4 @@ /** | ||
export default class IntentRouter extends BasicRouter { | ||
intentRouter<U>(user: U, msg: any, nlp: WitNLP): false | ((...args: any[]) => any); | ||
intentRouter<U>(user: U, msg: any, nlp: WitNLP): ((...args: any[]) => any) | false; | ||
} | ||
//# sourceMappingURL=IntentRouter.d.ts.map | ||
//# sourceMappingURL=IntentRouter.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,9 +11,7 @@ * ebony-framework | ||
*/ | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const BasicRouter_1 = __importDefault(require('./BasicRouter')); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const BasicRouter_1 = __importDefault(require("./BasicRouter")); | ||
/** | ||
@@ -42,2 +40,2 @@ * Intent router class | ||
exports.default = IntentRouter; | ||
//# sourceMappingURL=IntentRouter.js.map | ||
//# sourceMappingURL=IntentRouter.js.map |
import User from '../models/User'; | ||
export interface PostbackRoutes<T extends User> { | ||
export interface PostbackRoutes<T extends User<any>> { | ||
stringPayloads?: { | ||
[key: string]: (user: T) => Promise<any>; | ||
[key: string]: (user: T, payload?: string) => Promise<any>; | ||
}; | ||
@@ -19,6 +19,6 @@ objectPayloads?: { | ||
*/ | ||
importRoutes<U extends User>({ stringPayloads, objectPayloads }: PostbackRoutes<U>): void; | ||
stringPayloadHandler<U extends User>(payload: string, user: U): any; | ||
objectPayloadHandler<U extends User>(payload: string, user: U): any; | ||
importRoutes<U extends User<any>>({ stringPayloads, objectPayloads }: PostbackRoutes<U>): void; | ||
stringPayloadHandler<U>(payload: string, user: U): any; | ||
objectPayloadHandler<U>(payload: string, user: U): any; | ||
} | ||
//# sourceMappingURL=PostbackRouter.d.ts.map | ||
//# sourceMappingURL=PostbackRouter.d.ts.map |
@@ -1,8 +0,6 @@ | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -17,3 +15,3 @@ * ebony-framework | ||
*/ | ||
const BasicRouter_1 = __importDefault(require('./BasicRouter')); | ||
const BasicRouter_1 = __importDefault(require("./BasicRouter")); | ||
/** | ||
@@ -54,3 +52,4 @@ * A Postback Router | ||
throw new Error(`Unknown payload: ${payload}`); | ||
} catch (err) { | ||
} | ||
catch (err) { | ||
if (err instanceof SyntaxError) { | ||
@@ -64,2 +63,2 @@ throw new Error(`[objectPayloadHandler] Payload: ${payload} is not JSON`); | ||
exports.default = PostbackRouter; | ||
//# sourceMappingURL=PostbackRouter.js.map | ||
//# sourceMappingURL=PostbackRouter.js.map |
@@ -11,6 +11,5 @@ /** | ||
import BasicRouter from './BasicRouter'; | ||
import User from '../models/User'; | ||
export default class ReferralsRouter extends BasicRouter { | ||
referralsRouter<U extends User>(user: U, referral: any): any; | ||
referralsRouter<U>(user: U, referral: Record<string, any>): any; | ||
} | ||
//# sourceMappingURL=ReferralsRouter.d.ts.map |
@@ -23,4 +23,6 @@ /** | ||
importRules(rules: ITextRule[]): void; | ||
ruleMatcher(message: { text: string }): false | ((...param: any[]) => any); | ||
ruleMatcher(message: { | ||
text: string; | ||
}): ((...param: any[]) => any) | false; | ||
} | ||
//# sourceMappingURL=TextMatcher.d.ts.map | ||
//# sourceMappingURL=TextMatcher.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,3 +11,3 @@ * ebony-framework | ||
*/ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -39,2 +39,2 @@ * A Text Matcher | ||
exports.default = TextMatcher; | ||
//# sourceMappingURL=TextMatcher.js.map | ||
//# sourceMappingURL=TextMatcher.js.map |
@@ -11,29 +11,21 @@ /** | ||
import User from '../models/User'; | ||
declare type Action<T extends User> = (user: T, ...params: any) => Promise<any>; | ||
interface ActionsStore<T extends User> { | ||
[key: string]: Action<T>; | ||
declare type Action<U extends User<any>> = (user: U, ...params: any) => Promise<any>; | ||
interface ActionsStore<U extends User<any>> { | ||
[key: string]: Action<U>; | ||
} | ||
export declare type ActionMiddleware<T extends User> = ( | ||
actionName: string, | ||
user: T, | ||
params: any[], | ||
next: () => any | ||
) => any; | ||
export declare type ActionMiddleware<U extends User<any>> = (actionName: string, user: U, params: any[], next: () => any) => any; | ||
/** | ||
* The Actions Class | ||
*/ | ||
export default class Actions<T extends User> { | ||
export default class Actions<U extends User<any>> { | ||
private actions; | ||
private preMiddlewares; | ||
private postMiddlewares; | ||
constructor( | ||
preMiddlewares?: Array<ActionMiddleware<T>>, | ||
postMiddlewares?: Array<ActionMiddleware<T>> | ||
); | ||
addMiddleware(type: 'pre' | 'post', middleware: ActionMiddleware<T>): void; | ||
addMiddlewares(type: 'pre' | 'post', middlewares: Array<ActionMiddleware<T>>): void; | ||
constructor(preMiddlewares?: Array<ActionMiddleware<U>>, postMiddlewares?: Array<ActionMiddleware<U>>); | ||
addMiddleware(type: 'pre' | 'post', middleware: ActionMiddleware<U>): void; | ||
addMiddlewares(type: 'pre' | 'post', middlewares: Array<ActionMiddleware<U>>): void; | ||
/** | ||
* Adds actions to the bot | ||
*/ | ||
importActions(actions?: ActionsStore<T>): void; | ||
importActions(actions?: ActionsStore<U>): void; | ||
private nextFactory; | ||
@@ -43,5 +35,5 @@ /** | ||
*/ | ||
exec(actionName: string, user: T, ...params: any): Promise<void>; | ||
exec(actionName: string, user: U, ...params: any[]): Promise<void>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=actions.d.ts.map | ||
//# sourceMappingURL=actions.d.ts.map |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
/** | ||
@@ -11,34 +11,12 @@ * ebony-framework | ||
*/ | ||
var __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator['throw'](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -85,18 +63,18 @@ * The Actions Class | ||
let i = 0; | ||
const next = () => | ||
__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (middlewares.length <= i) { | ||
if (type === 'pre') { | ||
yield actions[actionName](user, ...params); | ||
} | ||
return; | ||
const next = () => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (middlewares.length <= i) { | ||
if (type === 'pre') { | ||
yield actions[actionName](user, ...params); | ||
} | ||
i = i + 1; | ||
yield middlewares[i - 1](actionName, user, params, next); | ||
return; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}); | ||
i = i + 1; | ||
yield middlewares[i - 1](actionName, user, params, next); | ||
return; | ||
} | ||
catch (err) { | ||
throw err; | ||
} | ||
}); | ||
return next; | ||
@@ -114,5 +92,7 @@ } | ||
yield preNext(); | ||
} catch (err) { | ||
} | ||
catch (err) { | ||
throw err; | ||
} finally { | ||
} | ||
finally { | ||
postNext(); | ||
@@ -127,2 +107,2 @@ } | ||
exports.default = Actions; | ||
//# sourceMappingURL=actions.js.map | ||
//# sourceMappingURL=actions.js.map |
import { Scenario } from '../interfaces/bot'; | ||
import GenericAdapter from '../adapter'; | ||
import User from '../models/User'; | ||
export default function createScenario<U extends User>(id: string, adapter: GenericAdapter<U>): Scenario<GenericAdapter<U, { | ||
handover: (id: string) => Promise<any>; | ||
}>, U>; | ||
export default function createScenario<A extends GenericAdapter>(id: string, adapter: A): Scenario<A>; | ||
//# sourceMappingURL=scenario.d.ts.map |
@@ -62,5 +62,2 @@ "use strict"; | ||
} | ||
finally { | ||
this._actions = []; | ||
} | ||
}); | ||
@@ -67,0 +64,0 @@ } |
import { Application } from 'express'; | ||
import { GenericAdapter, User } from '..'; | ||
export declare function start<U extends User>(app: Application, port: number, route: string, adapter: GenericAdapter<U>): void; | ||
import { GenericAdapter } from '..'; | ||
export declare function start(app: Application, port: number, route: string, adapter: GenericAdapter): void; | ||
//# sourceMappingURL=server.d.ts.map |
{ | ||
"name": "@ebenos/framework", | ||
"version": "3.4.5", | ||
"version": "4.0.0-alpha.1", | ||
"description": "A module-based NodeJS chatbot framework.", | ||
@@ -17,3 +17,4 @@ "main": "./build/index.js", | ||
"prettier:write": "yarn run prettier:base -- --write \"lib/**/*.{ts,tsx}\"", | ||
"lint": "eslint '*/**/*.ts' --quiet --fix -c ../../.eslintrc.js --ignore-path ../../.eslintignore" | ||
"lint": "eslint '*/**/*.ts' --quiet --fix -c ../../.eslintrc.js --ignore-path ../../.eslintignore", | ||
"unit-test": "ts-mocha -p src/tsconfig.json src/tests/**/*.spec.ts" | ||
}, | ||
@@ -36,12 +37,10 @@ "keywords": [ | ||
"@types/body-parser": "^1.17.1", | ||
"@types/express": "^4.17.1", | ||
"@types/lodash": "^4.14.138", | ||
"@types/mongodb": "^3.5.27", | ||
"@types/mongoose": "^5.7.36", | ||
"@types/mongoose": "^5.10.1", | ||
"@types/node-fetch": "^2.5.7", | ||
"body-parser": "^1.19.0", | ||
"express": "^4.17.1", | ||
"lodash": "^4.17.15", | ||
"mongodb": "^3.6.2", | ||
"mongoose": "^5.10.5", | ||
"mongoose": "^5.10.15", | ||
"node-fetch": "^2.6.1" | ||
@@ -57,3 +56,3 @@ }, | ||
], | ||
"gitHead": "048b3816f680c6db9be8223503567c64ffbc89e3" | ||
"gitHead": "04583595fb6aef30da25b21674815e34db7b621b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101379
10
106
1608
2
- Removed@types/express@^4.17.1
- Removedexpress@^4.17.1
- Removed@types/express@4.17.21(transitive)
- Removed@types/express-serve-static-core@4.19.6(transitive)
- Removed@types/http-errors@2.0.4(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removed@types/qs@6.9.17(transitive)
- Removed@types/range-parser@1.2.7(transitive)
- Removed@types/send@0.17.4(transitive)
- Removed@types/serve-static@1.15.7(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcookie@0.7.1(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.1(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedms@2.1.3(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.10(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)
Updated@types/mongoose@^5.10.1
Updatedmongoose@^5.10.15