Create Variation to Your Chatbot’s Solutions by Including a Script to a Stream in Teneo

Generally you need a wide range of solutions that the bot you construct select from. And to ensure that the bot remembers what has been stated throughout the dialog a script is a method to accomplish this.

Scripts will be included in flows. Let’s create a really primary move that incorporates a script.

The move we are going to create will recommend a random espresso drink, like so:

Person: Recommend a drink!
Bot: Effectively, you’re placing me on the spot right here. I’d go for a flat white!

To realize this, we have to create a move that incorporates the next components:

  • A set off
  • A script that chooses a espresso drink
  • A move variable to retailer the worth chosen by the script
  • An output that may show the worth of the variable

The ultimate move will appear like this:

Let’s get began.

Create a New Stream and Populate the Set off

Create a brand new move and name it Person needs bot to recommend a espresso. Then choose the category set off and add the next instance inputs:

Give the set off a reputation like Recommend a drink!. (Visible directions of methods to create a move and populate the set off will be discovered right here.)

Add a Script Node

With nothing else within the move marked, click on the ‘Script’ icon within the ribbon. It will add an empty script node to your move. Give it a reputation that explains what the script does, like Choose a drink.

Put the Script Node in Its Place

At the moment, our script node is dangling and never linked to any of the opposite components within the move. Nevertheless, we would like our script to be executed instantly after the move is triggered, and proper earlier than the output is proven to the consumer. To realize this we have to observe these steps:

  1. Choose the script node
  2. Within the ribbon select ‘Set begin node’. This factors the set off straight to the script node.
  3. Draw a line from the script node to the output node

[embedded content]

Populate the Script Node

We now have added the script node, however it’s nonetheless empty. Now we’ll want so as to add the script that picks a random espresso drink to recommend to the consumer. Choose the script node in your move, open the ‘Script Motion’ tab on the fitting sight of the display and paste the next code into the script node:

Scripts in Teneo are written in Groovy. You’ll find extra particulars about Groovy and scripts in Teneo within the Scripting part.

As you may see within the script node above the primary two variables (coffeesToSuggest and quantity) are preceded by def which suggests they’re native variables which can be solely out there contained in the script node. They are going to be forgotten instantly after the script is executed, on this case, it will occur when Teneo strikes on to the output node. Nevertheless, we would like the result of the script (the espresso chosen by the script node) to be out there outdoors of the script so we will use it in our output textual content. So we might want to retailer the worth in a move variable that we will use in a while.

The final line of the script assumes a variable referred to as coffeeSuggestion exists by which the chosen espresso drink will be saved. That is decided by the truth that coffeeSuggestion just isn’t outlined by previous it with def. Nevertheless, we don’t have a move variable referred to as coffeeSuggestion but, so let’s add it.

[embedded content]

Add Stream Variable

So as to add a move variable, proceed as follows:

  1. Click on on the tab ‘FLOW’ within the high left nook of your move.
  2. Select ‘Variables’ within the purple bar on the left
  3. Click on the ‘Add’ button within the high proper of the window
  4. Identify the variable coffeeSuggestion by changing the phrase Variable1
  5. We wish to initialize this variable as an empty string, so within the textual content field under add "".

You need to use the again arrow on the high to return to the principle move view.

[embedded content]

Add Solutions to the Output

The consumer is stuffed with anticipation so let’s present the reply. Add the next reply texts to the output node:

  • Effectively, you are placing me on the spot right here. I might go for a ${coffeeSuggestion}!
  • Now that you simply're asking, I might recommend a ${coffeeSuggestion}!
  • Straightforward alternative, a ${coffeeSuggestion} in fact!

As you may see we’ve got used the move variable coffeeSuggestion in our solutions. This placeholder can be changed by the worth picked within the script node. Lastly, give the output node a reputation like I might go for a flat white!


That’s it! Save your move and provides it a attempt in tryout.

Additional Problem for the Courageous!

When you’re up for an additional problem: usually there are a number of methods to design a move. On this case, for instance, you may also mannequin this move with three separate output nodes (for every espresso kind recommended). Can you determine what the design of the move could be when taking that strategy? Trace: transitions can include script situations too!

0 Comment

Leave a comment