Responder

Kind: global class

 

new Responder()

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

 

responder.data : object

Kind: instance property of Responder

 

responder.setMessgingType(messagingType, [tag]) ⇒ this

Kind: instance method of Responder

Param Type Default
messagingType string
[tag] 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, [quickReplies]) ⇒ this

Send text as a response

Kind: instance method of Responder

Param Type Description
text string text to send to user, can contain placeholders (%s)
[quickReplies] Object.<string, string> \ Array.<Object>

Example

// simply
res.text('Hello %s', name, {
    action: 'Quick reply',
    another: 'Another quick reply'
});

// complex
res.text('Hello %s', name, [
    { action: 'action', title: 'Quick reply' },
    {
        action: 'complexAction', // required
        title: 'Another quick reply', // required
        match: 'string' || /regexp/, // optional
        someData: '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])

Appends quick reply, to be sent with following text method

Kind: instance method of Responder

Param Type Default Description
action string relative or absolute action
title string quick reply title
[data] Object additional data
[prepend] boolean false set true to add reply at the beginning

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.expected(action) ⇒ 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
 

responder.toAbsoluteAction(action) ⇒ string

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
 

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

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

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 url
res.file('https://google.com/img/foo.pdf');
 

responder.wait([ms]) ⇒ this

Sets delay between two responses

Kind: instance method of Responder

Param Type Default
[ms] number 600
 

responder.typingOn() ⇒ this

Sends "typing..." information

Kind: instance method of Responder

 

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.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')
        .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.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();

results matching ""

    No results matching ""