Sending Replies

Whenever you receive a webhook call, Flow.ai 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 flowai-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.ai expects a Webhook call to return a reply within seconds. This can cause problems whenever you need to do a long running process.

Imagine a bank doing a money transfer. Sometimes that even takes up to a couple days. For those cases Flow.ai 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 a HTTP POST request.

The JSON payload you send is the same as with 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 what 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 AI 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