Classes

Request

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

Typedefs

Entity : Object
Intent : Object
Subscribtion : Object
Action : Object
 

Request

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

Kind: global class

 

request.params

Kind: instance property of Request
Properties

Name Type Description
params object plugin configuration
 

request.timestamp

Kind: instance property of Request
Properties

Name Type
timestamp number \ null
 

request.senderId

Kind: instance property of Request
Properties

Name Type Description
senderId string sender.id from the event
 

request.recipientId

Kind: instance property of Request
Properties

Name Type Description
recipientId string recipient.id from the event
 

request.pageId

Kind: instance property of Request
Properties

Name Type Description
pageId string page identifier from the event
 

request.state

Kind: instance property of Request
Properties

Name Type Description
state Object current state of the conversation
 

request.subscribtions

Kind: instance property of Request
Properties

Name Type Description
state Array.<Subscribtion> list of subscribed tags
 

request.entities

Kind: instance property of Request
Properties

Name Type Description
entities Array.<Entity> list of entities
 

request.intents

Kind: instance property of Request
Properties

Name Type Description
intents Array.<Intent> \ null list of resolved intents
 

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

Returns intent, when using AI

Kind: instance method of Request
Params

  • getDataOrScore boolean | number = false - score limit or true for getting intent data
 

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

Get matched entity value

Kind: instance method of Request
Params

  • name string - name of requested entity
  • [sequence] number = 0 - when 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.isImage([attachmentIndex], [includingStickers]) ⇒ boolean

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

Kind: instance method of Request
Params

  • [attachmentIndex] number = 0 - use, when user sends more then one attachment
  • [includingStickers] boolean = false - return true, when the image is also a sticker
 

request.isFile([attachmentIndex]) ⇒ boolean

Checks, when the attachment is a file

Kind: instance method of Request
Params

  • [attachmentIndex] number = 0 - use, 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
Params

  • [attachmentIndex] number = 0 - use, when user sends more then one attachment
 

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

Returns attachment URL

Kind: instance method of Request
Params

  • [attachmentIndex] number = 0 - use, 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
Params

  • [includeToTextStickers] boolean = false - including strickers transformed into a text
 

request.text([tokenized]) ⇒ string

Returns text of the message

Kind: instance method of Request
Params

  • [tokenized] boolean = false - when true, message is normalized to lowercase with -

Example

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

request.expected() ⇒ string | null

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

Kind: instance method of Request

 

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
Params

  • [getData] boolean = false

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.isPassThread() ⇒ boolean

Deprecated

Returns true, if request pass thread control

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
Params

  • action string | Action | null
  • [data] Object
 

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

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

  1. the postback is checked
  2. the referral is checked
  3. the quick reply is checked
  4. expected keywords are checked
  5. expected state is checked

Kind: instance method of Request
Params

  • [getData] boolean = false

Example

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

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
Params

  • [getData] boolean = false

Example

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

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Properties

Name Type
intent string
score number
[entities] Array.<Entity>
 

Subscribtion : Object

Kind: global typedef
Properties

Name Type
tag string
ts number
 

Action : Object

Kind: global typedef
Properties

Name Type
action string
data Object

results matching ""

    No results matching ""