Teach your Bot to Add Attachments to its Answers in Teneo

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 tFhhe value to ${fbAttachment}.

When using the Facebook Messenger example connector you would give the output parameter the name fbmessenger.

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

Teneo Developers

Try Before You Buy.
Build. Deploy. Analyze.

Sign up to get your own developer sandbox of Teneo containing all the tools needed to build and manage advanced conversational solutions.

Get Started For Free

Author:
Gareth Walters is Vice President of Innovation and Community. Having moved into IT 20 years ago, he was responsible for Professional Services teams in several ERP, Supply Chain Management and Content Management software companies in a variety of sectors including Central Government, FMCG, Automotive and Pharmaceutical.

Leave a Reply

Your email address will not be published. Required fields are marked *