BotFrameworkHelper

To make it easier to produce the JSON for common botframework attachments when working in Studio, you can make use of the BotFrameworkHelper class.

Installation

Add the file BotFrameworkHelper.groovy to Resources in your solution and set the path to /script_lib.

For more details on managing files in your solution, see Resource File Manager.

Tip: you can open the .groovy file in a text editor to inspect or edit the source code.

Main methods

The BotFrameworksHelper contains the methods below.

createHeroCardJSON

Method to produce the JSON needed to attach a Hero card to an output. The result of this method can be used as value for the msbotframework output parameter.

Arguments

Argument Type Description
title String Title of the card. Maximum 2 lines; formatting not currently supported
subtitle String Subtitle of the card. Maximum 2 lines; formatting not currently supported
text String Text appears just below the subtitle; see Card formatting for formatting options
buttons List List of buttons applicable to the current card. Maximum 6. See helper method createPostbackButton
heroImage List List contianing a single image. Image displayed at top of card. Aspect ratio 16:9. See helper method createHeroImage

createImageJSON

Method to produce the JSON needed to attach an image to an output. The result of this method can be used as value for the `msbotframework' output parameter.

Arguments

Argument Type Description
url String URL for the image. Supported protocols are: HTTP, HTTPS.
alt String Alternative text for the image

Helper Methods

createPostbackButton

Method to produce a button object that posts a value back to your Teneo bot. These buttons can for example be added to Hero cards.

Arguments

Argument Type Description
label String Label shown in the button
postbackValue String Value that should be posted back to Teneo when the user clicks/taps the button

createHeroImage

Method to produce a list with an image object. The result of this method can added to Hero cards.

Arguments

Argument Type Description
url String URL for the image. Supported protocols are: HTTP, HTTPS.
alt String Alternative text for the image

Examples

Creating JSON for a Hero card

The script below can be added to a script node in a flow. It assumes the flow has a flow variable called myHeroCard which should be initialised as an empty string. The script will populate the flow variable with the JSON for the Hero card.

// image for hero card
def myHeroCardImage = BotFrameworkHelper.createHeroCardImage("https://url.to/image.jpg","Alternative text")

// populate list of buttons to be shown on hero card
def myHeroCardButtons = []
myHeroCardButtons << BotFrameworkHelper.createPostbackButton("Yes", "User clicked yes")
myHeroCardButtons << BotFrameworkHelper.createPostbackButton("No", "User clicked no")

// populate flow variable with JSON for hero card
myHeroCard = BotFrameworkHelper.createHeroCardJSON("Card title","Card subtitle","Card body text", myHeroCardButtons, myHeroCardImage)

To attach the json in the myHeroCard flow variable to an output, open the 'Output Parameters' panel for the output, add an output parameter called msbotframework and give it the value ${myHeroCard}.

Creating JSON for an image

The example above shows how to populate a flow variable using a script node and then adding the flow variable to the output parameter. However, you can also call methods directly in the value field of an output parameter. For example, to attach the json for an image to an output, add an output parameter called msbotframework and give it a value like ${BotFrameworkHelper.createImageJSON("https://url.to/image.png","Alternative text")}.

Was this page helpful?