Sending Replies
Whenever you receive a webhook call, Flow expects a 200 response code from your server. With each reply, you can send back messages and information.
Example
{
"verifyToken": "59a755e5-2581-4307-393f-630ad4983adf",
"messages": [{
"fallback": "Hi there",
"responses": [{
"type": "text",
"payload": {
"text": "Hi there"
},
"delay": 0
}]
}]
}
When your webhook runs on Node.js it's best to use flow-js-templates to send back reply messages. Any other technology stack is possible as long as you send back JSON-formatted data.
Send later
Flow expects a Webhook call to return a reply within seconds. This can cause problems whenever you need to do a long-running process.
Certain business processes may however take considerably longer. For those cases, Flow provides a mechanism that allows you to reply with messages at a later point in time.
To do this there is a reply URL being provided with each webhook call. Use this URL to make an HTTP POST request.
The JSON payload you send is the same as when replying directly. Do not forget to include the verifyToken
with each request.
// Node.js example using request
const opts = {
method: 'POST',
uri: replyUrl,
body: {
verifyToken,
messages
},
json: true
}
request(opts)
Trigger events
Like sending messages you can also trigger events using Webhooks. It works the same as with sending messages except you specify which event to trigger.
// Node.js example using request
const opts = {
method: 'POST',
uri: replyUrl,
body: {
verifyToken,
events: [{
name: 'MY_EVENT_NAME'
}]
},
json: true
}
request(opts)
Sending Params
With each reply (or immediate response) you can also manipulate data that is used by the NLP engine. This is done by sending along params with a reply message.
The following example sends a reply that contains the params destination_city
and departure_city
.
const replyBody = {
verifyToken,
params: {
destination_city: [{
value: 'AMS'
}],
departure_city: [{
value: 'NYC'
}]
},
events: [{
name: 'WELCOME'
}]
}
const opts = {
method: 'POST',
uri: replyUrl,
body: replyBody,
json: true
}
request(opts)
Further reading
Updated 11 months ago