@ebenos/framework
Advanced tools
Comparing version 3.2.7 to 3.2.8
@@ -9,2 +9,3 @@ import { Router } from 'express'; | ||
import { WitNLP } from './interfaces/nlp'; | ||
import { ISerializable } from '.'; | ||
export interface UserModel<U extends User> { | ||
@@ -25,2 +26,11 @@ new (...params: any): U; | ||
} | ||
export interface IBaseMessageOptions { | ||
delay: number; | ||
} | ||
export interface IBaseMessage<T extends IBaseMessageOptions> { | ||
type: 'message' | 'typing_on' | 'typing_off' | 'mark_seen'; | ||
id: string; | ||
message?: ISerializable; | ||
options?: Partial<T>; | ||
} | ||
export default abstract class GenericAdapter<U extends User = User> { | ||
@@ -31,2 +41,3 @@ webhook: Router; | ||
protected userModel: UserModel<U | User>; | ||
abstract sender: <T extends IBaseMessageOptions = IBaseMessageOptions>(messages: Array<IBaseMessage<T>>, order: 'ORDERED' | 'UNORDERED') => Promise<any>; | ||
protected providerName: string; | ||
@@ -38,5 +49,2 @@ constructor(providerName: string, userModel?: UserModel<U | User>); | ||
abstract initWebhook(): void; | ||
abstract get sender(): (id: string, message: any, options: any) => Promise<any>; | ||
abstract get startsTyping(): (id: string, ...params: any[]) => Promise<any>; | ||
handover(id: string, ...params: any): void; | ||
userLoader(...args: any): (id: string) => Promise<U>; | ||
@@ -43,0 +51,0 @@ init(routers: InitOptionsRouters, handlers: InitOptionsHandlers<U>): void; |
@@ -34,5 +34,3 @@ "use strict"; | ||
} | ||
handover(id, ...params) { | ||
console.log('Not Implemented'); | ||
} | ||
// Available Actions | ||
userLoader(...args) { | ||
@@ -39,0 +37,0 @@ return (id) => __awaiter(this, void 0, void 0, function* () { |
@@ -16,5 +16,5 @@ /** | ||
import { ActionMiddleware } from './utilities/actions'; | ||
import { UserModel, IRouters, EbonyHandlers } from './adapter'; | ||
import { UserModel, IRouters, EbonyHandlers, IBaseMessage, IBaseMessageOptions } from './adapter'; | ||
import { WitNLP } from './interfaces/nlp'; | ||
export { Module, BotOptions, ActionMiddleware, WitNLP, IRouters, EbonyHandlers, ISerializable, Bot, User, GenericAdapter, UserModel }; | ||
export { Module, BotOptions, ActionMiddleware, WitNLP, IRouters, EbonyHandlers, ISerializable, IBaseMessage, IBaseMessageOptions, Bot, User, GenericAdapter, UserModel }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -19,6 +19,5 @@ import { GenericAdapter, User } from '..'; | ||
send: (message: any, options?: any) => Scenario<A, U>; | ||
handover: (...params: any) => Scenario<A, U>; | ||
} | ||
export interface Action { | ||
call: string; | ||
call: 'message' | 'wait' | 'typing_on' | 'typing_off' | 'mark_seen' | 'handover'; | ||
params: any[]; | ||
@@ -25,0 +24,0 @@ } |
@@ -21,4 +21,4 @@ "use strict"; | ||
types, | ||
typeAndWait, | ||
handover | ||
typeAndWait | ||
// handover | ||
}; | ||
@@ -38,24 +38,4 @@ return scenarios; | ||
try { | ||
let waiter = 0; | ||
for (const action of this._actions) { | ||
const { call, params } = action; | ||
switch (call) { | ||
case 'handover': | ||
yield this.adapter.handover(...params); | ||
continue; | ||
case 'wait': | ||
waiter += params[0]; | ||
continue; | ||
case 'sender': | ||
params[2].delay = waiter; | ||
yield this.adapter.sender(...params); | ||
continue; | ||
case 'startsTyping': | ||
if (waiter) { | ||
waiter += 5; | ||
} | ||
yield this.adapter.startsTyping(params[0], waiter); | ||
continue; | ||
} | ||
} | ||
const messages = processScenario(this._actions); | ||
yield this.adapter.sender(messages, 'ORDERED'); | ||
} | ||
@@ -79,3 +59,3 @@ catch (err) { | ||
this._actions.push({ | ||
call: 'sender', | ||
call: 'message', | ||
params: [this.id, message, options] | ||
@@ -87,3 +67,3 @@ }); | ||
this._actions.push({ | ||
call: 'startsTyping', | ||
call: 'typing_on', | ||
params: [this.id] | ||
@@ -98,2 +78,43 @@ }); | ||
} | ||
function processScenario(actions) { | ||
let waiter = 0; | ||
const messages = []; | ||
for (const action of actions) { | ||
const { call, params } = action; | ||
switch (call) { | ||
case 'wait': | ||
waiter += params[0]; | ||
continue; | ||
case 'message': | ||
params[2].delay = waiter; | ||
messages.push({ | ||
type: 'message', | ||
id: params[0], | ||
message: params[1], | ||
options: params[2] | ||
}); | ||
waiter = 0; | ||
continue; | ||
case 'typing_on': | ||
messages.push({ | ||
type: 'typing_on', | ||
id: params[0] | ||
}); | ||
continue; | ||
case 'typing_off': | ||
messages.push({ | ||
type: 'typing_off', | ||
id: params[0] | ||
}); | ||
continue; | ||
case 'mark_seen': | ||
messages.push({ | ||
type: 'mark_seen', | ||
id: params[0] | ||
}); | ||
continue; | ||
} | ||
} | ||
return messages; | ||
} | ||
//# sourceMappingURL=scenario.js.map |
{ | ||
"name": "@ebenos/framework", | ||
"version": "3.2.7", | ||
"version": "3.2.8", | ||
"description": "A module-based NodeJS chatbot framework.", | ||
@@ -58,3 +58,3 @@ "main": "./build/index.js", | ||
], | ||
"gitHead": "1e9239885960ea3b8acb85fe6e0031a5ae6595f2" | ||
"gitHead": "8370fb942c51f1dd5ca3303a72390ef9f770024f" | ||
} |
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
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
90043
1459