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
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
- .senderMeta ⇒
SenderMeta
- .data :
object
- .textResponses ⇒
Array.<string>
- .run(blockName) ⇒
Promise
- .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]) ⇒
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) ⇒
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 |
VoiceControl
| VoiceControlFactory
responder.voiceControl : Kind: instance property of Responder
SendOptions
responder._nextMessageSendOptions : Kind: instance property of Responder
SenderMeta
responder.senderMeta ⇒ Response has been marked with a flag
Kind: instance property of Responder
object
responder.data : Kind: instance property of Responder
Array.<string>
responder.textResponses ⇒ Return array of text responses
Kind: instance property of Responder
Promise
responder.run(blockName) ⇒ Run a code block defined by a plugin
Kind: instance method of Responder
Param | Type |
---|---|
blockName | string |
Properties
Type |
---|
function |
this
responder.setFlag(flag) ⇒ Kind: instance method of Responder
Param | Type |
---|---|
flag | string |
Promise.<Array.<Transcript>>
responder.getTranscript([limit], [onlyFlag], [skipThisTurnaround]) ⇒ 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 |
this
responder.doNotLogTheEvent() ⇒ Disables logging the event to history
Kind: instance method of Responder
this
responder.trackEvent(type, category, [action], [label], [value]) ⇒ 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 |
this
responder.send(data) ⇒ 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
this
Deprecated
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
| null
Deprecated
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()}`);})
this
responder.setMessagingType(messagingType, [tag]) ⇒ Kind: instance method of Responder
Param | Type | Default |
---|---|---|
messagingType | string | |
[tag] | string | null |
this
responder.setPersona(personaId) ⇒ Tets the persona for following requests
Kind: instance method of Responder
Param | Type | Default |
---|---|---|
personaId | Persona | string | null |
|
boolean
responder.isResponseType() ⇒ Returns true, when responder is not sending an update (notification) message
Kind: instance method of Responder
this
responder.setData(data) ⇒ 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});
this
responder.text(text, [replies], [voice]) ⇒ 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 |
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}]);
this
responder.setState(object) ⇒ 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});
this
responder.quickReply(reply, [atStart], [toLastMessage], [ifNotExists]) ⇒ 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});
this
responder.keepPreviousContext(req, [justOnce], [includeKeywords]) ⇒ 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 |
this
responder.expected(action, data) ⇒ 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 |
this
responder.expectedConfidentInput([expectedInput]) ⇒ 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 });});
this
responder.expectedInput(type, [options]) ⇒ Kind: instance method of Responder
Param | Type |
---|---|
type | ExpectedInput |
[options] | ExpectedInputOptions |
Example
bot.use((req, res) => {res.expectedInput(res.ExpectedInputTypes.TYPE_PASSWORD)});
string
responder.toAbsoluteAction(action) ⇒ Converts relative action to absolute action path
Kind: instance method of Responder
Returns: string
- absolute action path
Param | Type | Description |
---|---|---|
action | string | relative action to covert to absolute |
string
responder.currentAction() ⇒ Returns current action path
Kind: instance method of Responder
Promise.<UploadResult>
responder.upload(data, contentType, fileName) ⇒ Kind: instance method of Responder
Param | Type |
---|---|
data | Buffer |
contentType | string |
fileName | string |
this
responder.image(imageUrl, [reusable]) ⇒ 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');
this
responder.video(videoUrl, [reusable]) ⇒ 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');
this
responder.file(fileUrl, [reusable]) ⇒ 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');
this
responder.oneTimeNotificationRequest(title, action, [tag], [data]) ⇒ 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 |
this
responder.wait([ms]) ⇒ Sets delay between two responses
Kind: instance method of Responder
Param | Type | Default |
---|---|---|
[ms] | number | 600 |
this
responder.typingOn([force]) ⇒ Sends "typing..." information
Kind: instance method of Responder
Param | Type | Default | Description |
---|---|---|---|
[force] | boolean | false | send even if was recently sent |
this
responder.typingOff() ⇒ Stops "typing..." information
Kind: instance method of Responder
this
responder.seen() ⇒ Reports last message from user as seen
Kind: instance method of Responder
this
responder.passThread(targetAppId, [data]) ⇒ Pass thread to another app
Kind: instance method of Responder
Param | Type | Default |
---|---|---|
targetAppId | string | |
[data] | string | object | null |
this
responder.requestThread([data]) ⇒ Request thread from Primary Receiver app
Kind: instance method of Responder
Param | Type | Default |
---|---|---|
[data] | string | object | null |
this
responder.takeThead([data]) ⇒ Take thread from another app
Kind: instance method of Responder
Param | Type | Default |
---|---|---|
[data] | string | object | null |
ReceiptTemplate
responder.receipt(recipientName, [paymentMethod], [currency], [uniqueCode]) ⇒ 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();
ButtonTemplate
responder.button(text) ⇒ 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();
GenericTemplate
responder.genericTemplate([shareable], [isSquare]) ⇒ 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();
ListTemplate
responder.list([topElementStyle]) ⇒ 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 |
this
responder.trackAs(action) ⇒ Override action tracking
Kind: instance method of Responder
Param | Type | Description |
---|---|---|
action | string | boolean | use false to not emit analytics events |
this
responder.trackAsSkill(skill) ⇒ Set skill for tracking (will used untill it will be changed)
Kind: instance method of Responder
Param | Type |
---|---|
skill | string | null |
enum
ExpectedInput : 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" |
object
ExpectedInputOptions : Kind: global typedef
Properties
Name | Type |
---|---|
[url] | string |
[webview_height_ratio] | string |
[onCloseAction] | string |
[onCloseActionData] | string |
object
QuickReply : Kind: global typedef
Properties
Name | Type |
---|---|
title | string |
[action] | string |
[data] | object |
[setState] | object |
[aiTitle] | string | function |
[match] | RegExp | string | Array.<string> |
object
SenderMeta : Kind: global typedef
Properties
Name | Type |
---|---|
flag | ResponseFlag | null |
[likelyIntent] | string |
[disambText] | string |
[disambiguationIntents] | Array.<string> |
object
VoiceControl : 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 |
VoiceControl
VoiceControlFactory ⇒ Kind: global typedef
Param | Type |
---|---|
state | object |
object
Persona : Kind: global typedef
Properties
Name | Type |
---|---|
[profile_pic_url] | string |
[name] | string |