Classes

Responder

Instance of responder is passed as second parameter of handler (res)

Typedefs

ExpectedInputOptions : object
QuickReply : object
SenderMeta : object
VoiceControl : object
VoiceControlFactoryVoiceControl
Persona : object
 

Responder

Instance of responder is passed as second parameter of handler (res)

Kind: global class

 

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.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

ParamType
blockNamestring

Properties

Type
function
 

responder.setFlag(flag) ⇒ this

Kind: instance method of Responder

ParamType
flagstring
 

responder.getTranscript([limit], [onlyFlag], [skipThisTurnaround]) ⇒ Promise.<Array.<Transcript>>

Returns current conversation transcript

Kind: instance method of Responder

ParamTypeDefault
[limit]number10
[onlyFlag]stringnull
[skipThisTurnaround]booleanfalse
 

responder.setNotificationRecipient(recipient)

Replaces recipient and disables autotyping Usefull for sending a one-time notification

Kind: instance method of Responder

ParamType
recipientobject
 

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

ParamTypeDefaultDescription
typeTrackingType(log,report,conversation,audit,user,training)
categoryTrackingCategory
[action]string
[label]string
[value]number0
 

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

ParamType
dataobject

Example

res.send({ message: { text: 'Hello!' } });
 

responder.setBookmark([action], [winningIntent]) ⇒ this

Deprecated

Stores current action to be able to all it again

Kind: instance method of Responder

ParamTypeDefault
[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

Deprecated

Returns the action of bookmark

Kind: instance method of Responder

 

responder.runBookmark(postBack, [data]) ⇒ Promise.<(null|boolean)>

Deprecated

Kind: instance method of Responder

ParamTypeDescription
postBackfunctionthe postback func
[data]objectdata 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

ParamTypeDefault
messagingTypestring
[tag]stringnull
 

responder.setPersona(personaId) ⇒ this

Tets the persona for following requests

Kind: instance method of Responder

ParamTypeDefault
personaIdPersona | 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

ParamType
dataobject

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]) ⇒ this

Send text as a response

Kind: instance method of Responder

ParamTypeDefaultDescription
textstringtext to send to user, can contain placeholders (%s)
[replies]Object.<string, (string|QuickReply)> | Array.<QuickReply>quick replies
[voice]VoiceControlvoice control data

Example

// simply
res.text('Hello', {
action: 'Quick reply',
another: 'Another quick reply'
});
// complex
res.text('Hello', [
{ action: 'action', title: 'Quick reply' },
{
action: 'complexAction', // required
title: 'Another quick reply', // required
setState: { prop: 'value' }, // optional
match: 'text' || /regexp/ || ['intent'], // optional
data: { 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

ParamType
objectobject

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

ParamTypeDefaultDescription
actionstring | QuickReplyrelative or absolute action
[title]stringquick reply title
[data]objectadditional data
[prepend]booleanfalseset true to add reply at the beginning
[justToExisting]booleanfalseadd 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

ParamTypeDefault
replyQuickReply
[atStart]booleanfalse
[toLastMessage]booleantrue
[ifNotExists]booleanfalse

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

ParamTypeDefaultDescription
reqRequest
[justOnce]booleanfalsedon't do it again
[includeKeywords]booleanfalsekeep 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

ParamTypeDefault
intentsstring | Array.<string>
actionstring
dataobject
[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

ParamTypeDescription
actionstringdesired action
dataobjectdesired 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

ParamTypeDefault
[expectedInput]ExpectedInput

Example

const { Router } = require('wingbot');
const bot = new Router();
bot.use('start', (req, res) => {
// evil question
res.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 number
req.isConfidentInput(); // true
res.text('got it')
.setState({ cardNumber });
});
 

responder.expectedInput(type, [options]) ⇒ this

Kind: instance method of Responder

ParamType
typeExpectedInput
[options]ExpectedInputOptions

Example

bot.use((req, res) => {
res.expectedInput(res.ExpectedInputTypes.TYPE_PASSWORD)
});
 

responder.toAbsoluteAction(action) ⇒ string

Converts relative action to absolute action path

Kind: instance method of Responder
Returns: string - absolute action path

ParamTypeDescription
actionstringrelative action to covert to absolute
 

responder.currentAction() ⇒ string

Returns current action path

Kind: instance method of Responder

 

responder.upload(data, contentType, fileName) ⇒ Promise.<UploadResult>

Kind: instance method of Responder

ParamType
dataBuffer
contentTypestring
fileNamestring
 

responder.image(imageUrl, [reusable]) ⇒ this

Sends image as response. Requires appUrl option to send images from server

Kind: instance method of Responder

ParamTypeDefaultDescription
imageUrlstringrelative or absolute url
[reusable]booleanfalseforce facebook to cache image

Example

// image on same server (appUrl option)
res.image('/img/foo.png');
// image at url
res.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

ParamTypeDefaultDescription
videoUrlstringrelative or absolute url
[reusable]booleanfalseforce facebook to cache asset

Example

// file on same server (appUrl option)
res.video('/img/foo.mp4');
// file at url
res.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

ParamTypeDefaultDescription
fileUrlstringrelative or absolute url
[reusable]booleanfalseforce facebook to cache asset

Example

// file on same server (appUrl option)
res.file('/img/foo.pdf');
// file at url
res.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

ParamTypeDefaultDescription
titlestringpropmt text
actionstringtarget action, when user subscribes
[tag]stringnullsubscribtion tag, which will be matched against a campaign
[data]object
 

responder.wait([ms]) ⇒ this

Sets delay between two responses

Kind: instance method of Responder

ParamTypeDefault
[ms]number600
 

responder.typingOn([force]) ⇒ this

Sends "typing..." information

Kind: instance method of Responder

ParamTypeDefaultDescription
[force]booleanfalsesend 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

ParamTypeDefault
targetAppIdstring
[data]string | objectnull
 

responder.requestThread([data]) ⇒ this

Request thread from Primary Receiver app

Kind: instance method of Responder

ParamTypeDefault
[data]string | objectnull
 

responder.takeThead([data]) ⇒ this

Take thread from another app

Kind: instance method of Responder

ParamTypeDefault
[data]string | objectnull
 

responder.receipt(recipientName, [paymentMethod], [currency], [uniqueCode]) ⇒ ReceiptTemplate

Sends Receipt template

Kind: instance method of Responder

ParamTypeDefaultDescription
recipientNamestring
[paymentMethod]string"'Cash'"should not contain more then 4 numbers
[currency]string"'USD'"sets right currency
[uniqueCode]stringnullwhen 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

ParamType
textstring

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

ParamTypeDefaultDescription
[shareable]booleanfalseability to share template
[isSquare]booleanfalseuse 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

ParamTypeDefault
[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

ParamType
anonymizerTextFilter
 

responder.trackAs(action) ⇒ this

Override action tracking

Kind: instance method of Responder

ParamTypeDescription
actionstring | booleanuse 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

ParamType
skillstring | null
 

ExpectedInput : enum

ExpectedInput

Kind: global enum
Read only: true
Properties

NameTypeDefault
TYPE_PASSWORDstring"password"
TYPE_NONEstring"none"
TYPE_UPLOADstring"upload"
TYPE_WEBVIEWstring"webview"
 

ExpectedInputOptions : object

Kind: global typedef
Properties

NameType
[url]string
[webview_height_ratio]string
[onCloseAction]string
[onCloseActionData]string
 

QuickReply : object

Kind: global typedef
Properties

NameType
titlestring
[action]string
[data]object
[setState]object
[aiTitle]string | function
[match]RegExp | string | Array.<string>
 

SenderMeta : object

Kind: global typedef
Properties

NameType
flagResponseFlag | null
[likelyIntent]string
[disambText]string
[disambiguationIntents]Array.<string>
 

VoiceControl : object

Kind: global typedef
Properties

NameType
[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

ParamType
stateobject
 

Persona : object

Kind: global typedef
Properties

NameType
[profile_pic_url]string
[name]string