Populate output parameters

Along with the answer text, you can add additional data to an output by populating output parameters. For example, you can use them to add attachments to messages for Facebook Messenger or rich responses for Google Assistant.

Adding an output parameter

We can add output parameters in the ‘Output Parameters’ panel of an output. Output parameters have two fields: Name and Value. The name field should contain the name you want to give to the output parameter (without spaces). In the value field you can enter the value directly (for static values), but you can also use variables (or scripts) by embracing them with ${ and }, for example ${myFlowVariable}.

Adding JSON to an output parameter

Often you will want to include JSON in an output parameter, especially when you want to provide structured data that is rendered by a client application. Let’s look at an example of how to populate an output a parameter with the JSON needed to attach an image on Facebook Messenger. 

If we look at Facebook's specification of an image attachment, the JSON to attach an image to a message needs to look like this:

    "type": "image",
    "payload": {
        "url": "https://url.to/an/image.png",
        "is_reusable": true

We can use Groovy's JsonBuilder to produce this JSON by adding the following script to a script node in a flow:

def fbAttachmentBuilder = new groovy.json.JsonBuilder()
fbAttachmentBuilder {
    type 'image'
    payload {
        url 'https://url.to/an/image.png'
        is_reusable true
fbAttachment = fbAttachmentBuilder.toString()

The last line of the scripts stores the resulting JSON as a String in a (flow) variable fbAttachment. We can now use this variable to populate an output parameter by setting the value to ${fbAttachment}.

When using the Facebook Messenger example connector you would give the output parameter the name fbmessenger. The result would look like this:

Example of a populated output parameter

For more example connectors and the output parameters they use for attachments, please refer to Channels in the Deploy your bot section.

Was this page helpful?