Classes
- MemoryStateStorage
Memory conversation state storage for testing purposes
- ReturnSender
- ReturnSender
Functions
- bufferloader(url, [limit], [limitJustByBody], [redirCount]) ⇒
Promise.<Buffer> Downloads a file from url into a buffer. Supports size limits and redirects.
- compileWithState(req, res, template) ⇒
string Utility, which helps to render handlebars syntax with all variables within conversations state
- makeExpectedKeyword(action, title, [matcher], [payloadData], [setState], [aiTitle]) ⇒
ExpectedKeyword disambiguationQuickReply(title, likelyIntent, disambText, action, data)Create a disambiguation quick reply
Typedefs
- ExpectedKeyword :
object - QuickReplyAction :
object - State :
object - StateCondition :
object - GetInteractions ⇒
Promise.<Array.<object>> - ChatLogStorage :
object - ReturnSenderOptions :
object - UploadResult :
object - DeferOperation ⇒
Promise.<any> - ErrorLogger :
object - SendOptions :
object - TextFilter ⇒
string Text filter function
MemoryStateStorage
Memory conversation state storage for testing purposes
Kind: global class
- MemoryStateStorage
- .getState(senderId, pageId) ⇒
Promise.<(State|null)> - .getOrCreateAndLock(senderId, pageId, defaultState, lockTimeout) ⇒
Promise.<State> - .saveState(state) ⇒
Promise - .getStates(condition, limit, lastKey) ⇒
Promise.<{Array.<data:State>, lastKey:string}>
- .getState(senderId, pageId) ⇒
memoryStateStorage.getState(senderId, pageId) ⇒ Promise.<(State|null)>
Kind: instance method of MemoryStateStorage
| Param | Type |
|---|---|
| senderId | string |
| pageId | string |
memoryStateStorage.getOrCreateAndLock(senderId, pageId, defaultState, lockTimeout) ⇒ Promise.<State>
Kind: instance method of MemoryStateStorage
Returns: Promise.<State> - - conversation state
| Param | Type | Default | Description |
|---|---|---|---|
| senderId | string | sender identifier | |
| pageId | string | page or channel identifier | |
| defaultState | object | default state of the conversation | |
| lockTimeout | number | 300 | duration of lock |
memoryStateStorage.saveState(state) ⇒ Promise
Kind: instance method of MemoryStateStorage
| Param | Type | Description |
|---|---|---|
| state | object | conversation state |
memoryStateStorage.getStates(condition, limit, lastKey) ⇒ Promise.<{Array.<data:State>, lastKey:string}>
Kind: instance method of MemoryStateStorage
| Param | Type | Default |
|---|---|---|
| condition | StateCondition | |
| limit | number | 20 |
| lastKey | string | null |
ReturnSender
Kind: global class
Implements: LLMLogger
- ReturnSender
- new ReturnSender(options, senderId, incommingMessage, logger)
- .responses :
Array.<object> - ._responseOptions :
Array.<SendOptions> - .waits :
boolean - .textFilter :
TextFilter - .prompts :
Array.<PromptInfo> - .requestTexts ⇒
Array.<string> - .responseTexts ⇒
Array.<string> - .chatLogStorage ⇒
ChatLogStorage - .tracking ⇒
TrackingObject - .logPrompt(promptInfo)
- .defer(operation, logger)
- .upload(data, contentType, fileName) ⇒
Promise.<UploadResult> - .send(payload, options) ⇒
void - .modifyStateAfterLoad() ⇒
Promise.<(object|null)> - .modifyStateBeforeStore() ⇒
Promise.<(object|null)> - .finished([req], [res], [err], [reportError]) ⇒
Promise.<Object>
new ReturnSender(options, senderId, incommingMessage, logger)
| Param | Type | Default | Description |
|---|---|---|---|
| options | ReturnSenderOptions | ||
| senderId | string | ||
| incommingMessage | object | ||
| logger | ChatLogStorage | | console like logger |
returnSender.responses : Array.<object>
Kind: instance property of ReturnSender
returnSender._responseOptions : Array.<SendOptions>
Kind: instance property of ReturnSender
returnSender.waits : boolean
Kind: instance property of ReturnSender
returnSender.textFilter : TextFilter
Preprocess text for NLP For example to remove any confidential data
Kind: instance property of ReturnSender
| Param | Type |
|---|---|
| text | string |
returnSender.prompts : Array.<PromptInfo>
Kind: instance property of ReturnSender
returnSender.requestTexts ⇒ Array.<string>
Kind: instance property of ReturnSender
returnSender.responseTexts ⇒ Array.<string>
Kind: instance property of ReturnSender
returnSender.chatLogStorage ⇒ ChatLogStorage
Kind: instance property of ReturnSender
returnSender.tracking ⇒ TrackingObject
Kind: instance property of ReturnSender
returnSender.logPrompt(promptInfo)
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| promptInfo | PromptInfo |
returnSender.defer(operation, logger)
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| operation | DeferOperation | Promise |
| logger | ErrorLogger |
returnSender.upload(data, contentType, fileName) ⇒ Promise.<UploadResult>
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| data | Buffer |
| contentType | string |
| fileName | string |
returnSender.send(payload, options) ⇒ void
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| payload | object |
| options | SendOptions |
returnSender.modifyStateAfterLoad() ⇒ Promise.<(object|null)>
Kind: instance method of ReturnSender
returnSender.modifyStateBeforeStore() ⇒ Promise.<(object|null)>
Kind: instance method of ReturnSender
returnSender.finished([req], [res], [err], [reportError]) ⇒ Promise.<Object>
Kind: instance method of ReturnSender
| Param | Type | Default |
|---|---|---|
| [req] | Request | |
| [res] | Responder | |
| [err] | Error | |
| [reportError] | function |
ReturnSender
Kind: global class
- ReturnSender
- new ReturnSender(options, senderId, incommingMessage, logger)
- .responses :
Array.<object> - ._responseOptions :
Array.<SendOptions> - .waits :
boolean - .textFilter :
TextFilter - .prompts :
Array.<PromptInfo> - .requestTexts ⇒
Array.<string> - .responseTexts ⇒
Array.<string> - .chatLogStorage ⇒
ChatLogStorage - .tracking ⇒
TrackingObject - .logPrompt(promptInfo)
- .defer(operation, logger)
- .upload(data, contentType, fileName) ⇒
Promise.<UploadResult> - .send(payload, options) ⇒
void - .modifyStateAfterLoad() ⇒
Promise.<(object|null)> - .modifyStateBeforeStore() ⇒
Promise.<(object|null)> - .finished([req], [res], [err], [reportError]) ⇒
Promise.<Object>
new ReturnSender(options, senderId, incommingMessage, logger)
| Param | Type | Default | Description |
|---|---|---|---|
| options | ReturnSenderOptions | ||
| senderId | string | ||
| incommingMessage | object | ||
| logger | ChatLogStorage | | console like logger |
returnSender.responses : Array.<object>
Kind: instance property of ReturnSender
returnSender._responseOptions : Array.<SendOptions>
Kind: instance property of ReturnSender
returnSender.waits : boolean
Kind: instance property of ReturnSender
returnSender.textFilter : TextFilter
Preprocess text for NLP For example to remove any confidential data
Kind: instance property of ReturnSender
| Param | Type |
|---|---|
| text | string |
returnSender.prompts : Array.<PromptInfo>
Kind: instance property of ReturnSender
returnSender.requestTexts ⇒ Array.<string>
Kind: instance property of ReturnSender
returnSender.responseTexts ⇒ Array.<string>
Kind: instance property of ReturnSender
returnSender.chatLogStorage ⇒ ChatLogStorage
Kind: instance property of ReturnSender
returnSender.tracking ⇒ TrackingObject
Kind: instance property of ReturnSender
returnSender.logPrompt(promptInfo)
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| promptInfo | PromptInfo |
returnSender.defer(operation, logger)
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| operation | DeferOperation | Promise |
| logger | ErrorLogger |
returnSender.upload(data, contentType, fileName) ⇒ Promise.<UploadResult>
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| data | Buffer |
| contentType | string |
| fileName | string |
returnSender.send(payload, options) ⇒ void
Kind: instance method of ReturnSender
| Param | Type |
|---|---|
| payload | object |
| options | SendOptions |
returnSender.modifyStateAfterLoad() ⇒ Promise.<(object|null)>
Kind: instance method of ReturnSender
returnSender.modifyStateBeforeStore() ⇒ Promise.<(object|null)>
Kind: instance method of ReturnSender
returnSender.finished([req], [res], [err], [reportError]) ⇒ Promise.<Object>
Kind: instance method of ReturnSender
| Param | Type | Default |
|---|---|---|
| [req] | Request | |
| [res] | Responder | |
| [err] | Error | |
| [reportError] | function |
bufferloader(url, [limit], [limitJustByBody], [redirCount]) ⇒ Promise.<Buffer>
Downloads a file from url into a buffer. Supports size limits and redirects.
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| url | string | ||
| [limit] | number | 0 | limit in bytes |
| [limitJustByBody] | boolean | false | when true, content size in header is ignored |
| [redirCount] | number | 3 | maximmum amount of redirects |
Example
router.use('*', (req, res, postBack) => {if (req.isFile()) {bufferloader(req.attachmentUrl()).then(buffer => postBack('downloaded', { data: buffer })).catch(err => postBack('donwloaded', { err }))}});
compileWithState(req, res, template) ⇒ string
Utility, which helps to render handlebars syntax with all variables within conversations state
Kind: global function
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| template | string |
Example
const { compileWithState } = require('wingbot');function myPluginFactory (params) {return (req, res) => {const text = compileWithState(req, res, params.text);res.text(text);};}
makeExpectedKeyword(action, title, [matcher], [payloadData], [setState], [aiTitle]) ⇒ ExpectedKeyword
Kind: global function
| Param | Type | Default |
|---|---|---|
| action | string | |
| title | string | |
| [matcher] | RegExp | string | Array.<string> | |
| [payloadData] | object | |
| [setState] | object | |
| [aiTitle] | string | null |
disambiguationQuickReply(title, likelyIntent, disambText, action, data)
Deprecated
Create a disambiguation quick reply
Kind: global function
| Param | Type | Description |
|---|---|---|
| title | string | quick reply title |
| likelyIntent | string | possible intent |
| disambText | string | users text input |
| action | string | action to process the disambbiguation |
| data | object | optional data |
ExpectedKeyword : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| action | string |
| title | string |
| match | null | string | Array.<string> |
| data | object |
| [hasAiTitle] | boolean |
| [setState] | object |
QuickReplyAction : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| aboveConfidence | boolean |
| action | string |
| title | string |
| match | null | string | Array.<string> |
| data | object |
| score | number |
| sort | number |
| [title] | string |
| [setState] | object |
| [_aiKeys] | Array.<string> |
| [intent] | Intent |
State : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| senderId | string |
| pageId | string |
| state | object |
StateCondition : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [search] | string |
GetInteractions ⇒ Promise.<Array.<object>>
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| senderId | string | |
| pageId | string | |
| [limit] | number | |
| [endAt] | number | iterate backwards to history |
| [startAt] | number | iterate forward to last interaction |
ChatLogStorage : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| log | function |
| error | function |
| [getInteractions] | GetInteractions |
ReturnSenderOptions : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| [dontWaitForDeferredOps] | boolean | |
| [textFilter] | TextFilter | filter for saving the texts |
| [logStandbyEvents] | boolean | log the standby events |
| [confidentInputFilter] | TextFilter | filter for confident input (@CONFIDENT) |
UploadResult : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [url] | string |
| [attachmentId] | string | number |
DeferOperation ⇒ Promise.<any>
Kind: global typedef
ErrorLogger : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| error | function |
SendOptions : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [anonymizer] | TextFilter |
TextFilter ⇒ string
Text filter function
Kind: global typedef
Returns: string - - filtered text
| Param | Type | Description |
|---|---|---|
| text | string | input text |
| key | 'text' | 'title' | 'url' | 'content' |