Classes

RouterReducerWrapper
Router
ReducerWrapperEventEmitter

Typedefs

RoutingInstruction : true | false | null | undefined | number | void
PostBackDataCallbackobject | Promise.<object>
PostBackPromise.<RoutingInstruction>
ResolverRoutingInstruction | Promise.<RoutingInstruction>
ReducePromise.<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

 

new Router()

Cascading router

 

new Router([configuration])

ParamTypeDefault
[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

ParamType
cPartial.<C>
 

router.use(...resolvers) ⇒ this

Appends middleware, action handler or another router

Kind: instance method of Router

ParamTypeDescription
...resolversMiddleware | Array.<Middleware>list of resolvers

Example

// middleware
router.use((req, res, postBack) => Router.CONTINUE);
// route with matching regexp
router.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 reducers
router.use('/path', reducer1, reducer2);
 

router.reduce(req, res, postBack)

Reducer function

Kind: instance method of Router
Overrides: reduce

ParamType
reqRequest
resResponder
postBackfunction
 

router.emitAction(req, res, action)

Low level tracking method, which disables the default automatic tracking for a single interaction.

Kind: instance method of Router

ParamTypeDefault
reqRequest
resResponder
actionstring | booleannull

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 nothing
router.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" event
res.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

 

new Router()

Cascading router

 

new Router([configuration])

ParamTypeDefault
[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

ParamType
cPartial.<C>
 

router.use(...resolvers) ⇒ this

Appends middleware, action handler or another router

Kind: instance method of Router

ParamTypeDescription
...resolversMiddleware | Array.<Middleware>list of resolvers

Example

// middleware
router.use((req, res, postBack) => Router.CONTINUE);
// route with matching regexp
router.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 reducers
router.use('/path', reducer1, reducer2);
 

router.reduce(req, res, postBack)

Reducer function

Kind: instance method of Router
Overrides: reduce

ParamType
reqRequest
resResponder
postBackfunction
 

router.emitAction(req, res, action)

Low level tracking method, which disables the default automatic tracking for a single interaction.

Kind: instance method of Router

ParamTypeDefault
reqRequest
resResponder
actionstring | booleannull

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 nothing
router.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" event
res.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

 

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

ParamType
reqRequest
resResponder
postBackfunction
 

reducerWrapper.emitAction(req, res, action)

Low level tracking method, which disables the default automatic tracking for a single interaction.

Kind: instance method of ReducerWrapper

ParamTypeDefault
reqRequest
resResponder
actionstring | booleannull

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 nothing
router.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" event
res.trackAs(false);
});
 

ReducerWrapper.ReducerWrapper

Kind: static class of ReducerWrapper

 

new ReducerWrapper([reduce])

Creates an instance of ReducerWrapper.

ParamTypeDescription
[reduce]functionthe 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

ParamType
[action]string
[data]object | PostBackDataCallback
[dispatchSync]boolean
 

Resolver ⇒ RoutingInstruction | Promise.<RoutingInstruction>

Kind: global typedef

ParamType
[req]Request
[res]Responder
[postBack]PostBack
 

Reduce ⇒ Promise.<RoutingInstruction>

Kind: global typedef

ParamType
[req]Request
[res]Responder
[postBack]PostBack
[path]string
 

IRouter : object

Kind: global typedef
Properties

NameType
reduceReduce.<S, C>
 

BotPath : object

Kind: global typedef
Properties

NameType
pathstring
 

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

NameType
[persona]PersonConfiguration
[gaMeasurementId]string
[gaApiSecret]string