top of page
  • Writer's pictureYash Agarwal

Sentiment Analysis for Power Virtual Agents using Power Automate & Azure Cognitive Services

In this #PowerShot, I will show you how to configure sentiment analysis in Power Virtual Agents. We will use Text Analytics from Azure Cognitive Services and Power Automate to implement this.


Let's Get Started!


The process we are looking at is, the customer enters their concern and then that concern is sent as an input to Power Automate. We use the sentiment analysis action in Power Automate to get a sentiment score. Based on the sentiment score returned, we make the bot take a smart decision on how to continue with the session.

 

Power Automate


Step 1: Trigger: When an HTTP Request is received: This flow will be called as an action in the virtual agent and so we are using this trigger. The JSON schema is defined to accept an input from the virtual agent.


Step 2: Action: Detect Sentiment: The input from the trigger is passed to this action and Azure Text Analytics service is used to analyse the input. This action returns a score between 0-1 where 0 stands for a low sentiment score.


Step 3: Action: Initialize Variable: To pass an output response to the virtual agent based on the sentiment score.

Step 4: Control: Condition: To check if the sentiment score is less than "0.6".


If yes, Action: Set variable to "Low"


If no, Action: Set variable to "Normal"

Step 5: Response: To send a response based on the sentiment score to the virtual agent.

 

Power Virtual Agent


Step 1: Log on to https://powervirtualagents.microsoft.com/ and select Explore Bots -> Create a New Bot and provide a name for the bot. You can change the environment in which this bot is created by selecting the desired environment in the advanced settings.


Step 2: You will see a set of actions already added and now you can start editing the flow of the bot as per the requirement. For the scenario that we are building, add a new node and select "Ask a Question" and enter "What can I help you with today?". Identify the response as "Entire Text" and save it as "Var1".

Step 3: Add a new node and select "Call an Action". From the actions select the Sentiment Analysis Flow that was created in Power Automate in the first section. For the input to the action, pass the "Var1" from Step 2. Now the Flow returns with a text response of "Low" or "Normal" and if the response is Low, we want to transfer the chat to an agent and if not, then end it.


Step 4: Add a new node and select "Condition". For the first branch, select the "responseSentiment" from the Flow action and select the operand as "is equal to" and then type the text "Low". This will check if the response returned from the Flow is Low and move to this branch of the Agent and if not, then move to the other branch.


If Low sentiment is detected,

Add a new node and select "Show Message". Display a message saying that the chat is being transferred to an agent and add another node and select "Transfer to Agent". In the Transfer to Agent node, you can provide a private message to the agent.


If a normal sentiment is detected,

Add a new node and select "Show Message". Display a message with a greeting and then add another node and select "End with Survey".

 

Sentiment Analysis


Step 1: Create a "Text Analytics" resource in Azure.


Step 2: Create a connection to the Text Analytics connector in Power Automate and pass the Key while creating the connection.

For more detail on the Text Analytics, refer the documentation here.

 

Setup in Action

 

In this post we saw how to implement sentiment analysis for Power Virtual Agents using Text Analytics in Azure Cognitive Services and Power Automate.


I hope you found this interesting and it helped you!

Recent Posts

See All
bottom of page