Skip to content

Latest commit

 

History

History

twitter-to-powerbi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Serverless Lab: Build a Social Dashboard

This lab will go over building a social dashboard using Azure Serverless technologies. You can listen to any search term on Twitter and plot the sentiment, location, and key phrases of that tweet in real-time.

Pre-requisites

All of the lab will take place within the Azure Portal. So the only thing you need is an Azure account.

Getting started with the Logic App

  1. In the Azure Portal, click the New button, and under Web + Mobile select Logic App
  2. Give your logic app any name, resource group, and region that you want. Click Create
    • I recommend pinning the logic app to your dashboard for quick access later
  3. Once the logic app has deployed, open it to view the designer
  4. Click the Blank Logic App template to start from blank

Adding the trigger to twitter

Now that we are in the logic app designer, we can set the trigger for this app. In this case we want to listen to new tweets from Twitter.

  1. Click the Twitter connector and the When a new tweet is posted trigger
  2. Login with a twitter account to access the twitter search API
  3. Configure the trigger for a search term to listen
    Twitter trigger
  4. Add a New Step and Add an action, notice all of connectors to different services
  5. Add the Text Analytics connector and Detect Sentiment operation to detect the sentimet of the tweet. It can have any name you want
  6. Select to add the Tweet text as the text to analyze
  7. Add the Key Phrases operation as well, and grab from the Tweet text

At this point in our application we are listening to tweets, and getting the key phrases and sentiment of the tweet. Now let's add in a simple Azure Function to return a plain list of Key Phrases.

Adding an Azure Function

  1. In a new tab, go to New and select Compute to create a Function App
  2. Give it a name, resource group, etc. (Consumption plan is fine)
    • Again I recommend pinning to the dashboard
  3. Click to add a new function, choose to make it a Webhook + API, and select C#
  4. Once the new function app is created, replace the code with the following:
#r "Newtonsoft.Json"

using System;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // Get the phrases array
    var phrases = await req.Content.ReadAsAsync<JArray>();
    // Join the array with a comma
    var joinedPhrases = string.Join(", ", phrases.ToObject<string[]>());
    // Return the response
    return req.CreateResponse(HttpStatusCode.OK, joinedPhrases);
}

You can even test it with the following Request body:

["Some", "Phrases", "Here"]

Which should produce "Some, Phrases, Here"

Create a streaming dataset in Power BI to populate tweets

Follow the steps here to create a Streaming dataset in Power BI. Be sure to enable historic analysis or else you will not see the columns in the designer.

Give the following columns:

Name Type
Tweet Text String
Tweeted By String
Score Number
Key Phrases String
Created at DateTime
Location String

Calling the Azure Function from the Logic App

Switching back over to the Logic App designer

  1. Add a new step and select the Azure Functions connector

  2. Select the function app just created. The function will likely be named HttpTriggerCSharp1

  3. Select to send in the Key Phrases list
    Function config

    Last but not least, we need to add the outputs to a Power BI Dataset.

  4. Add a new step with the Power BI Add rows to a dataset operation

  5. Sign in with your Power BI account

  6. Select My workspace for a workspace, the dataset that corresponds with your account number, and the Tweets table

    • Notice that the designer has automatically prompted for the columns of this table
  7. Fill out the connector like the following picture. Note for key phrases we are using the output of our Azure Function
    Power BI Config

That's it - now we can save it and open in Power BI.

Viewing the results

Go to https://app.powerbi.com and login with the same username and password as you did for the Power BI connector. Find your dashboard and see the tweets as they come in.