Integrating Twitter, SharePoint, and Azure Sentiment Analysis with Flow

Last month, I wrote a post that included steps for setting up Sentiment Analysis, an Azure Cognitive Service, and how to use it to score how positive your emails are.  This time, I’m going to leverage the service that was configured in that post by using it in a Flow.  The Flow will pull content from Twitter, store it in SharePoint, and determine the Sentiment score for the tweet. 

To begin, I setup a SharePoint list with a number field named Sentiment Score.  For the purpose of this demo, I’ll use the Title field to store the tweet text but in production, I’d create a separate field for it. 

 empty sp list.PNG

 Next, I click on Flow in the menu select Create a flow. 

 create a flow.PNG

 A menu will appear to the right of the page with a few templates but we’ll want to create our own so we’ll click on “See your flows” at the bottom. 

 See your flows.PNG

 Next, you’ll be taken to the Flow page where you’ll want to select “Create from blank”  

 Create from blank.PNG

 

The trigger for our flow will be when an item matching a particular hashtag is created in Twitter so you can either select the Twitter icon titled “When a new tweet is posted” or if it’s not there, you can click the Search button below it and find the Twitter trigger there. 

 start with trigger.PNG

Your flow designer will start you with the Twitter trigger.  When you first select it, you’ll need to provide credentials for Twitter.  After you do, your trigger will display a simple text box that lets you enter the text you’d like to search for.  In this case, I chose to search for #Microsoft.  This will grab any new tweets with that hashtag. 

flow - twitter

Next, I want to run that tweet against the sentiment analysis action.  I’m going to assume that you have the sentiment analysis service configured but if not, you can go back to my previous post where I walk through those steps.  To narrow down the actions, I searched for “sentiment” and it filtered it down to the results below. 

 Flow - sentiment.PNG

I then selected “Text Analytics” from the connector to show that there are multiple options, but I could’ve just selected the action titled “Text Analytics – Detect Sentiment”. 

 text analysis - actions.PNG

 

Next, it’s time to configure the sentiment action.  When the action first comes up, it’ll ask for a key and endpoint which you can get from the sentiment analysis service in Azure.  Once you provide that, you’ll get the action below which asks for the text that you want to analyze.  Using the Dynamic Content, you can tell the action to analyze the Tweet Text that is coming from the Tweet trigger and you can specify a language as well. 

 configure sentiment.PNGconfigured sentiment.PNG

 Once the text is scored, I can create another action to Create a SharePoint Item. 

 create item action.PNG

That will give me the action below which simply needs a URL, the List where we want to store our results.  This is the list that I created in the beginning with the Title and Sentiment Score fields.  Using dynamic content, you can save the Tweet Text to the Title field and the score from the sentiment action to the Sentiment Score field. 

 create sharepoint item.PNG

Once you’re done, the Flow should look something like this.  (Don’t forget to give your Flow a proper name by clicking on the text at the top left of the screen.  I named mine “Twitter Sentiment Analysis”)

flow complete.PNG

The result is a list that is populated with tweets and scores. 

 sharepoint populated list.PNG

 Conclusion 

This is just a simple proof of concept to show how simple it can be to do this.  Depending on how many tweets you expect to have, you may not want to create SharePoint list items for this.  Instead, you may want to store the content in a spreadsheet or database.  With a little more effort, you can create better ways to present the data using column formatting or SPFx web parts.   If you release a new products or have some sort of event, you can keep an eye on your social media buzz to see how people are receiving them.