Classes

RouterReducerWrapper
ReducerWrapperEventEmitter

Typedefs

Resolver : function
IRouter : object
BotPath : object
Middleware : Resolver | string | RegExp | IRouter | BotPath

flow control statement or function

 

Router ⇐ ReducerWrapper

Kind: global class
Extends: ReducerWrapper

 

new Router()

Cascading router

 

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

// 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

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.trackAs(req, res, 'foo');
    router.trackAs(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.trackAs(req, res, false);
});

router.use('disables-firing-processor-event', (req, res) => {
    // will track 'foo-bar'
    router.trackAs(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

Kind: static property of Router
Properties

Type
null
 

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

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.trackAs(req, res, 'foo');
    router.trackAs(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.trackAs(req, res, false);
});

router.use('disables-firing-processor-event', (req, res) => {
    // will track 'foo-bar'
    router.trackAs(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.

Param Type Description
[reduce] function the handler function
 

Resolver : function

Kind: global typedef

Param Type
[req] Request
[res] Responder
[postBack] function
 

IRouter : object

Kind: global typedef
Properties

Name Type
reduce function
 

BotPath : object

Kind: global typedef
Properties

Name Type
path string
 

Middleware : Resolver | string | RegExp | IRouter | BotPath

flow control statement or function

Kind: global typedef

results matching ""

    No results matching ""