Classes
- Router ⇐
ReducerWrapper - Router
- ReducerWrapper ⇐
EventEmitter
Typedefs
- RoutingInstruction :
true|false|null|undefined|number|void - PostBackDataCallback ⇒
object|Promise.<object> - PostBack ⇒
Promise.<RoutingInstruction> - Resolver ⇒
RoutingInstruction|Promise.<RoutingInstruction> - Reduce ⇒
Promise.<RoutingInstruction> - IRouter :
object - BotPath :
object - RouteExp :
string|RegExp|BotPath - Middleware :
Resolver|RouteExp|IRouter flow control statement or function
- PersonConfiguration :
Object.<(string|'_default'), PersonConfiguration> - BaseConfiguration :
object
Router ⇐ ReducerWrapper
Kind: global class
Extends: ReducerWrapper
- Router ⇐
ReducerWrapper- new Router()
- new Router([configuration])
- instance
- ._configuration :
C|Promise.<C> - .configuration ⇒
C|null - .getConfiguration() ⇒
C|Promise.<C> - .updateConfiguration(c) ⇒
Promise.<C> - .use(...resolvers) ⇒
this - .reduce(req, res, postBack)
- .emitAction(req, res, action)
- ._configuration :
- static
new Router()
Cascading router
new Router([configuration])
| Param | Type | Default |
|---|---|---|
| [configuration] | C | Promise.<C> | |
router._configuration : C | Promise.<C>
Kind: instance property of Router
router.configuration ⇒ C | null
Kind: instance property of Router
router.getConfiguration() ⇒ C | Promise.<C>
Kind: instance method of Router
router.updateConfiguration(c) ⇒ Promise.<C>
Kind: instance method of Router
| Param | Type |
|---|---|
| c | Partial.<C> |
router.use(...resolvers) ⇒ this
Appends middleware, action handler or another router
Kind: instance method of Router
| Param | Type | Description |
|---|---|---|
| ...resolvers | Middleware | Array.<Middleware> | list of resolvers |
Example
// middlewarerouter.use((req, res, postBack) => Router.CONTINUE);// route with matching regexprouter.use(/help/, (req, res) => {res.text('Hello!');});// route with matching function (the function is considered as matcher// in case of the function accepts zero or one argument)router.use('action', req => req.text() === 'a', (req, res) => {res.text('Hello!');});// use multiple reducersrouter.use('/path', reducer1, reducer2);
router.reduce(req, res, postBack)
Reducer function
Kind: instance method of Router
Overrides: reduce
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| postBack | function |
router.emitAction(req, res, action)
Low level tracking method, which disables the default automatic tracking for a single interaction.
Kind: instance method of Router
| Param | Type | Default |
|---|---|---|
| req | Request | |
| res | Responder | |
| action | string | boolean | null |
Example
const router = new Router();router.on('action', (r, action) => {// will receive the action event});router.use('interaction', (req, res) => {// track 'foo' and 'bar', but not 'interaction'router.emitAction(req, res, 'foo');router.emitAction(req, res, 'bar');});router.use('will-not-be-tracked', (req, res) => {// will stop Processor to fire an "event" event and also router will track nothingrouter.emitAction(req, res, false);});router.use('disables-firing-processor-event', (req, res) => {// will track 'foo-bar'router.emitAction(req, res, 'foo-bar');// will stop Processor to fire an "event" eventres.trackAs(false);});
Router.CONTINUE
Return Router.CONTINUE when action matches your route
Its same as returning true
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.BREAK
Return Router.BREAK when action does not match your route
Its same as returning false
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.END
Returning Router.END constant stops dispatching request
Its same as returning undefined, but not in plugin. Returning undefined in plugin
Kind: static property of Router
Properties
| Type |
|---|
null |
Router.NEXT
Let the plugin wrapper to decide, when end or not
Its same as returning undefined
Kind: static property of Router
Properties
| Type |
|---|
undefined |
Router
Kind: global class
- Router
- new Router()
- new Router([configuration])
- instance
- ._configuration :
C|Promise.<C> - .configuration ⇒
C|null - .getConfiguration() ⇒
C|Promise.<C> - .updateConfiguration(c) ⇒
Promise.<C> - .use(...resolvers) ⇒
this - .reduce(req, res, postBack)
- .emitAction(req, res, action)
- ._configuration :
- static
new Router()
Cascading router
new Router([configuration])
| Param | Type | Default |
|---|---|---|
| [configuration] | C | Promise.<C> | |
router._configuration : C | Promise.<C>
Kind: instance property of Router
router.configuration ⇒ C | null
Kind: instance property of Router
router.getConfiguration() ⇒ C | Promise.<C>
Kind: instance method of Router
router.updateConfiguration(c) ⇒ Promise.<C>
Kind: instance method of Router
| Param | Type |
|---|---|
| c | Partial.<C> |
router.use(...resolvers) ⇒ this
Appends middleware, action handler or another router
Kind: instance method of Router
| Param | Type | Description |
|---|---|---|
| ...resolvers | Middleware | Array.<Middleware> | list of resolvers |
Example
// middlewarerouter.use((req, res, postBack) => Router.CONTINUE);// route with matching regexprouter.use(/help/, (req, res) => {res.text('Hello!');});// route with matching function (the function is considered as matcher// in case of the function accepts zero or one argument)router.use('action', req => req.text() === 'a', (req, res) => {res.text('Hello!');});// use multiple reducersrouter.use('/path', reducer1, reducer2);
router.reduce(req, res, postBack)
Reducer function
Kind: instance method of Router
Overrides: reduce
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| postBack | function |
router.emitAction(req, res, action)
Low level tracking method, which disables the default automatic tracking for a single interaction.
Kind: instance method of Router
| Param | Type | Default |
|---|---|---|
| req | Request | |
| res | Responder | |
| action | string | boolean | null |
Example
const router = new Router();router.on('action', (r, action) => {// will receive the action event});router.use('interaction', (req, res) => {// track 'foo' and 'bar', but not 'interaction'router.emitAction(req, res, 'foo');router.emitAction(req, res, 'bar');});router.use('will-not-be-tracked', (req, res) => {// will stop Processor to fire an "event" event and also router will track nothingrouter.emitAction(req, res, false);});router.use('disables-firing-processor-event', (req, res) => {// will track 'foo-bar'router.emitAction(req, res, 'foo-bar');// will stop Processor to fire an "event" eventres.trackAs(false);});
Router.CONTINUE
Return Router.CONTINUE when action matches your route
Its same as returning true
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.BREAK
Return Router.BREAK when action does not match your route
Its same as returning false
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.END
Returning Router.END constant stops dispatching request
Its same as returning undefined, but not in plugin. Returning undefined in plugin
Kind: static property of Router
Properties
| Type |
|---|
null |
Router.NEXT
Let the plugin wrapper to decide, when end or not
Its same as returning undefined
Kind: static property of Router
Properties
| Type |
|---|
undefined |
ReducerWrapper ⇐ EventEmitter
Kind: global class
Extends: EventEmitter
Emits: ReducerWrapper#event:action
- ReducerWrapper ⇐
EventEmitter
new ReducerWrapper()
Solution for catching events. This is useful for analytics.
Example
const reducer = new ReducerWrapper((req, res) => {res.text('Hello');});reducer.on('action', (senderId, processedAction, text, req, lastAction, skill, res) => {// log action});
reducerWrapper.reduce(req, res, postBack)
Reducer function
Kind: instance method of ReducerWrapper
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| postBack | function |
reducerWrapper.emitAction(req, res, action)
Low level tracking method, which disables the default automatic tracking for a single interaction.
Kind: instance method of ReducerWrapper
| Param | Type | Default |
|---|---|---|
| req | Request | |
| res | Responder | |
| action | string | boolean | null |
Example
const router = new Router();router.on('action', (r, action) => {// will receive the action event});router.use('interaction', (req, res) => {// track 'foo' and 'bar', but not 'interaction'router.emitAction(req, res, 'foo');router.emitAction(req, res, 'bar');});router.use('will-not-be-tracked', (req, res) => {// will stop Processor to fire an "event" event and also router will track nothingrouter.emitAction(req, res, false);});router.use('disables-firing-processor-event', (req, res) => {// will track 'foo-bar'router.emitAction(req, res, 'foo-bar');// will stop Processor to fire an "event" eventres.trackAs(false);});
ReducerWrapper.ReducerWrapper
Kind: static class of ReducerWrapper
new ReducerWrapper([reduce])
Creates an instance of ReducerWrapper.
| Param | Type | Description |
|---|---|---|
| [reduce] | function | the handler function |
RoutingInstruction : true | false | null | undefined | number | void
Kind: global typedef
PostBackDataCallback ⇒ object | Promise.<object>
Kind: global typedef
PostBack ⇒ Promise.<RoutingInstruction>
Kind: global typedef
| Param | Type |
|---|---|
| [action] | string |
| [data] | object | PostBackDataCallback |
| [dispatchSync] | boolean |
Resolver ⇒ RoutingInstruction | Promise.<RoutingInstruction>
Kind: global typedef
| Param | Type |
|---|---|
| [req] | Request |
| [res] | Responder |
| [postBack] | PostBack |
Reduce ⇒ Promise.<RoutingInstruction>
Kind: global typedef
| Param | Type |
|---|---|
| [req] | Request |
| [res] | Responder |
| [postBack] | PostBack |
| [path] | string |
IRouter : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| reduce | Reduce.<S, C> |
BotPath : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| path | string |
RouteExp : string | RegExp | BotPath
Kind: global typedef
Middleware : Resolver | RouteExp | IRouter
flow control statement or function
Kind: global typedef
PersonConfiguration : Object.<(string|'_default'), PersonConfiguration>
Kind: global typedef
BaseConfiguration : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [persona] | PersonConfiguration |
| [gaMeasurementId] | string |
| [gaApiSecret] | string |