Teneo Developers

Share to

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.

add output parameters

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 enclosing them in ${ 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:

groovy

1{
2    "type": "image",
3    "image_url": "https://url.to/an/image.png",
4    "alt": "This is an image"
5}
6

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

groovy

1// create object that contains the image details
2def image = [:]
3
4// add details to the object
5image.type = "image"
6image.image_url = "https://url.to/an/image.png"
7image.alt = "This is an image"
8
9// convert object to JSON and store the result in a flow variable
10JSON = new groovy.json.JsonOutput().toJson(image)
11

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:

output parameters

Once the bot has published, the image will then be visible in Teneo Web Chat:

image in twc

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