Detect sentiment

At some point in the interaction, you might care more about the user's emotions rather than the exact content. For such situations, we offer you tools to analyze the sentiment.

Imagine you would like to branch the flow based on what memories the user has of their hometown. More specifically, you don't care about what the memories are precisely about. You would just like to continue the "positive" flow if they have positive memories, the "sad" flow if they have negative memories, or the "neutral" flow if they don't have any particularly strong negative or positive memories. For this purpose, you can use sentiment analysis.

Sentiment analysis is available in πŸ‡ΊπŸ‡Έ English, πŸ‡¨πŸ‡Ώ Czech, πŸ‡©πŸ‡ͺ German, and πŸ‡ͺπŸ‡Έ Spanish dialogues

Sentiment analysis classifies text into three categories: positive, neutral, and negative. We can use those categories to branch the dialogue flow.

"I loved the city in which I grew up" and "I like you" have a positive sentiment.

"Prague is the capital of Czechia" and "I do sports" have a neutral sentiment.

"I hated the street" and "I don't enjoy loud music" have a negative sentiment.

Sentiment snippet

The easiest way to employ sentiment analysis is by using the predefined Sentiment snippet. Drag&drop it from the snippet palette into your dialogue.

Code in the user input node

If you want to work with the source code to customize the decision, you can proceed from the following code (in the UserInput node).

Don't forget to modify the names of the transitions according to the transitions in your model.

// user said something positive
if (input.sentiment.name == Sentiment.POSITIVE.toString()){
    toPOSITIVE_sentiment // MODIFY THE TRANSITION NAME
}

// user said something neutral
else if (input.sentiment.name == Sentiment.NEUTRAL.toString()){
    toNEUTRAL_sentiment // MODIFY THE TRANSITION NAME
} 

// user said something positive
else if (input.sentiment.name == Sentiment.NEGATIVE.toString()){
    toNEGATIVE_sentiment // MODIFY THE TRANSITION NAME
}

// something went wrong, no sentiment detected -> default to neutral sentiment
else {
    toNEUTRAL_sentiment // MODIFY THE TRANSITION NAME
}

Last updated