ranka
Facebook Messaging bot with greater expressivity to be used in conjunction with Express.
Setting up
First, you will need to instantiate Ranka together with Express
const express = const app = const Ranka = const ranka = serverURL: '' validationToken: '' pageAccessToken: ''
Then, use your webhook this way:
app ranka
Bind your Express server port if you haven't already.
app
Request Object
Request Properties
Every Facebook callback is supported. This includes:
sender
recipient
timestamp
message
For example, when Facebook sends back the following:
console.log(req.message)
returns you with:
Request Methods
isThumbsUp()
Returns true if it is Facebook thumbs up.
req
hasAttachments()
Returns True, if there are attachments
getAttachmentsByType(type)
Returns an array of all attachments with specified type.
If no attachments of type is found, return an empty array.
req
Response Object
Response chainable methods
The methods are chainable, you can use multiple methods and run .exec()
at the end.
senderAction(value)
Set typing indicators or send read receipts using the Send API, to let users know you are processing their request.
res
typing(isTyping)
isTyping
is defaulted to true
.
Example:
res
send(message)
This is equivalent to sending this payload to Facebook Messenger API where message
is the passed in as an object.
In this case, we can send a basic text:
res
Correspondingly, ranka
generates the data to send back to Facebook:
The remaining commands are convenient helpers that wraps the send()
method.
sendText(text)
Sends a text as a reply to the sender.
res
sendQuickReplies(text, quick_replies)
You can send some quick replies:
res
sendAudio(url)
You can share a sound URL using the Send API.
See more in Facebook Messenger documentation.
sendVideo(url)
You can share a video URL using the Send API.
See more in Facebook Messenger documentation.
sendTemplate(payload)
You can send a message template and provide a payload
object:
req
.sendTemplate({
"template_type":"button",
"text":"What do you want to do next?",
"buttons":[
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com",
"title":"Show Website"
},
{
"type":"postback",
"title":"Start Chatting",
"payload":"USER_DEFINED_PAYLOAD"
}
]
})
.exec()
Using the above, you can send Button Template, Generic Template, List Template, Reciept Template, Airline Boarding Pass Template and more.
License
Apache 2.0 License