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:
To achieve this, we need to do the following:
- Create a global variable.
- Add a global listener.
- Recognize bad sentiment from the user.
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.
- Navigate to the Solution Dashboard and create a new Global Variable.
- Call it
isUserNegative
and the valuefalse
. This will turn to true if it is detected in the next step. - 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.
- Locate the Listeners tile and create a new Pre Listener.
- Click on 'Next' and name the listener
Negative Sentiment Detector
. - In the TLML field, paste in the following:
%SENTIMENT_NEGATIVE_HIGH_CONFIDENCE.INDICATOR
. - Below, execute the following groovy code:
isUserNegative = true
. - 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.
- Navigate to the Flows folder and create a new flow called
Negative Sentiment Detected
. Reuse the same name for the trigger node. - Add some examples in the intent, such as:
You are so bad
Go to hell
This is the worst thing that ever happened
- Add a Match for Global variable, and select 'isUserNegative'.
- 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.
- Navigate to the output node and name it
Bad sentiment detected
. - 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.
- Add a new 'On Drop' flow script, located below the Flow Overview.
- Enter the following script:
isUserNegative = false
. - 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.