Classes
- BuildRouter ⇐
Router - BuildRouter
- Plugins
Constants
Typedefs
- BuildInfo :
object - Resolver :
object - Route :
object - TransformedRoute :
object - LinksMap :
Map.<(string|number), string> - BlockMap :
Map.<(string|number), Block> - Block :
object - BotConfig :
object - ConfigStorage :
object - RouteConfig :
object - LinkTranslator ⇒
string - BuildRouterContext :
object - NestedLinksMapFactory ⇒
LinksMap - BotContextExtention :
object - BotContext :
BotContextExtention|BuildRouterContext.<C> - Plugin :
function - PluginFactory ⇒
Router|Middleware - PluginFactoryOptions :
object
BuildRouter ⇐ Router
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 - ._nestedLinksMap :
LinksMap - ._configStorage :
ConfigStorage|Promise.<ConfigStorage> - .keepConfigFor :
number - .loadBot() ⇒
Promise.<object> - ._buildBot(block, setConfigTimestamp, lastmod)
- ._createLinksMap(block)
- ._enabledByRouteConfig(routeConfig)
- ._getIncludedBlockId(route) ⇒
string|null - ._getRouteConfig(route) ⇒
RouteConfig - ._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒
void - ._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒
Array.<Middleware> - ._buildRoutes(routes, nestedBlocksByStaticId)
- ._lastMessageIndex(resolvers) ⇒
number - .buildResolvers(resolvers, [route], [buildInfo], [nestedBlocksByStaticId]) ⇒
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;
buildRouter._context : BotContext.<C> | Promise.<BuildRouterContext.<C>>
Kind: instance property of BuildRouter
buildRouter._resolvedContext : BotContext.<C>
Kind: instance property of BuildRouter
buildRouter._linksMap : LinksMap
Kind: instance property of BuildRouter
buildRouter._nestedLinksMap : LinksMap
Kind: instance property of BuildRouter
buildRouter._configStorage : ConfigStorage | Promise.<ConfigStorage>
Kind: instance property of BuildRouter
buildRouter.keepConfigFor : number
Timeout, when the router is not checking for new configuration
Kind: instance property of BuildRouter
buildRouter.loadBot() ⇒ Promise.<object>
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 | "-" |
buildRouter._createLinksMap(block)
returns {[LinksMap, BlockMap]}
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| block | Block |
buildRouter._enabledByRouteConfig(routeConfig)
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| routeConfig | RouteConfig |
buildRouter._getIncludedBlockId(route) ⇒ string | null
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | Route |
buildRouter._getRouteConfig(route) ⇒ RouteConfig
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | TransformedRoute |
buildRouter._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒ void
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| linksMap | LinksMap |
| includedBlock | Block |
| route | TransformedRoute |
buildRouter._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒ Array.<Middleware>
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | TransformedRoute |
| nextRouteIsSameResponder | boolean |
| includedBlockId | string |
buildRouter._buildRoutes(routes, nestedBlocksByStaticId)
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| routes | Array.<TransformedRoute> |
| nestedBlocksByStaticId | BlockMap |
buildRouter._lastMessageIndex(resolvers) ⇒ number
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| resolvers | Array.<Resolver> |
buildRouter.buildResolvers(resolvers, [route], [buildInfo], [nestedBlocksByStaticId]) ⇒ Array.<Middleware>
Kind: instance method of BuildRouter
| Param | Type | Default |
|---|---|---|
| resolvers | Array.<Resolver> | |
| [route] | TransformedRoute | |
| [buildInfo] | BuildInfo | |
| [nestedBlocksByStaticId] | BlockMap | |
buildRouter._resolverFactory(resolver, context, buildInfo) ⇒ Middleware
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 - ._nestedLinksMap :
LinksMap - ._configStorage :
ConfigStorage|Promise.<ConfigStorage> - .keepConfigFor :
number - .loadBot() ⇒
Promise.<object> - ._buildBot(block, setConfigTimestamp, lastmod)
- ._createLinksMap(block)
- ._enabledByRouteConfig(routeConfig)
- ._getIncludedBlockId(route) ⇒
string|null - ._getRouteConfig(route) ⇒
RouteConfig - ._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒
void - ._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒
Array.<Middleware> - ._buildRoutes(routes, nestedBlocksByStaticId)
- ._lastMessageIndex(resolvers) ⇒
number - .buildResolvers(resolvers, [route], [buildInfo], [nestedBlocksByStaticId]) ⇒
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;
buildRouter._context : BotContext.<C> | Promise.<BuildRouterContext.<C>>
Kind: instance property of BuildRouter
buildRouter._resolvedContext : BotContext.<C>
Kind: instance property of BuildRouter
buildRouter._linksMap : LinksMap
Kind: instance property of BuildRouter
buildRouter._nestedLinksMap : LinksMap
Kind: instance property of BuildRouter
buildRouter._configStorage : ConfigStorage | Promise.<ConfigStorage>
Kind: instance property of BuildRouter
buildRouter.keepConfigFor : number
Timeout, when the router is not checking for new configuration
Kind: instance property of BuildRouter
buildRouter.loadBot() ⇒ Promise.<object>
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 | "-" |
buildRouter._createLinksMap(block)
returns {[LinksMap, BlockMap]}
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| block | Block |
buildRouter._enabledByRouteConfig(routeConfig)
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| routeConfig | RouteConfig |
buildRouter._getIncludedBlockId(route) ⇒ string | null
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | Route |
buildRouter._getRouteConfig(route) ⇒ RouteConfig
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | TransformedRoute |
buildRouter._findEntryPointsInResolver(linksMap, includedBlock, route) ⇒ void
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| linksMap | LinksMap |
| includedBlock | Block |
| route | TransformedRoute |
buildRouter._buildRouteHead(route, nextRouteIsSameResponder, includedBlockId) ⇒ Array.<Middleware>
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| route | TransformedRoute |
| nextRouteIsSameResponder | boolean |
| includedBlockId | string |
buildRouter._buildRoutes(routes, nestedBlocksByStaticId)
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| routes | Array.<TransformedRoute> |
| nestedBlocksByStaticId | BlockMap |
buildRouter._lastMessageIndex(resolvers) ⇒ number
Kind: instance method of BuildRouter
| Param | Type |
|---|---|
| resolvers | Array.<Resolver> |
buildRouter.buildResolvers(resolvers, [route], [buildInfo], [nestedBlocksByStaticId]) ⇒ Array.<Middleware>
Kind: instance method of BuildRouter
| Param | Type | Default |
|---|---|---|
| resolvers | Array.<Resolver> | |
| [route] | TransformedRoute | |
| [buildInfo] | BuildInfo | |
| [nestedBlocksByStaticId] | BlockMap | |
buildRouter._resolverFactory(resolver, context, buildInfo) ⇒ Middleware
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
plugins.getPluginOptions(name) ⇒ PluginFactoryOptions
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|string)> |
| [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 |
DUMMY_ROUTE : TransformedRoute
Kind: global constant
BuildInfo : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [expectedToAddResolver] | boolean |
| [attachedRouter] | boolean |
| [notLastMessage] | boolean |
Resolver : object
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 |
Route : object
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 |
TransformedRoute : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [expectedPath] | string |
LinksMap : Map.<(string|number), string>
Kind: global typedef
BlockMap : Map.<(string|number), Block>
Kind: global typedef
Block : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| staticBlockId | string |
| routes | Array.<Route> |
| [isRoot] | boolean |
| [disabled] | boolean |
| [blockName] | string |
| [blockType] | string |
BotConfig : object
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 |
ConfigStorage : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| invalidateConfig | Object |
| getConfigTimestamp | Object |
| updateConfig | Object |
| getConfig | Object |
RouteConfig : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| path | string |
| [enabled] | boolean |
LinkTranslator ⇒ string
Kind: global typedef
| Param | Type |
|---|---|
| senderId | string |
| textLabel | string |
| urlText | string |
| isExtUrl | boolean |
| state | object |
| pageId | string |
BuildRouterContext : object
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 |
NestedLinksMapFactory ⇒ LinksMap
Kind: global typedef
BotContextExtention : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| [nestedBlocksByStaticId] | BlockMap | |
| [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> | |
| [nestedLinksMapFactory] | NestedLinksMapFactory | |
| [BuildRouter] | object | |
| [ai] | Ai | |
| [resolverId] | string | number | only for text messages with random characters |
BotContext : BotContextExtention | BuildRouterContext.<C>
Kind: global typedef
Plugin : function
Kind: global typedef
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| [postBack] | function |
| [context] | Object |
| [paramsData] | object |
PluginFactory ⇒ Router | Middleware
Kind: global typedef
| Param | Type |
|---|---|
| params | object |
| configuration | C |
PluginFactoryOptions : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [notLastMessageItems] | Array.<string> |