Teneo Developers

Use listeners

Listeners can be used in multiple ways in Teneo. For this example, we will demonstrate one way of using a listener inside a flow. On this page, we will go through how we can use Teneo's own Sentiment Detector and react accordingly when bad sentiment is detected.

Before our changes, we would have a conversation like this:

User: You are so bad
Bot: Really? That's very sad. I will try to perform better in the future.

After our modifications, it will look like this:

User: You are so bad.
Bot: We at Longberry Baristas do not condone this type of behavior. I understand that you're upset, but please don't speak to me that way.

The final flow will look like this: final flow layout

To achieve this, we need to do the following:

Create a global variable

Let's start by opening the Globals section and creating a global variable to capture whether or not the user is using bad sentiment in their input.

  1. Navigate to the Solution Dashboard and create a new Global Variable.
  2. Call it isUserNegative and the value false. This will turn to true if it is detected in the next step.
  3. Save the variable.

Create a global listener

Now it is time to create a global listener to only react and capture negative high inputs from the user.

  1. Locate the Listeners tile and create a new Pre Listener.
  2. Click on 'Next' and name the listener Negative Sentiment Detector.
  3. In the TLML field, paste in the following: %SENTIMENT_NEGATIVE_HIGH_CONFIDENCE.INDICATOR.
  4. Below, execute the following groovy code: isUserNegative = true.
  5. Save the listener.

Split the path

The next step is create a new flow that will trigger once bad sentiment is detected, with our global variable 'isUserNegative' turning from false to true.

  1. Navigate to the Flows folder and create a new flow called Negative Sentiment Detected. Reuse the same name for the trigger node.
  2. Add some examples in the intent, such as:
  • You are so bad
  • Go to hell
  • This is the worst thing that ever happened
  1. Add a Match for Global variable, and select 'isUserNegative'.
  2. Enter true as the 'Evaluation script'. This will cause the following intent to only trigger when actual bad sentiment from the user is detected.

Modify the Output

Now we need to finish the flow by adding a fitting answer when the user is using negative sentiment.

  1. Navigate to the output node and name it Bad sentiment detected.
  2. Add the following answer: We at Longberry Baristas do not condone this type of behavior. I understand that you're upset, but please don't speak to me that way..

Reset sentiment detector

Now that we have created the flow, we need to make sure we push back the boolean to false again so that it does not keep triggering. This can be done with a flow script.

  1. Add a new 'On Drop' flow script, located below the Flow Overview.
  2. Enter the following script: isUserNegative = false.
  3. Save the flow.

Try it out

Let's go ahead and test the flow:

User: You are so bad
Bot: We at Longberry Baristas do not condone this type of behavior. I understand that you're upset, but please don't speak to me that way.