Analyze Sentiment

At some point in the interaction, you might care more about the user's emotions rather than the exact content. For such situations, Flowstorm offers you tools to analyze the so-called "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 nor positive memories. For this purpose, you can use sentiment analysis.

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 the Czech Republic" and "I do sports" have a neutral sentiment.

"I hated the street I lived on" 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-and-drop it from the snippet palette into your dialogue.

Using a predefined "dialogue snippet" for sentiment analysis.

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.

// process input
processPipeline()
// 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
}