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
ReducerWrapper
Router ⇐ 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> |
|
C
| Promise.<C>
router._configuration : Kind: instance property of Router
C
| null
router.configuration ⇒ Kind: instance property of Router
C
| Promise.<C>
router.getConfiguration() ⇒ Kind: instance method of Router
Promise.<C>
router.updateConfiguration(c) ⇒ Kind: instance method of Router
Param | Type |
---|---|
c | Partial.<C> |
this
router.use(...resolvers) ⇒ 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> |
|
C
| Promise.<C>
router._configuration : Kind: instance property of Router
C
| null
router.configuration ⇒ Kind: instance property of Router
C
| Promise.<C>
router.getConfiguration() ⇒ Kind: instance method of Router
Promise.<C>
router.updateConfiguration(c) ⇒ Kind: instance method of Router
Param | Type |
---|---|
c | Partial.<C> |
this
router.use(...resolvers) ⇒ 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 |
EventEmitter
ReducerWrapper ⇐ 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 |
true
| false
| null
| undefined
| number
| void
RoutingInstruction : Kind: global typedef
object
| Promise.<object>
PostBackDataCallback ⇒ Kind: global typedef
Promise.<RoutingInstruction>
PostBack ⇒ Kind: global typedef
Param | Type |
---|---|
[action] | string |
[data] | object | PostBackDataCallback |
[dispatchSync] | boolean |
RoutingInstruction
| Promise.<RoutingInstruction>
Resolver ⇒ Kind: global typedef
Param | Type |
---|---|
[req] | Request |
[res] | Responder |
[postBack] | PostBack |
Promise.<RoutingInstruction>
Reduce ⇒ Kind: global typedef
Param | Type |
---|---|
[req] | Request |
[res] | Responder |
[postBack] | PostBack |
[path] | string |
object
IRouter : Kind: global typedef
Properties
Name | Type |
---|---|
reduce | Reduce.<S, C> |
object
BotPath : Kind: global typedef
Properties
Name | Type |
---|---|
path | string |
string
| RegExp
| BotPath
RouteExp : Kind: global typedef
Resolver
| RouteExp
| IRouter
Middleware : flow control statement or function
Kind: global typedef
Object.<(string|'_default'), PersonConfiguration>
PersonConfiguration : Kind: global typedef
object
BaseConfiguration : Kind: global typedef
Properties
Name | Type |
---|---|
[persona] | PersonConfiguration |
[gaMeasurementId] | string |
[gaApiSecret] | string |