Classes
- BuildRouter ⇐
Router
- BuildRouter
- Plugins
Constants
Typedefs
- BuildInfo :
object
- Resolver :
object
- Route :
object
- TransformedRoute :
object
- LinksMap :
Map.<(string|number), string>
- Block :
object
- BotConfig :
object
- ConfigStorage :
object
- RouteConfig :
object
- LinkTranslator ⇒
string
- BuildRouterContext :
object
- BotContextExtention :
object
- BotContext :
BotContextExtention
|BuildRouterContext.<C>
- Plugin :
function
- PluginFactory ⇒
Router
|Middleware
- PluginFactoryOptions :
object
Router
BuildRouter ⇐ Kind: global class
Extends: Router
- BuildRouter ⇐
Router
- new BuildRouter()
- new BuildRouter(block, plugins, context, [fetchFn])
- instance
- ._context :
BotContext.<C>
|Promise.<BuildRouterContext.<C>>
- ._resolvedContext :
BotContext.<C>
- ._linksMap :
LinksMap
- ._configStorage :
ConfigStorage
|Promise.<ConfigStorage>
- .keepConfigFor :
number
- .loadBot() ⇒
Promise.<object>
- ._buildBot(block, setConfigTimestamp, lastmod)
- ._createLinksMap(block) ⇒
LinksMap
- ._enabledByRouteConfig(routeConfig)
- ._getIncludedBlockId(route) ⇒
string
|null
- ._getBlockById(staticBlockId) ⇒
Block
|null
- ._getRouteConfig(route) ⇒
RouteConfig
- ._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒
void
- ._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒
Array.<Middleware>
- ._buildRoutes(routes)
- ._lastMessageIndex(resolvers) ⇒
number
- .buildResolvers(resolvers, [route], [buildInfo]) ⇒
Array.<Middleware>
- ._resolverFactory(resolver, context, buildInfo) ⇒
Middleware
- ._context :
- static
new BuildRouter()
Build bot from Wingbot configuration file or snapshot url
new BuildRouter(block, plugins, context, [fetchFn])
Create new router from configuration
Param | Type | Description |
---|---|---|
block | BotConfig | Block | |
plugins | Plugins | custom code blocks resource |
context | BuildRouterContext.<C> | Promise.<BuildRouterContext.<C>> | the building context |
[fetchFn] | fetch | override a request function |
Example
// usage of pluginsconst { BuildRouter, Plugins } = require('wingbot');const dynamoDb = require('./lib/dynamodb');const config = require('./config');const plugins = new Plugins();plugins.register('exampleBlock', async (req, res, postBack) => {await res.run('responseBlockName');});const bot = new BuildRouter({botId: 'b7a71c27-c295-4ab0-b64e-6835b50a0db0',snapshot: 'master',token: 'adjsadlkadjj92n9u9'}, plugins);module.exports = bot;
BotContext.<C>
| Promise.<BuildRouterContext.<C>>
buildRouter._context : Kind: instance property of BuildRouter
BotContext.<C>
buildRouter._resolvedContext : Kind: instance property of BuildRouter
LinksMap
buildRouter._linksMap : Kind: instance property of BuildRouter
ConfigStorage
| Promise.<ConfigStorage>
buildRouter._configStorage : Kind: instance property of BuildRouter
number
buildRouter.keepConfigFor : Timeout, when the router is not checking for new configuration
Kind: instance property of BuildRouter
Promise.<object>
buildRouter.loadBot() ⇒ Loads conversation configuration
Kind: instance method of BuildRouter
buildRouter._buildBot(block, setConfigTimestamp, lastmod)
Kind: instance method of BuildRouter
Param | Type | Default |
---|---|---|
block | Block | |
setConfigTimestamp | number | |
lastmod | string | "-" |
LinksMap
buildRouter._createLinksMap(block) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
block | Block |
buildRouter._enabledByRouteConfig(routeConfig)
Kind: instance method of BuildRouter
Param | Type |
---|---|
routeConfig | RouteConfig |
string
| null
buildRouter._getIncludedBlockId(route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | Route |
Block
| null
buildRouter._getBlockById(staticBlockId) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
staticBlockId | string |
RouteConfig
buildRouter._getRouteConfig(route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | TransformedRoute |
void
buildRouter._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
linksMap | LinksMap |
includedBlock | Block |
route | TransformedRoute |
Array.<Middleware>
buildRouter._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | TransformedRoute |
nextRouteIsSameResponder | boolean |
includedBlockId | string |
buildRouter._buildRoutes(routes)
Kind: instance method of BuildRouter
Param | Type |
---|---|
routes | Array.<TransformedRoute> |
number
buildRouter._lastMessageIndex(resolvers) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
resolvers | Array.<Resolver> |
Array.<Middleware>
buildRouter.buildResolvers(resolvers, [route], [buildInfo]) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
resolvers | Array.<Resolver> |
[route] | TransformedRoute |
[buildInfo] | BuildInfo |
Middleware
buildRouter._resolverFactory(resolver, context, buildInfo) ⇒ Kind: instance method of BuildRouter
BuildRouter.fromData(blocks, [plugins], [context])
Kind: static method of BuildRouter
Param | Type | Description |
---|---|---|
blocks | Array.<Block> | blocks list |
[plugins] | Plugins | |
[context] | BotContext.<C> |
BuildRouter
Kind: global class
- BuildRouter
- new BuildRouter()
- new BuildRouter(block, plugins, context, [fetchFn])
- instance
- ._context :
BotContext.<C>
|Promise.<BuildRouterContext.<C>>
- ._resolvedContext :
BotContext.<C>
- ._linksMap :
LinksMap
- ._configStorage :
ConfigStorage
|Promise.<ConfigStorage>
- .keepConfigFor :
number
- .loadBot() ⇒
Promise.<object>
- ._buildBot(block, setConfigTimestamp, lastmod)
- ._createLinksMap(block) ⇒
LinksMap
- ._enabledByRouteConfig(routeConfig)
- ._getIncludedBlockId(route) ⇒
string
|null
- ._getBlockById(staticBlockId) ⇒
Block
|null
- ._getRouteConfig(route) ⇒
RouteConfig
- ._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒
void
- ._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒
Array.<Middleware>
- ._buildRoutes(routes)
- ._lastMessageIndex(resolvers) ⇒
number
- .buildResolvers(resolvers, [route], [buildInfo]) ⇒
Array.<Middleware>
- ._resolverFactory(resolver, context, buildInfo) ⇒
Middleware
- ._context :
- static
new BuildRouter()
Build bot from Wingbot configuration file or snapshot url
new BuildRouter(block, plugins, context, [fetchFn])
Create new router from configuration
Param | Type | Description |
---|---|---|
block | BotConfig | Block | |
plugins | Plugins | custom code blocks resource |
context | BuildRouterContext.<C> | Promise.<BuildRouterContext.<C>> | the building context |
[fetchFn] | fetch | override a request function |
Example
// usage of pluginsconst { BuildRouter, Plugins } = require('wingbot');const dynamoDb = require('./lib/dynamodb');const config = require('./config');const plugins = new Plugins();plugins.register('exampleBlock', async (req, res, postBack) => {await res.run('responseBlockName');});const bot = new BuildRouter({botId: 'b7a71c27-c295-4ab0-b64e-6835b50a0db0',snapshot: 'master',token: 'adjsadlkadjj92n9u9'}, plugins);module.exports = bot;
BotContext.<C>
| Promise.<BuildRouterContext.<C>>
buildRouter._context : Kind: instance property of BuildRouter
BotContext.<C>
buildRouter._resolvedContext : Kind: instance property of BuildRouter
LinksMap
buildRouter._linksMap : Kind: instance property of BuildRouter
ConfigStorage
| Promise.<ConfigStorage>
buildRouter._configStorage : Kind: instance property of BuildRouter
number
buildRouter.keepConfigFor : Timeout, when the router is not checking for new configuration
Kind: instance property of BuildRouter
Promise.<object>
buildRouter.loadBot() ⇒ Loads conversation configuration
Kind: instance method of BuildRouter
buildRouter._buildBot(block, setConfigTimestamp, lastmod)
Kind: instance method of BuildRouter
Param | Type | Default |
---|---|---|
block | Block | |
setConfigTimestamp | number | |
lastmod | string | "-" |
LinksMap
buildRouter._createLinksMap(block) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
block | Block |
buildRouter._enabledByRouteConfig(routeConfig)
Kind: instance method of BuildRouter
Param | Type |
---|---|
routeConfig | RouteConfig |
string
| null
buildRouter._getIncludedBlockId(route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | Route |
Block
| null
buildRouter._getBlockById(staticBlockId) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
staticBlockId | string |
RouteConfig
buildRouter._getRouteConfig(route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | TransformedRoute |
void
buildRouter._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
linksMap | LinksMap |
includedBlock | Block |
route | TransformedRoute |
Array.<Middleware>
buildRouter._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
route | TransformedRoute |
nextRouteIsSameResponder | boolean |
includedBlockId | string |
buildRouter._buildRoutes(routes)
Kind: instance method of BuildRouter
Param | Type |
---|---|
routes | Array.<TransformedRoute> |
number
buildRouter._lastMessageIndex(resolvers) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
resolvers | Array.<Resolver> |
Array.<Middleware>
buildRouter.buildResolvers(resolvers, [route], [buildInfo]) ⇒ Kind: instance method of BuildRouter
Param | Type |
---|---|
resolvers | Array.<Resolver> |
[route] | TransformedRoute |
[buildInfo] | BuildInfo |
Middleware
buildRouter._resolverFactory(resolver, context, buildInfo) ⇒ Kind: instance method of BuildRouter
BuildRouter.fromData(blocks, [plugins], [context])
Kind: static method of BuildRouter
Param | Type | Description |
---|---|---|
blocks | Array.<Block> | blocks list |
[plugins] | Plugins | |
[context] | BotContext.<C> |
Plugins
Kind: global class
new Plugins()
Custom code plugins for BuildRouter and wingbot.ai
PluginFactoryOptions
plugins.getPluginOptions(name) ⇒ Kind: instance method of Plugins
Param | Type |
---|---|
name | string |
plugins.getWrappedPlugin(name, [paramsData], [items], [context])
Get plugin for the router
Kind: instance method of Plugins
Param | Type |
---|---|
name | string |
[paramsData] | object |
[items] | Map.<string, Array.<function()>> | Object.<string, Middleware> |
[context] | object |
[context.isLastIndex] | boolean |
[context.router] | Router |
[context.configuration] | object |
[context.defaultPlugin] | Middleware |
Example
const { Router } = require('wingbot');const bot = new Router();// simplybot.use('simple-route', plugins.getWrappedPlugin('myCoolPLugin'));// fullybot.use('full-plugin-route', plugins.getWrappedPlugin('fancyPLugin',{ param: 123 },{onSuccess: (req, res) => { res.text('yes, success'); }}));
plugins.register(name, [plugin])
Register plugin
Kind: instance method of Plugins
Param | Type | Description |
---|---|---|
name | string | Plugins.<S, C> | plugin name or plugins object to include |
[plugin] | Plugin.<S, C> | Router | plugin - optional when including plugin object |
plugins.registerFactory(name, pluginFactory, [options])
Register plugin factory
Kind: instance method of Plugins
Param | Type | Description |
---|---|---|
name | string | plugin name or plugins object to include |
pluginFactory | PluginFactory.<S, C> | function, which returns a plugin |
[options] | PluginFactoryOptions |
TransformedRoute
DUMMY_ROUTE : Kind: global constant
object
BuildInfo : Kind: global typedef
Properties
Name | Type |
---|---|
[expectedToAddResolver] | boolean |
[attachedRouter] | boolean |
[notLastMessage] | boolean |
object
Resolver : Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[id] | string | number | only for text messages with random characters |
type | string | |
params | object | |
[params.staticBlockId] | string | |
[params.items] | object | |
[tag] | string |
object
Route : Kind: global typedef
Properties
Name | Type |
---|---|
id | number |
path | string | null |
[skill] | string | null |
resolvers | Array.<Resolver> |
[isFallback] | boolean |
[aiTags] | Array.<string> |
[isResponder] | boolean |
[respondsToRouteId] | number |
[aiTitle] | string | Array.<any> |
[aiGlobal] | boolean |
[bounceAllowedTo] | BounceAllow |
[bounceReturn] | BounceReturn |
[isEntryPoint] | boolean |
object
TransformedRoute : Kind: global typedef
Properties
Name | Type |
---|---|
[expectedPath] | string |
Map.<(string|number), string>
LinksMap : Kind: global typedef
object
Block : Kind: global typedef
Properties
Name | Type |
---|---|
staticBlockId | string |
routes | Array.<Route> |
[isRoot] | boolean |
[disabled] | boolean |
[blockName] | string |
[blockType] | string |
object
BotConfig : Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
botId | string | the ID of bot |
snapshot | string | snapshot stage of bot |
token | string | Promise.<string> | authorization token for bot |
[url] | string | specify alternative configuration resource |
object
ConfigStorage : Kind: global typedef
Properties
Name | Type |
---|---|
invalidateConfig | Object |
getConfigTimestamp | Object |
updateConfig | Object |
getConfig | Object |
object
RouteConfig : Kind: global typedef
Properties
Name | Type |
---|---|
path | string |
[enabled] | boolean |
string
LinkTranslator ⇒ Kind: global typedef
Param | Type |
---|---|
senderId | string |
textLabel | string |
urlText | string |
isExtUrl | boolean |
state | object |
pageId | string |
object
BuildRouterContext : Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[linksTranslator] | LinkTranslator | function, that translates links globally |
[configStorage] | ConfigStorage | function, that translates links globally |
[allowForbiddenSnippetWords] | boolean | disable security rule |
[defaultPlugin] | Middleware | to be able to test configurations without plugins |
[routeConfigs] | Array.<RouteConfig> | list of disabled routes |
[configuration] | C | context data |
object
BotContextExtention : Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[linksMap] | LinksMap | |
[isLastIndex] | boolean | |
[isLastMessage] | boolean | |
[router] | BuildRouter | |
[path] | string | |
[isFallback] | boolean | |
[expectedPath] | string | |
[isResponder] | boolean | |
[routeId] | string | number | |
[blockName] | string | |
[blockType] | string | |
[isRoot] | boolean | |
[staticBlockId] | string | |
[blocks] | Array.<Block> | |
[BuildRouter] | object | |
[resolverId] | string | number | only for text messages with random characters |
BotContextExtention
| BuildRouterContext.<C>
BotContext : Kind: global typedef
function
Plugin : Kind: global typedef
Param | Type |
---|---|
req | Request |
res | Responder |
[postBack] | function |
[context] | Object |
[paramsData] | object |
Router
| Middleware
PluginFactory ⇒ Kind: global typedef
Param | Type |
---|---|
params | object |
configuration | C |
object
PluginFactoryOptions : Kind: global typedef
Properties
Name | Type |
---|---|
[notLastMessageItems] | Array.<string> |