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 Teneo Web Chat.

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 parameter with the JSON needed to attach an image in Teneo Web Chat. 

If we look at Teneo Web Chat's message type specification of an image, the JSON to attach an image to a message needs to look like this:

{
    "type": "image",
    "image_url": "https://url.to/an/image.png",
    "alt": "This is an image"
}

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

// create object that contains the image details
def image = [:]

// add details to the object
image.type = "image"
image.image_url = "https://url.to/an/image.png"
image.alt = "This is an image"

// convert object to JSON and store the result in a flow variable
JSON = new groovy.json.JsonOutput().toJson(image)

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

When using Teneo Web Chat you need give the output parameter the name teneowebclient. The result then looks 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?