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 |
Array.<OnEventHandler>
botApp._eventHandlers : Kind: instance property of BotApp
Processor
botApp.processor ⇒ Get the processor instance
Kind: instance property of BotApp
this
botApp.registerAnalyticsStorage(analyticsStorage, [options]) ⇒ 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 |
Promise.<BotAppSender>
botApp.createSender(senderId, pageId, [message], [secret], appId) ⇒ 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 |
Promise.<{status:number}>
botApp.processMessage(message, senderId, pageId, data) ⇒ 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 |
Promise.<ApiResponse>
botApp.request(rawBody, rawHeaders) ⇒ 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);})});
Promise.<string>
BotApp.signBody(body, secret, appId) ⇒ Get authorization token for wingbot orchestrator
Kind: static method of BotApp
Param | Type |
---|---|
body | string |
secret | string |
appId | string |
Plugin
BotApp.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 |
object
Options : 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 |
object
ApiResponse : Kind: global typedef
Properties
Name | Type |
---|---|
statusCode | number |
body | string |
headers | object |
object
AutoTypingConfig : 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 |
object
Plugin : Kind: global typedef
Properties
Name | Type |
---|---|
[processMessage] | function |
[beforeAiPreload] | function |
[beforeProcessMessage] | function |
[afterProcessMessage] | function |
object
TrackingEvent : Kind: global typedef
Properties
Name | Type |
---|---|
type | TrackingType |
category | TrackingCategory |
action | string |
label | string |
value | number |
object
TrackingObject : Kind: global typedef
Properties
Name | Type |
---|---|
events | Array.<TrackingEvent> |
object
InteractionEvent : 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 |
Promise
| void
IInteractionHandler ⇒ Kind: global typedef
Param | Type |
---|---|
params | InteractionEvent |
object
ILogger : Kind: global typedef
Properties
Name | Type |
---|---|
log | function |
warn | function |
error | function |
object
ProcessorOptions : 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 |
[preloader] | Preloader.<R> |
object
IntentAction : 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 |
object
IStateStorage : Kind: global typedef
Properties
Name | Type |
---|---|
saveState | function |
getState | function |
getOrCreateAndLock | function |
Promise.<void>
Preloader ⇒ Kind: global typedef
Param | Type |
---|---|
router | T |
ai | Ai |