Classes
Functions
Typedefs
- Options :
object - ApiResponse :
object - AutoTypingConfig :
object - Plugin :
object - TrackingEvent :
object - TrackingObject :
object - InteractionEvent :
object - IInteractionHandler ⇒
Promise|void - ILogger :
object - ProcessorOptions :
object - IntentAction :
object - IStateStorage :
object - Preloader ⇒
Promise.<void>
BotApp
Adapter for Wingbot flight director
Kind: global class
- BotApp
- new BotApp(bot, options)
- instance
- ._eventHandlers :
Array.<OnEventHandler> - .processor ⇒
Processor - .registerAnalyticsStorage(analyticsStorage, [options]) ⇒
this - .trackEvent(pageId, senderId, event, [ts], [nonInteractive])
- ._processSenderResponses(sender, senderId, pageId, headers)
- .createSender(senderId, pageId, [message], [secret], appId) ⇒
Promise.<BotAppSender> - .processMessage(message, senderId, pageId, data) ⇒
Promise.<{status:number}> - .request(rawBody, rawHeaders) ⇒
Promise.<ApiResponse>
- ._eventHandlers :
- static
- .signBody(body, secret, appId) ⇒
Promise.<string> - .plugin() ⇒
Plugin - .sendContext(req, res)
- .signBody(body, secret, appId) ⇒
new BotApp(bot, options)
| Param | Type |
|---|---|
| bot | Router |
| options | Options |
botApp._eventHandlers : Array.<OnEventHandler>
Kind: instance property of BotApp
botApp.processor ⇒ Processor
Get the processor instance
Kind: instance property of BotApp
botApp.registerAnalyticsStorage(analyticsStorage, [options]) ⇒ this
Kind: instance method of BotApp
| Param | Type |
|---|---|
| analyticsStorage | IAnalyticsStorage |
| [options] | HandlerConfig |
Example
const { GA4 } = require('wingbot');botApp.registerAnalyticsStorage(new GA4({measurementId: 'G-123456,apiSecret: 'apisecret'}))
botApp.trackEvent(pageId, senderId, event, [ts], [nonInteractive])
Method for tracking special events
Kind: instance method of BotApp
| Param | Type | Default |
|---|---|---|
| pageId | string | |
| senderId | string | |
| event | Event | |
| [ts] | number | |
| [nonInteractive] | boolean | false |
botApp._processSenderResponses(sender, senderId, pageId, headers)
Kind: instance method of BotApp
| Param | Type |
|---|---|
| sender | ReturnSender |
| senderId | string |
| pageId | string |
| headers | object |
botApp.createSender(senderId, pageId, [message], [secret], appId) ⇒ Promise.<BotAppSender>
Creates a Sender to be able, for example, to upload files
Kind: instance method of BotApp
| Param | Type |
|---|---|
| senderId | string |
| pageId | string |
| [message] | object |
| [secret] | string | Promise.<string> |
| appId | string |
botApp.processMessage(message, senderId, pageId, data) ⇒ Promise.<{status:number}>
Compatibility method for Notification engine
Kind: instance method of BotApp
| Param | Type | Description |
|---|---|---|
| message | object | wingbot chat event |
| senderId | string | chat event sender identifier |
| pageId | string | channel/page identifier |
| data | object | contextual data (will be available in res.data) |
| [data.appId] | string | possibility to override appId |
botApp.request(rawBody, rawHeaders) ⇒ Promise.<ApiResponse>
Process incomming API request from the orchestrator.
The response can be sent using an express, or you can directly return the response to
Kind: instance method of BotApp
| Param | Type |
|---|---|
| rawBody | string | null |
| rawHeaders | object |
Example
const express = require('express');const { Router, BotApp } = require('express');const app = express();const bot = new Router();bot.use((req, res) => { res.text('hello!'); });const botApp = new BotApp(bot, {apiUrl: 'https://<url to orchestrator>',secret: '<application secret in orchestrator>'});app.get('/bot', express.text(), (req, res) => {botApp.request(req.body, req.headers).then((response) => {const { body, statusCode, headers } = response;res.status(statusCode).set(headers).send(body);})});
BotApp.signBody(body, secret, appId) ⇒ Promise.<string>
Get authorization token for wingbot orchestrator
Kind: static method of BotApp
| Param | Type |
|---|---|
| body | string |
| secret | string |
| appId | string |
BotApp.plugin() ⇒ Plugin
Returns processor plugin, which updates thread context automatically
Kind: static method of BotApp
BotApp.sendContext(req, res)
Kind: static method of BotApp
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
afterProcessMessage(req, res)
Kind: global function
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
Options : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| secret | string | Promise.<string> | |
| [appId] | string | for notifications |
| [apiUrl] | string | |
| [fetch] | function | |
| [chatLogStorage] | ChatLogStorage | |
| [preferSynchronousResponse] | boolean | |
| [auditLog] | AuditLog | |
| [tls] | TlsOptions |
ApiResponse : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| statusCode | number |
| body | string |
| headers | object |
AutoTypingConfig : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| time | number | duration |
| perCharacters | number | number of characters |
| minTime | number | minimum writing time |
| maxTime | number | maximum writing time |
Plugin : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [processMessage] | function |
| [beforeAiPreload] | function |
| [beforeProcessMessage] | function |
| [afterProcessMessage] | function |
TrackingEvent : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| type | TrackingType |
| category | TrackingCategory |
| action | string |
| label | string |
| value | number |
TrackingObject : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| events | Array.<TrackingEvent> |
InteractionEvent : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| req | Request | |
| actions | Array.<string> | |
| lastAction | string | null | |
| state | object | |
| data | object | |
| skill | string | null | |
| prevSkill | string | null | |
| pathname | string | null | |
| tracking | TrackingObject | deprecated |
| events | Array.<TrackingEvent> | |
| flag | ResponseFlag | null | |
| nonInteractive | boolean | |
| responseTexts | Array.<string> | |
| doNotTrack | boolean |
IInteractionHandler ⇒ Promise | void
Kind: global typedef
| Param | Type |
|---|---|
| params | InteractionEvent |
ILogger : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| log | function |
| warn | function |
| error | function |
ProcessorOptions : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| [appUrl] | string | url basepath for relative links |
| [stateStorage] | IStateStorage | chatbot state storage |
| [tokenStorage] | object | frontend token storage |
| [translator] | function | text translate function |
| [timeout] | number | chat sesstion lock duration (30000) |
| [justUpdateTimeout] | number | simple read and write lock (1000) |
| [waitForLockedState] | number | wait when state is locked (12000) |
| [retriesWhenWaiting] | number | number of attampts (6) |
| [nameFromState] | function | override the name translator |
| [autoTyping] | boolean | AutoTypingConfig | enable or disable automatic typing |
| [log] | ILogger | console like error logger |
| [defaultState] | object | default chat state |
| [autoSeen] | boolean | send seen automatically |
| [redirectLimit] | number | maximum number of redirects at single request |
| [secret] | string | Secret for calling orchestrator API |
| [apiUrl] | string | Url for calling orchestrator API |
| [fetch] | function | Fetch function for calling orchestrator API |
| [sessionDuration] | number | Session duration for analytic purposes |
| [llm] | LLMConfiguration | LLM model configuration |
| [preloader] | Preloader.<R> |
IntentAction : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| action | string |
| intent | Intent |
| sort | number |
| [score] | number |
| local | boolean |
| aboveConfidence | boolean |
| [winner] | boolean |
| meta | object |
| title | string |
| [meta.targetAppId] | string |
| [meta.targetAction] | string | null |
IStateStorage : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| saveState | function |
| getState | function |
| getOrCreateAndLock | function |
Preloader ⇒ Promise.<void>
Kind: global typedef
| Param | Type |
|---|---|
| router | T |
| ai | Ai |