Classes

Request
Request

Constants

FEATURE_VOICE : string

channel supports voice messages

FEATURE_SSML : string

channel supports SSML voice messages

FEATURE_PHRASES : string

channel supports expected phrases messages

FEATURE_TEXT : string

channel supports text communication

FEATURE_TRACKING : string

channel supports tracking protocol

FEATURE_VOICE : string

channel supports voice messages

FEATURE_SSML : string

channel supports SSML voice messages

FEATURE_PHRASES : string

channel supports expected phrases messages

FEATURE_TEXT : string

channel supports text communication

FEATURE_TRACKING : string

channel supports tracking protocol

Typedefs

Entity : object
Intent : object
Action : object
IntentAction : object
QuickReply : object
QuickReplyDisambiguation : object
RequestOrchestratorOptions : object
TextAlternative : object
Attachment : object
AiSetStateOption : number
 

Request

Kind: global class

 

new Request()

Instance of {Request} class is passed as first parameter of handler (req)

 

new Request(event, state, pageId, globalIntents, [orchestratorOptions], [configuration])

ParamType
event*
stateS
pageIdstring
globalIntentsMap
[orchestratorOptions]RequestOrchestratorOptions
[configuration]C
 

request.params

Kind: instance property of Request
Properties

NameTypeDescription
paramsobjectplugin configuration
 

request.attachments : Array.<Attachment>

Kind: instance property of Request

 

request.timestamp : number | null

timestamp

Kind: instance property of Request

 

request.senderId : string

senderId sender.id from the event

Kind: instance property of Request

 

request.recipientId : string

recipientId recipient.id from the event

Kind: instance property of Request

 

request.pageId : string

pageId page identifier from the event

Kind: instance property of Request

 

request.state : S

current state of the conversation

Kind: instance property of Request

 

request.features : Array.<string>

features supported messaging features

Kind: instance property of Request

 

request.subscribtions : Array.<string>

state list of subscribed tags

Kind: instance property of Request

 

request.entities : Array.<Entity>

entities list of entities

Kind: instance property of Request

 

request.intents : Array.<Intent>

intents list of resolved intents

Kind: instance property of Request

 

request._orchestratorClientOptions : OrchestratorClientOptions

Kind: instance property of Request

 

request.configuration : C

Kind: instance property of Request

 

request.event : object

The original messaging event

Kind: instance property of Request

 

request.AI_SETSTATE : enum

Kind: instance enum of Request
Properties

NameTypeDefault
ONLYAiSetStateOption1
INCLUDEAiSetStateOption0
EXCLUDEAiSetStateOption-1
EXCLUDE_WITH_SET_ENTITIESAiSetStateOption-2
EXCLUDE_WITHOUT_SET_ENTITIESAiSetStateOption-3
 

request.supportsFeature(feature) ⇒ boolean

Returns true if a channel supports specified feature

Kind: instance method of Request

ParamType
featurestring
 

request.isStandby() ⇒ boolean

Returns true, if the incoming event is standby

Kind: instance method of Request

 

request.aiActions([local]) ⇒ Array.<IntentAction>

Get all matched actions from NLP intents

Kind: instance method of Request

ParamTypeDefault
[local]booleanfalse
 

request.aiActionsForQuickReplies([limit], [aiActions], [overrideAction]) ⇒ Array.<QuickReplyDisambiguation>

Covert all matched actions for disambiguation purposes

Kind: instance method of Request

ParamTypeDefault
[limit]number5
[aiActions]Array.<IntentAction>
[overrideAction]stringnull
 

request.hasAiActionsForDisambiguation(minimum, [local]) ⇒ boolean

Returns true, if there is an action for disambiguation

Kind: instance method of Request

ParamTypeDefault
minimumnumber1
[local]booleanfalse
 

request.intent(getDataOrScore) ⇒ null | string | Intent

Returns intent, when using AI

Kind: instance method of Request

ParamTypeDefaultDescription
getDataOrScoreboolean | numberfalsescore limit or true for getting intent data
 

request.entity(name, [sequence]) ⇒ number | string | null

Get matched entity value

Kind: instance method of Request

ParamTypeDefaultDescription
namestringname of requested entity
[sequence]number0when there are more then one entity
 

request.isAttachment() ⇒ boolean

Checks, when message contains an attachment (file, image or location)

Kind: instance method of Request

 

request.isSetContext(varsToCheck)

Orchestrator: check, if the request updates only $context variables

  • when no variables to check provided, returns false when set_context is bundled within another conversational event

Kind: instance method of Request

ParamTypeDescription
varsToCheckArray.<string>list of variables to check
 

request.getSetContext([includeContextSync]) ⇒ object

Orchestrator: get current thread context update

Kind: instance method of Request
Returns: object - - with § prefixed keys

ParamTypeDefault
[includeContextSync]booleanfalse
 

request.isImage([attachmentIndex], [includingStickers]) ⇒ boolean

Checks, when the attachment is an image, but not a sticker

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
[includingStickers]booleanfalsereturn true, when the image is also a sticker
 

request.isFile([attachmentIndex]) ⇒ boolean

Checks, when the attachment is a file

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.hasLocation() ⇒ boolean

Checks for location in attachments

Kind: instance method of Request

 

request.getLocation() ⇒ null | Object

Gets location coordinates from attachment, when exists

Kind: instance method of Request
Example

const { Router } = require('wingbot');
const bot = new Router();
bot.use('start', (req, res) => {
res.text('share location?', [
// location share quick reply
{ action: 'locAction', title: 'Share location', isLocation: true }
]);
});
bot.use('locAction', (req, res) => {
if (req.hasLocation()) {
const { lat, long } = req.getLocation();
res.text(`Got ${lat}, ${long}`);
} else {
res.text('No location received');
}
});
 

request.attachment([attachmentIndex]) ⇒ object | null

Returns whole attachment or null

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.attachmentUrl([attachmentIndex]) ⇒ string | null

Returns attachment URL

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.isMessage() ⇒ boolean

Returns true, when the request is text message, quick reply or attachment

Kind: instance method of Request

 

request.isQuickReply() ⇒ boolean

Check, that message is a quick reply

Kind: instance method of Request

 

request.isText() ⇒ boolean

Check, that message is PURE text

Kind: instance method of Request

 

request.isSticker([includeToTextStickers]) ⇒ boolean

Returns true, when the attachment is a sticker

Kind: instance method of Request

ParamTypeDefaultDescription
[includeToTextStickers]booleanfalseincluding strickers transformed into a text
 

request.text([tokenized]) ⇒ string

Returns text of the message

Kind: instance method of Request

ParamTypeDefaultDescription
[tokenized]booleanfalsewhen true, message is normalized to lowercase with -

Example

console.log(req.text(true)) // "can-you-help-me"
 

request.textAlternatives() ⇒ Array.<TextAlternative>

Returns all text message alternatives including it's score

Kind: instance method of Request

 

request.expected() ⇒ Action | null

Returns the request expected handler in case have been set last response

Kind: instance method of Request

 

request.expectedKeywords([justOnce])

Returns all expected keywords for the next request (just expected keywords)

Kind: instance method of Request

ParamTypeDefaultDescription
[justOnce]booleanfalse- don't return already retained items

Example

bot.use('my-route', (req, res) => {
res.setState(req.expectedKeywords());
});
 

request.expectedContext([justOnce], [includeKeywords]) ⇒ object

Returns current turn-around context (expected and expected keywords)

Kind: instance method of Request

ParamTypeDefaultDescription
[justOnce]booleanfalsedon't return already retained items
[includeKeywords]booleanfalsekeep intents from quick replies

Example

bot.use('my-route', (req, res) => {
res.setState(req.expectedContext());
});
 

request.quickReply([getData]) ⇒ null | string | object

Returns action or data of quick reply When getData is true, object will be returned. Otherwise string or null.

Kind: instance method of Request

ParamTypeDefault
[getData]booleanfalse

Example

typeof res.quickReply() === 'string' || res.quickReply() === null;
typeof res.quickReply(true) === 'object';
 

request.isPostBack() ⇒ boolean

Returns true, if request is the postback

Kind: instance method of Request

 

request.isReferral() ⇒ boolean

Returns true, if request is the referral

Kind: instance method of Request

 

request.isOptin() ⇒ boolean

Returns true, if request is the optin

Kind: instance method of Request

 

request.setAction(action, [data]) ⇒ Action | null | undefined

Sets the action and returns previous action

Kind: instance method of Request
Returns: Action | null | undefined - - previous action

ParamType
actionstring | Action | null
[data]object
 

request.action([getData]) ⇒ null | string

Returns action of the postback or quickreply

the order, where from the action is resolved

  1. referral
  2. postback
  3. optin
  4. quick reply
  5. expected keywords & intents
  6. expected action in state
  7. global or local AI intent action

Kind: instance method of Request

ParamTypeDefaultDescription
[getData]booleanfalsedeprecated

Example

typeof res.action() === 'string' || res.action() === null;
typeof res.actionData() === 'object';
 

request.actionData() ⇒ object

Returns action data of postback or quick reply

Kind: instance method of Request

 

request.getSetState(keysFromAi) ⇒ object

Gets incomming setState action variable

Kind: instance method of Request

ParamType
keysFromAiAiSetStateOption

Example

res.setState(req.getSetState());
 

request.isConfidentInput() ⇒ boolean

Returns true, if previous request has been marked as confident using res.expectedConfidentInput()

It's good to consider this state in "analytics" integrations.

Kind: instance method of Request

 

request.actionByAi() ⇒ string | null

Returs action string, if there is an action detected by NLP

use rather designer's bounce feature instead of this pattern

Kind: instance method of Request
Example

const { Router } = require('wingbot');
const bot = new Router();
bot.use('question', (req, res) => {
res.text('tell me your email')
.expected('email');
});
bot.use('email', async (req, res, postBack) => {
if (req.actionByAi()) {
await postBack(req.actionByAi(), {}, true);
return;
}
res.text('thank you for your email');
res.setState({ email: req.text() });
});
 

request.aiActionsWinner() ⇒ IntentAction | null

Returns full detected AI action

Kind: instance method of Request

 

request.postBack([getData]) ⇒ null | string | object

Returns action or data of postback When getData is true, object will be returned. Otherwise string or null.

Kind: instance method of Request

ParamTypeDefault
[getData]booleanfalse

Example

typeof res.postBack() === 'string' || res.postBack() === null;
typeof res.postBack(true) === 'object';
 

request.expectedEntities() ⇒ Array.<string>

Kind: instance method of Request

 

Request

Kind: global class

 

new Request()

Instance of {Request} class is passed as first parameter of handler (req)

 

new Request(event, state, pageId, globalIntents, [orchestratorOptions], [configuration])

ParamType
event*
stateS
pageIdstring
globalIntentsMap
[orchestratorOptions]RequestOrchestratorOptions
[configuration]C
 

request.params

Kind: instance property of Request
Properties

NameTypeDescription
paramsobjectplugin configuration
 

request.attachments : Array.<Attachment>

Kind: instance property of Request

 

request.timestamp : number | null

timestamp

Kind: instance property of Request

 

request.senderId : string

senderId sender.id from the event

Kind: instance property of Request

 

request.recipientId : string

recipientId recipient.id from the event

Kind: instance property of Request

 

request.pageId : string

pageId page identifier from the event

Kind: instance property of Request

 

request.state : S

current state of the conversation

Kind: instance property of Request

 

request.features : Array.<string>

features supported messaging features

Kind: instance property of Request

 

request.subscribtions : Array.<string>

state list of subscribed tags

Kind: instance property of Request

 

request.entities : Array.<Entity>

entities list of entities

Kind: instance property of Request

 

request.intents : Array.<Intent>

intents list of resolved intents

Kind: instance property of Request

 

request._orchestratorClientOptions : OrchestratorClientOptions

Kind: instance property of Request

 

request.configuration : C

Kind: instance property of Request

 

request.event : object

The original messaging event

Kind: instance property of Request

 

request.AI_SETSTATE : enum

Kind: instance enum of Request
Properties

NameTypeDefault
ONLYAiSetStateOption1
INCLUDEAiSetStateOption0
EXCLUDEAiSetStateOption-1
EXCLUDE_WITH_SET_ENTITIESAiSetStateOption-2
EXCLUDE_WITHOUT_SET_ENTITIESAiSetStateOption-3
 

request.supportsFeature(feature) ⇒ boolean

Returns true if a channel supports specified feature

Kind: instance method of Request

ParamType
featurestring
 

request.isStandby() ⇒ boolean

Returns true, if the incoming event is standby

Kind: instance method of Request

 

request.aiActions([local]) ⇒ Array.<IntentAction>

Get all matched actions from NLP intents

Kind: instance method of Request

ParamTypeDefault
[local]booleanfalse
 

request.aiActionsForQuickReplies([limit], [aiActions], [overrideAction]) ⇒ Array.<QuickReplyDisambiguation>

Covert all matched actions for disambiguation purposes

Kind: instance method of Request

ParamTypeDefault
[limit]number5
[aiActions]Array.<IntentAction>
[overrideAction]stringnull
 

request.hasAiActionsForDisambiguation(minimum, [local]) ⇒ boolean

Returns true, if there is an action for disambiguation

Kind: instance method of Request

ParamTypeDefault
minimumnumber1
[local]booleanfalse
 

request.intent(getDataOrScore) ⇒ null | string | Intent

Returns intent, when using AI

Kind: instance method of Request

ParamTypeDefaultDescription
getDataOrScoreboolean | numberfalsescore limit or true for getting intent data
 

request.entity(name, [sequence]) ⇒ number | string | null

Get matched entity value

Kind: instance method of Request

ParamTypeDefaultDescription
namestringname of requested entity
[sequence]number0when there are more then one entity
 

request.isAttachment() ⇒ boolean

Checks, when message contains an attachment (file, image or location)

Kind: instance method of Request

 

request.isSetContext(varsToCheck)

Orchestrator: check, if the request updates only $context variables

  • when no variables to check provided, returns false when set_context is bundled within another conversational event

Kind: instance method of Request

ParamTypeDescription
varsToCheckArray.<string>list of variables to check
 

request.getSetContext([includeContextSync]) ⇒ object

Orchestrator: get current thread context update

Kind: instance method of Request
Returns: object - - with § prefixed keys

ParamTypeDefault
[includeContextSync]booleanfalse
 

request.isImage([attachmentIndex], [includingStickers]) ⇒ boolean

Checks, when the attachment is an image, but not a sticker

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
[includingStickers]booleanfalsereturn true, when the image is also a sticker
 

request.isFile([attachmentIndex]) ⇒ boolean

Checks, when the attachment is a file

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.hasLocation() ⇒ boolean

Checks for location in attachments

Kind: instance method of Request

 

request.getLocation() ⇒ null | Object

Gets location coordinates from attachment, when exists

Kind: instance method of Request
Example

const { Router } = require('wingbot');
const bot = new Router();
bot.use('start', (req, res) => {
res.text('share location?', [
// location share quick reply
{ action: 'locAction', title: 'Share location', isLocation: true }
]);
});
bot.use('locAction', (req, res) => {
if (req.hasLocation()) {
const { lat, long } = req.getLocation();
res.text(`Got ${lat}, ${long}`);
} else {
res.text('No location received');
}
});
 

request.attachment([attachmentIndex]) ⇒ object | null

Returns whole attachment or null

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.attachmentUrl([attachmentIndex]) ⇒ string | null

Returns attachment URL

Kind: instance method of Request

ParamTypeDefaultDescription
[attachmentIndex]number0use, when user sends more then one attachment
 

request.isMessage() ⇒ boolean

Returns true, when the request is text message, quick reply or attachment

Kind: instance method of Request

 

request.isQuickReply() ⇒ boolean

Check, that message is a quick reply

Kind: instance method of Request

 

request.isText() ⇒ boolean

Check, that message is PURE text

Kind: instance method of Request

 

request.isSticker([includeToTextStickers]) ⇒ boolean

Returns true, when the attachment is a sticker

Kind: instance method of Request

ParamTypeDefaultDescription
[includeToTextStickers]booleanfalseincluding strickers transformed into a text
 

request.text([tokenized]) ⇒ string

Returns text of the message

Kind: instance method of Request

ParamTypeDefaultDescription
[tokenized]booleanfalsewhen true, message is normalized to lowercase with -

Example

console.log(req.text(true)) // "can-you-help-me"
 

request.textAlternatives() ⇒ Array.<TextAlternative>

Returns all text message alternatives including it's score

Kind: instance method of Request

 

request.expected() ⇒ Action | null

Returns the request expected handler in case have been set last response

Kind: instance method of Request

 

request.expectedKeywords([justOnce])

Returns all expected keywords for the next request (just expected keywords)

Kind: instance method of Request

ParamTypeDefaultDescription
[justOnce]booleanfalse- don't return already retained items

Example

bot.use('my-route', (req, res) => {
res.setState(req.expectedKeywords());
});
 

request.expectedContext([justOnce], [includeKeywords]) ⇒ object

Returns current turn-around context (expected and expected keywords)

Kind: instance method of Request

ParamTypeDefaultDescription
[justOnce]booleanfalsedon't return already retained items
[includeKeywords]booleanfalsekeep intents from quick replies

Example

bot.use('my-route', (req, res) => {
res.setState(req.expectedContext());
});
 

request.quickReply([getData]) ⇒ null | string | object

Returns action or data of quick reply When getData is true, object will be returned. Otherwise string or null.

Kind: instance method of Request

ParamTypeDefault
[getData]booleanfalse

Example

typeof res.quickReply() === 'string' || res.quickReply() === null;
typeof res.quickReply(true) === 'object';
 

request.isPostBack() ⇒ boolean

Returns true, if request is the postback

Kind: instance method of Request

 

request.isReferral() ⇒ boolean

Returns true, if request is the referral

Kind: instance method of Request

 

request.isOptin() ⇒ boolean

Returns true, if request is the optin

Kind: instance method of Request

 

request.setAction(action, [data]) ⇒ Action | null | undefined

Sets the action and returns previous action

Kind: instance method of Request
Returns: Action | null | undefined - - previous action

ParamType
actionstring | Action | null
[data]object
 

request.action([getData]) ⇒ null | string

Returns action of the postback or quickreply

the order, where from the action is resolved

  1. referral
  2. postback
  3. optin
  4. quick reply
  5. expected keywords & intents
  6. expected action in state
  7. global or local AI intent action

Kind: instance method of Request

ParamTypeDefaultDescription
[getData]booleanfalsedeprecated

Example

typeof res.action() === 'string' || res.action() === null;
typeof res.actionData() === 'object';
 

request.actionData() ⇒ object

Returns action data of postback or quick reply

Kind: instance method of Request

 

request.getSetState(keysFromAi) ⇒ object

Gets incomming setState action variable

Kind: instance method of Request

ParamType
keysFromAiAiSetStateOption

Example

res.setState(req.getSetState());
 

request.isConfidentInput() ⇒ boolean

Returns true, if previous request has been marked as confident using res.expectedConfidentInput()

It's good to consider this state in "analytics" integrations.

Kind: instance method of Request

 

request.actionByAi() ⇒ string | null

Returs action string, if there is an action detected by NLP

use rather designer's bounce feature instead of this pattern

Kind: instance method of Request
Example

const { Router } = require('wingbot');
const bot = new Router();
bot.use('question', (req, res) => {
res.text('tell me your email')
.expected('email');
});
bot.use('email', async (req, res, postBack) => {
if (req.actionByAi()) {
await postBack(req.actionByAi(), {}, true);
return;
}
res.text('thank you for your email');
res.setState({ email: req.text() });
});
 

request.aiActionsWinner() ⇒ IntentAction | null

Returns full detected AI action

Kind: instance method of Request

 

request.postBack([getData]) ⇒ null | string | object

Returns action or data of postback When getData is true, object will be returned. Otherwise string or null.

Kind: instance method of Request

ParamTypeDefault
[getData]booleanfalse

Example

typeof res.postBack() === 'string' || res.postBack() === null;
typeof res.postBack(true) === 'object';
 

request.expectedEntities() ⇒ Array.<string>

Kind: instance method of Request

 

FEATURE_VOICE : string

channel supports voice messages

Kind: global constant

 

FEATURE_SSML : string

channel supports SSML voice messages

Kind: global constant

 

FEATURE_PHRASES : string

channel supports expected phrases messages

Kind: global constant

 

FEATURE_TEXT : string

channel supports text communication

Kind: global constant

 

FEATURE_TRACKING : string

channel supports tracking protocol

Kind: global constant

 

FEATURE_VOICE : string

channel supports voice messages

Kind: global constant

 

FEATURE_SSML : string

channel supports SSML voice messages

Kind: global constant

 

FEATURE_PHRASES : string

channel supports expected phrases messages

Kind: global constant

 

FEATURE_TEXT : string

channel supports text communication

Kind: global constant

 

FEATURE_TRACKING : string

channel supports tracking protocol

Kind: global constant

 

Entity : object

Kind: global typedef
Properties

NameType
entitystring
valuestring
scorenumber
[alternatives]Array.<Entity>
 

Intent : object

Kind: global typedef
Properties

NameType
intentstring
scorenumber
[entities]Array.<Entity>
 

Action : object

Kind: global typedef
Properties

NameType
actionstring
dataobject
[setState]object | null
 

IntentAction : object

Kind: global typedef
Properties

NameType
actionstring
intentIntent
sortnumber
localboolean
aboveConfidenceboolean
[data]object
[match]string | Array.<string>
[setState]object
[winner]boolean
[title]string | function
[hasAiTitle]boolean
metaobject
[meta.targetAppId]string
[meta.targetAction]string | null
[meta.resolverTag]string
 

QuickReply : object

Kind: global typedef
Properties

NameType
actionstring
title*
 

QuickReplyDisambiguation : object

Kind: global typedef
Properties

NameType
actionstring
titlestring
dataobject
templateDataobject
 

RequestOrchestratorOptions : object

Kind: global typedef
Properties

NameType
[apiUrl]string
[secret]Promise.<string>
[fetch]function
[appId]string
 

TextAlternative : object

Kind: global typedef
Properties

NameType
textstring
scorenumber
 

Attachment : object

Kind: global typedef
Properties

NameType
type'file' | 'audio' | 'video' | 'image'
payloadobject
payload.urlstring
 

AiSetStateOption : number

Kind: global typedef