Classes
- Responder
Instance of responder is passed as second parameter of handler (res)
Typedefs
- ExpectedInputOptions :
object - QuickReply :
object - SenderMeta :
object - VoiceControl :
object - VoiceControlFactory ⇒
VoiceControl - Persona :
object - PromptGetter ⇒
string|Promise.<string> - PromptSource :
PromptGetter|string - PromptContextItem :
PromptSource|Promise.<string> - PromisedString :
Promise.<string> - MessageOptions :
object
Responder
Instance of responder is passed as second parameter of handler (res)
Kind: global class
- Responder
- .newState
- .ExpectedInputTypes
- .finalMessageSent
- .startedOutput
- .voiceControl :
VoiceControl|VoiceControlFactory - ._nextMessageSendOptions :
SendOptions - .llm :
LLM - ._llmContext :
Map.<string, Array.<PromptContextItem>> - ._llmResultRules :
Map.<string, Array.<PreprocessedRule>> - ._llmFilters :
Map.<string, Array.<LLMFilter>> - .senderMeta ⇒
SenderMeta - .data :
object - .textResponses ⇒
Array.<string> - .run(blockName) ⇒
Promise .llmAddSystemPrompt(systemPrompt, [contextType]) ⇒this- .llmAddInstructions(systemPrompt, contextType) ⇒
this - .llmAddFilter(filter, [scope], [contextType]) ⇒
this - .llmAddResultRule(rule, [action], [setState], [contextType]) ⇒
this - .llmEvaluate(session, [contextType]) ⇒
Promise.<EvaluationResult> - ._getSystemContentForType(contextType, [callStack]) ⇒
Promise.<Array.<string>> - ._filtersForContext(contextType) ⇒
Array.<LLMFilter> - ._llmSend(messages, quickReplies)
- .setFlag(flag) ⇒
this - .getTranscript([limit], [onlyFlag], [skipThisTurnaround]) ⇒
Promise.<Array.<Transcript>> - .setNotificationRecipient(recipient)
- .doNotLogTheEvent() ⇒
this - .trackEvent(type, category, [action], [label], [value]) ⇒
this - .send(data) ⇒
this .setBookmark([action], [winningIntent]) ⇒this.bookmark() ⇒string|null.runBookmark(postBack, [data]) ⇒Promise.<(null|boolean)>- .setMessagingType(messagingType, [tag]) ⇒
this - .setPersona(personaId) ⇒
this - .isResponseType() ⇒
boolean - .setData(data) ⇒
this - .text(text, [replies], [voice], [options]) ⇒
this - .setState(object) ⇒
this .addQuickReply(action, [title], [data], [prepend], [justToExisting])- .quickReply(reply, [atStart], [toLastMessage], [ifNotExists]) ⇒
this - .keepPreviousContext(req, [justOnce], [includeKeywords]) ⇒
this - .expectedIntent(intents, action, data, [setState], [aiTitle])
- .expected(action, data) ⇒
this - .expectedConfidentInput([expectedInput]) ⇒
this - .expectedInput(type, [options]) ⇒
this - .toAbsoluteAction(action, [forceStartingSlash]) ⇒
string - .currentAction() ⇒
string - .upload(data, contentType, fileName) ⇒
Promise.<UploadResult> - .image(imageUrl, [reusable]) ⇒
this - .video(videoUrl, [reusable]) ⇒
this - .file(fileUrl, [reusable]) ⇒
this - .oneTimeNotificationRequest(title, action, [tag], [data]) ⇒
this - .wait([ms]) ⇒
this - .typingOn([force]) ⇒
this - .typingOff() ⇒
this - .seen() ⇒
this - .passThread(targetAppId, [data]) ⇒
this - .requestThread([data]) ⇒
this - .takeThead([data]) ⇒
this - .receipt(recipientName, [paymentMethod], [currency], [uniqueCode]) ⇒
ReceiptTemplate - .button(text) ⇒
ButtonTemplate - .genericTemplate([shareable], [isSquare]) ⇒
GenericTemplate - .list([topElementStyle]) ⇒
ListTemplate - .nextOutputConfident(anonymizer)
- .trackAs(action) ⇒
this - .trackAsSkill(skill) ⇒
this
responder.newState
The empty object, which is filled with res.setState() method and saved (with Object.assign) at the end of event processing into the conversation state.
Kind: instance property of Responder
Properties
| Type |
|---|
object |
responder.ExpectedInputTypes
Kind: instance property of Responder
Properties
| Type |
|---|
Object.<ExpectedInput, ExpectedInput> |
responder.finalMessageSent
Is true, when a final message (the quick replies by default) has been sent
Kind: instance property of Responder
Properties
| Type |
|---|
boolean |
responder.startedOutput
Is true, when a an output started during the event dispatch
Kind: instance property of Responder
Properties
| Type |
|---|
boolean |
responder.voiceControl : VoiceControl | VoiceControlFactory
Kind: instance property of Responder
responder._nextMessageSendOptions : SendOptions
Kind: instance property of Responder
responder.llm : LLM
Kind: instance property of Responder
responder._llmContext : Map.<string, Array.<PromptContextItem>>
Kind: instance property of Responder
responder._llmResultRules : Map.<string, Array.<PreprocessedRule>>
Kind: instance property of Responder
responder._llmFilters : Map.<string, Array.<LLMFilter>>
Kind: instance property of Responder
responder.senderMeta ⇒ SenderMeta
Response has been marked with a flag
Kind: instance property of Responder
responder.data : object
Kind: instance property of Responder
responder.textResponses ⇒ Array.<string>
Return array of text responses
Kind: instance property of Responder
responder.run(blockName) ⇒ Promise
Run a code block defined by a plugin
Kind: instance method of Responder
| Param | Type |
|---|---|
| blockName | string |
Properties
| Type |
|---|
function |
responder.llmAddSystemPrompt(systemPrompt, [contextType]) ⇒ this
thisDeprecated
Kind: instance method of Responder
| Param | Type |
|---|---|
| systemPrompt | PromptSource |
| [contextType] | string |
responder.llmAddInstructions(systemPrompt, contextType) ⇒ this
Kind: instance method of Responder
| Param | Type |
|---|---|
| systemPrompt | PromptSource |
| contextType | string |
responder.llmAddFilter(filter, [scope], [contextType]) ⇒ this
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| filter | LLMFilter | LLMFilterFn | |
| [scope] | FilterScope | |
| [contextType] | string | null |
responder.llmAddResultRule(rule, [action], [setState], [contextType]) ⇒ this
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| rule | Array.<string> | PreprocessedRule | |
| [action] | EvaluationRuleAction | |
| [setState] | object | |
| [contextType] | string |
responder.llmEvaluate(session, [contextType]) ⇒ Promise.<EvaluationResult>
Kind: instance method of Responder
| Param | Type |
|---|---|
| session | LLMSession |
| [contextType] | string |
responder._getSystemContentForType(contextType, [callStack]) ⇒ Promise.<Array.<string>>
Kind: instance method of Responder
| Param | Type |
|---|---|
| contextType | string |
| [callStack] | Array.<string> |
responder._filtersForContext(contextType) ⇒ Array.<LLMFilter>
Kind: instance method of Responder
| Param | Type |
|---|---|
| contextType | string | null |
responder._llmSend(messages, quickReplies)
Kind: instance method of Responder
| Param | Type |
|---|---|
| messages | Array.<LLMMessage> |
| quickReplies | Array.<QuickReply> |
responder.setFlag(flag) ⇒ this
Kind: instance method of Responder
| Param | Type |
|---|---|
| flag | string |
responder.getTranscript([limit], [onlyFlag], [skipThisTurnaround]) ⇒ Promise.<Array.<Transcript>>
Returns current conversation transcript
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [limit] | number | 10 |
| [onlyFlag] | string | null |
| [skipThisTurnaround] | boolean | false |
responder.setNotificationRecipient(recipient)
Replaces recipient and disables autotyping Usefull for sending a one-time notification
Kind: instance method of Responder
| Param | Type |
|---|---|
| recipient | object |
responder.doNotLogTheEvent() ⇒ this
Disables logging the event to history
Kind: instance method of Responder
responder.trackEvent(type, category, [action], [label], [value]) ⇒ this
Fire tracking event
Events are aggregated within ReturnSender and can be caught
within Processor's interaction event (event.tracking.events)
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| type | TrackingType | (log,report,conversation,audit,user,training) | |
| category | TrackingCategory | ||
| [action] | string | ||
| [label] | string | ||
| [value] | number | 0 |
responder.send(data) ⇒ this
Send a raw messaging event. If no recipient is provided, a default (senderId) will be added.
Kind: instance method of Responder
| Param | Type |
|---|---|
| data | object |
Example
res.send({ message: { text: 'Hello!' } });
responder.setBookmark([action], [winningIntent]) ⇒ this
thisDeprecated
Stores current action to be able to all it again
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [action] | string | |
| [winningIntent] | object | |
Example
bot.use(['action-name', /keyword/], (req, res) => {if (req.action() !== res.currentAction()) {// only for routes with action name (action-name)res.setBookmark();return Router.BREAK;}res.text('Keyword reaction');});// check out the res.runBookmark() method
responder.bookmark() ⇒ string | null
string | nullDeprecated
Returns the action of bookmark
Kind: instance method of Responder
responder.runBookmark(postBack, [data]) ⇒ Promise.<(null|boolean)>
Promise.<(null|boolean)>Deprecated
Kind: instance method of Responder
| Param | Type | Description |
|---|---|---|
| postBack | function | the postback func |
| [data] | object | data for bookmark action |
Example
// there should be a named intent intent matcher (ai.match() and 'action-name')bot.use('action', (req, res) => {res.text('tell me your name');res.expected('onName');});bot.use('onName', (req, res, postBack) => {if (res.bookmark()) {await res.runBookmark(postBack);res.text('But I'll need your name').expected('onName');return;}res.text(`Your name is: ${res.text()}`);})
responder.setMessagingType(messagingType, [tag]) ⇒ this
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| messagingType | string | |
| [tag] | string | null |
responder.setPersona(personaId) ⇒ this
Tets the persona for following requests
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| personaId | Persona | string | null | |
responder.isResponseType() ⇒ boolean
Returns true, when responder is not sending an update (notification) message
Kind: instance method of Responder
responder.setData(data) ⇒ this
Set temporary data to responder, which are persisted through single event
Kind: instance method of Responder
| Param | Type |
|---|---|
| data | object |
Example
bot.use('foo', (req, res, postBack) => {res.setData({ a: 1 });postBack('bar');});bot.use('bar', (req, res) => {res.data.a; // === 1 from postback});
responder.text(text, [replies], [voice], [options]) ⇒ this
Send text as a response
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| text | string | text to send to user, can contain placeholders (%s) | |
| [replies] | Object.<string, (string|QuickReply)> | Array.<QuickReply> | | quick replies |
| [voice] | VoiceControl | | voice control data |
| [options] | MessageOptions | {} |
Example
// simplyres.text('Hello', {action: 'Quick reply',another: 'Another quick reply'});// complexres.text('Hello', [{ action: 'action', title: 'Quick reply' },{action: 'complexAction', // requiredtitle: 'Another quick reply', // requiredsetState: { prop: 'value' }, // optionalmatch: 'text' || /regexp/ || ['intent'], // optionaldata: { foo: 1 }'Will be included in payload data' // optional}]);
responder.setState(object) ⇒ this
Sets new attributes to state (with Object.assign())
Kind: instance method of Responder
| Param | Type |
|---|---|
| object | object |
Example
res.setState({ visited: true });
responder.addQuickReply(action, [title], [data], [prepend], [justToExisting])
Deprecated
Appends quick reply, to be sent with following text method
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| action | string | QuickReply | relative or absolute action | |
| [title] | string | quick reply title | |
| [data] | object | additional data | |
| [prepend] | boolean | false | set true to add reply at the beginning |
| [justToExisting] | boolean | false | add quick reply only to existing replies |
Example
bot.use((req, res) => {res.addQuickReply('barAction', 'last action');res.addQuickReply('theAction', 'first action', {}, true);res.text('Text', {fooAction: 'goto foo'}); // will be merged and sent with previously added quick replies});
responder.quickReply(reply, [atStart], [toLastMessage], [ifNotExists]) ⇒ this
Adds quick reply, to be sent by following text message
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| reply | QuickReply | |
| [atStart] | boolean | false |
| [toLastMessage] | boolean | true |
| [ifNotExists] | boolean | false |
Example
bot.use((req, res) => {res.quickReply({ action: 'barAction', title: 'last action' });res.text('Text', {fooAction: 'goto foo'}); // will be merged and sent with previously added quick replies});
responder.keepPreviousContext(req, [justOnce], [includeKeywords]) ⇒ this
To be able to keep context of previous interaction (expected action and intents) Just use this method to let user to answer again.
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| req | Request | ||
| [justOnce] | boolean | false | don't do it again |
| [includeKeywords] | boolean | false | keep intents from quick replies |
Example
bot.use('start', (req, res) => {res.text('What color do you like?', [{ match: ['@Color=red'], text: 'red', action: 'red' },{ match: ['@Color=blue'], text: 'blue', action: 'blue' }]);res.expected('need-color')});bot.use('need-color', (req, res) => {res.keepPreviousContext(req);res.text('Sorry, only red or blue.');});
responder.expectedIntent(intents, action, data, [setState], [aiTitle])
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| intents | string | Array.<string> | |
| action | string | |
| data | object | |
| [setState] | object | |
| [aiTitle] | string | Array.<object> | null |
responder.expected(action, data) ⇒ this
When user writes some text as reply, it will be processed as action
Kind: instance method of Responder
| Param | Type | Description |
|---|---|---|
| action | string | desired action |
| data | object | desired action data |
responder.expectedConfidentInput([expectedInput]) ⇒ this
Makes a following user input anonymized
- disables processing of it with NLP
- replaces text content of incomming request before
storing it at ChatLogStorage using a
confidentInputFilter req.isConfidentInput()will return true
After processing the user input, next requests will be processed as usual,
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [expectedInput] | ExpectedInput | |
Example
const { Router } = require('wingbot');const bot = new Router();bot.use('start', (req, res) => {// evil questionres.text('Give me your CARD NUMBER :D').expected('received-card-number').expectedConfidentInput();});bot.use('received-card-number', (req, res) => {const cardNumber = req.text();// raw card numberreq.isConfidentInput(); // trueres.text('got it').setState({ cardNumber });});
responder.expectedInput(type, [options]) ⇒ this
Kind: instance method of Responder
| Param | Type |
|---|---|
| type | ExpectedInput |
| [options] | ExpectedInputOptions |
Example
bot.use((req, res) => {res.expectedInput(res.ExpectedInputTypes.TYPE_PASSWORD)});
responder.toAbsoluteAction(action, [forceStartingSlash]) ⇒ string
Converts relative action to absolute action path
Kind: instance method of Responder
Returns: string - absolute action path
| Param | Type | Default | Description |
|---|---|---|---|
| action | string | relative action to covert to absolute | |
| [forceStartingSlash] | boolean | false |
responder.currentAction() ⇒ string
Returns current action path
Kind: instance method of Responder
responder.upload(data, contentType, fileName) ⇒ Promise.<UploadResult>
Kind: instance method of Responder
| Param | Type |
|---|---|
| data | Buffer |
| contentType | string |
| fileName | string |
responder.image(imageUrl, [reusable]) ⇒ this
Sends image as response. Requires appUrl option to send images from server
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| imageUrl | string | relative or absolute url | |
| [reusable] | boolean | false | force facebook to cache image |
Example
// image on same server (appUrl option)res.image('/img/foo.png');// image at urlres.image('https://google.com/img/foo.png');
responder.video(videoUrl, [reusable]) ⇒ this
Sends video as response. Requires appUrl option to send videos from server
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| videoUrl | string | relative or absolute url | |
| [reusable] | boolean | false | force facebook to cache asset |
Example
// file on same server (appUrl option)res.video('/img/foo.mp4');// file at urlres.video('https://google.com/img/foo.mp4');
responder.file(fileUrl, [reusable]) ⇒ this
Sends file as response. Requires appUrl option to send files from server
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| fileUrl | string | relative or absolute url | |
| [reusable] | boolean | false | force facebook to cache asset |
Example
// file on same server (appUrl option)res.file('/img/foo.pdf');// file at urlres.file('https://google.com/img/foo.pdf');
responder.oneTimeNotificationRequest(title, action, [tag], [data]) ⇒ this
One-time Notification request
use tag to be able to use the specific token with a specific campaign
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| title | string | propmt text | |
| action | string | target action, when user subscribes | |
| [tag] | string | null | subscribtion tag, which will be matched against a campaign |
| [data] | object |
responder.wait([ms]) ⇒ this
Sets delay between two responses
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [ms] | number | 600 |
responder.typingOn([force]) ⇒ this
Sends "typing..." information
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| [force] | boolean | false | send even if was recently sent |
responder.typingOff() ⇒ this
Stops "typing..." information
Kind: instance method of Responder
responder.seen() ⇒ this
Reports last message from user as seen
Kind: instance method of Responder
responder.passThread(targetAppId, [data]) ⇒ this
Pass thread to another app
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| targetAppId | string | |
| [data] | string | object | null |
responder.requestThread([data]) ⇒ this
Request thread from Primary Receiver app
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [data] | string | object | null |
responder.takeThead([data]) ⇒ this
Take thread from another app
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [data] | string | object | null |
responder.receipt(recipientName, [paymentMethod], [currency], [uniqueCode]) ⇒ ReceiptTemplate
Sends Receipt template
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| recipientName | string | ||
| [paymentMethod] | string | "'Cash'" | should not contain more then 4 numbers |
| [currency] | string | "'USD'" | sets right currency |
| [uniqueCode] | string | null | when omitted, will be generated randomly |
Example
res.receipt('Name', 'Cash', 'CZK', '1').addElement('Element name', 1, 2, '/inside.png', 'text').send();
responder.button(text) ⇒ ButtonTemplate
Sends nice button template. It can redirect user to server with token in url
Kind: instance method of Responder
| Param | Type |
|---|---|
| text | string |
Example
res.button('Hello').postBackButton('Text', 'action').urlButton('Url button', '/internal', true) // opens webview with token.urlButton('Other button', 'https://goo.gl') // opens in internal browser.send();
responder.genericTemplate([shareable], [isSquare]) ⇒ GenericTemplate
Creates a generic template
Kind: instance method of Responder
| Param | Type | Default | Description |
|---|---|---|---|
| [shareable] | boolean | false | ability to share template |
| [isSquare] | boolean | false | use square aspect ratio for images |
Example
res.genericTemplate().addElement('title', 'subtitle').setElementImage('/local.png').setElementAction('https://www.seznam.cz').postBackButton('Button title', 'action', { actionData: 1 }).addElement('another', 'subtitle').setElementImage('https://goo.gl/image.png').setElementActionPostback('action', { actionData: 1 }).urlButton('Local link with extension', '/local/path', true, 'compact').send();
responder.list([topElementStyle]) ⇒ ListTemplate
Creates a generic template
Kind: instance method of Responder
| Param | Type | Default |
|---|---|---|
| [topElementStyle] | 'large' | 'compact' | 'large' |
Example
res.list('compact').postBackButton('Main button', 'action', { actionData: 1 }).addElement('title', 'subtitle').setElementImage('/local.png').setElementUrl('https://www.seznam.cz').postBackButton('Button title', 'action', { actionData: 1 }).addElement('another', 'subtitle').setElementImage('https://goo.gl/image.png').setElementAction('action', { actionData: 1 }).urlButton('Local link with extension', '/local/path', true, 'compact').send();
responder.nextOutputConfident(anonymizer)
Set next message as confident
Kind: instance method of Responder
| Param | Type |
|---|---|
| anonymizer | TextFilter |
responder.trackAs(action) ⇒ this
Override action tracking
Kind: instance method of Responder
| Param | Type | Description |
|---|---|---|
| action | string | boolean | use false to not emit analytics events |
responder.trackAsSkill(skill) ⇒ this
Set skill for tracking (will used untill it will be changed)
Kind: instance method of Responder
| Param | Type |
|---|---|
| skill | string | null |
ExpectedInput : enum
ExpectedInput
Kind: global enum
Read only: true
Properties
| Name | Type | Default |
|---|---|---|
| TYPE_PASSWORD | string | "password" |
| TYPE_NONE | string | "none" |
| TYPE_UPLOAD | string | "upload" |
| TYPE_WEBVIEW | string | "webview" |
ExpectedInputOptions : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [url] | string |
| [webview_height_ratio] | string |
| [onCloseAction] | string |
| [onCloseActionData] | string |
QuickReply : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| title | string |
| [action] | string |
| [data] | object |
| [setState] | object |
| [aiTitle] | string | function |
| [match] | RegExp | string | Array.<string> |
SenderMeta : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| flag | ResponseFlag | null |
| [likelyIntent] | string |
| [disambText] | string |
| [disambiguationIntents] | Array.<string> |
VoiceControl : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [ssml] | string |
| [speed] | number |
| [pitch] | number |
| [volume] | number |
| [style] | string |
| [language] | string |
| [voice] | string |
| [timeout] | number |
| [minTimeout] | number |
| [endTimeout] | number |
| [recognitionLanguage] | string |
| [recognitionEngine] | string |
VoiceControlFactory ⇒ VoiceControl
Kind: global typedef
| Param | Type |
|---|---|
| state | object |
Persona : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [profile_pic_url] | string |
| [name] | string |
PromptGetter ⇒ string | Promise.<string>
Kind: global typedef
| Param | Type |
|---|---|
| res | Responder |
PromptSource : PromptGetter | string
Kind: global typedef
PromptContextItem : PromptSource | Promise.<string>
Kind: global typedef
PromisedString : Promise.<string>
Kind: global typedef
MessageOptions : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| [disableAutoTyping] | boolean |