Sending Replies
This guide explains how to send different messages from Khoros Flow to your server.
Flow expects a 200 response code from your server whenever you receive a webhook call. 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 if 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.
To do this, a reply URL will be 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. Remember 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
You can also trigger events using webhooks. It works the same as 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 Parameters
With each reply (or immediate response), you can also manipulate data used by the NLP engine. This is done by sending along parameters 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)
More information
Refer to the links below for examples of templates.
Updated 28 days ago