Logic Twitter



-->

This article helps you to learn how to create a Logic App Flow between Facebook and Twitter. Logic App is a cloud-based service. It allows us to react to an event in one service (such as SharePoint online) and do something with the data from that event into another one Service (such as Twitter). It makes it practical and simple for line-of-business. The users build workflows that automatically. The latest tweets from @solidstatelogic.

Azure Functions integrates with Azure Logic Apps in the Logic Apps Designer. This integration allows you use the computing power of Functions in orchestrations with other Azure and third-party services.

This tutorial shows you how to create a workflow to analyze Twitter activity. As tweets are evaluated, the workflow sends notifications when positive sentiments are detected.

In this tutorial, you learn to:

  • Create a Cognitive Services API Resource.
  • Create a function that categorizes tweet sentiment.
  • Create a logic app that connects to Twitter.
  • Add sentiment detection to the logic app.
  • Connect the logic app to the function.
  • Send an email based on the response from the function.

Prerequisites

  • An active Twitter account.
  • An Outlook.com account (for sending notifications).

Note

If you want to use the Gmail connector, only G-Suite business accounts can use this connector without restrictions in logic apps. If you have a Gmail consumer account, you can use the Gmail connector with only specific Google-approved apps and services, or you can create a Google client app to use for authentication in your Gmail connector.
For more information, see Data security and privacy policies for Google connectors in Azure Logic Apps.

Create Text Analytics resource

The Cognitive Services APIs are available in Azure as individual resources. Use the Text Analytics API to detect the sentiment of posted tweets.

  1. Sign in to the Azure portal.

  2. Select Create a resource in the upper left-hand corner of the Azure portal.

  3. Under Categories, select AI + Machine Learning

  4. Under Text Analytics, select Create.

  5. Enter the following values in the Create Text Analytics screen.

    SettingValueRemarks
    SubscriptionYour Azure subscription name
    Resource groupCreate a new resource group named tweet-sentiment-tutorialLater, you delete this resource group to remove all the resources created during this tutorial.
    RegionSelect the region closest to you
    NameTweetSentimentApp
    Pricing tierSelect Free F0
  6. Select Review + create.

  7. Select Create.

  8. Once the deployment is complete, select Go to Resource.

Get Text Analytics settings

Twitter

With the Text Analytics resource created, you'll copy a few settings and set them aside for later use.

  1. Select Keys and Endpoint.

  2. Copy Key 1 by clicking on the icon at the end of the input box.

  3. Paste the value into a text editor.

  4. Copy the Endpoint by clicking on the icon at the end of the input box.

  5. Paste the value into a text editor.

Create the function app

  1. From the top search box, search for and select Function app.

  2. Select Create.

  3. Enter the following values.

    SettingSuggested ValueRemarks
    SubscriptionYour Azure subscription name
    Resource grouptweet-sentiment-tutorialUse the same resource group name throughout this tutorial.
    Function App nameTweetSentimentAPI + a unique suffixFunction application names are globally unique. Valid characters are a-z (case insensitive), 0-9, and -.
    PublishCode
    Runtime stack.NETThe function code provided for you is in C#.
    VersionSelect the latest version number
    RegionSelect the region closest to you
  4. Select Review + create.

  5. Select Create.

  6. Once the deployment is complete, select Go to Resource.

Create an HTTP-triggered function

  1. From the left menu of the Functions window, select Functions.

  2. Select Add from the top menu and enter the following values.

    SettingValueRemarks
    Development environmentDevelop in portal
    TemplateHTTP Trigger
    New FunctionTweetSentimentFunctionThis is the name of your function.
    Authorization levelFunction
  3. Select the Add button.

  4. Select the Code + Test button.

  5. Paste the following code in the code editor window.

    A sentiment score is passed into the function, which returns a category name for the value.

  6. Select the Save button on the toolbar to save your changes.

    Note

    To test the function, select Test/Run from the top menu. On the Input tab, enter a value of 0.9 in the Body input box, and then select Run. Verify that a value of Positive is returned in the HTTP response content box in the Output section.

Next, create a logic app that integrates with Azure Functions, Twitter, and the Cognitive Services API.

Create a logic app

  1. From the top search box, search for and select Logic Apps.

  2. Select Add.

  3. Select Consumption and enter the following values.

    SettingSuggested Value
    SubscriptionYour Azure subscription name
    Resource grouptweet-sentiment-tutorial
    Logic app nameTweetSentimentApp
    RegionSelect the region closest to you, preferably the same region you selected in previous steps.

    Accept default values for all other settings.

  4. Select Review + create.

  5. Select Create.

  6. Once the deployment is complete, select Go to Resource.

  7. Select the Blank Logic App button.

  8. Select the Save button on the toolbar to save your progress.

You can now use the Logic Apps Designer to add services and triggers to your application.

Connect to Twitter

Create a connection to Twitter so your app can poll for new tweets.

  1. Search for Twitter in the top search box.

  2. Select the Twitter icon.

  3. Select the When a new tweet is posted trigger.

  4. Enter the following values to set up the connection.

    SettingValue
    Connection nameMyTwitterConnection
    Authentication TypeUse default shared application
  5. Select Sign in.

  6. Follow the prompts in the popup window to complete signing in to Twitter.

  7. Next, enter the following values in the When a new tweet is posted box.

    SettingValue
    Search text#my-twitter-tutorial
    How oven do you want to check for items?15 in the textbox, and
    Minute in the dropdown
  8. Select the Save button on the toolbar to save your progress.

Next, connect to text analytics to detect the sentiment of collected tweets.

Add Text Analytics sentiment detection

  1. Select New step.

  2. Search for Text Analytics in the search box.

  3. Select the Text Analytics icon.

  4. Select Detect Sentiment and enter the following values.

    SettingValue
    Connection nameTextAnalyticsConnection
    Account KeyPaste in the Text Analytics account key you set aside earlier.
    Site URLPaste in the Text Analytics endpoint you set aside earlier.
  5. Select Create.

  6. Click inside the Add new parameter box, and check the box next to documents that appears in the pop-up.

  7. Click inside the documents Id - 1 textbox to open the dynamic content pop-up.

  8. In the dynamic content search box, search for id, and click on Tweet id.

  9. Click inside the documents Text - 1 textbox to open the dynamic content pop-up.

  10. In the dynamic content search box, search for text, and click on Tweet text.

  11. In Choose an action, type Text Analytics, and then click the Detect sentiment action.

  12. Select the Save button on the toolbar to save your progress.

The Detect Sentiment box should look like the following screenshot.

Connect sentiment output to function endpoint

  1. Select New step.

  2. Search for Azure Functions in the search box.

  3. Select the Azure Functions icon.

  4. Search for your function name in the search box. If you followed the guidance above, your function name begins with TweetSentimentAPI.

  5. Select the function icon.

  6. Select the TweetSentimentFunction item.

  7. Click inside the Request Body box, and select the Detect Sentimentscore item from the pop-up window.

  8. Select the Save button on the toolbar to save your progress.

Add conditional step

  1. Select the Add an action button.

  2. Click inside the Control box, and search for and select Control in the pop-up window.

  3. Select Condition.

  4. Click inside the Choose a value box, and select the TweetSentimentFunctionBody item from the pop-up window.

  5. Enter Positive in the Choose a value box.

  6. Select the Save button on the toolbar to save your progress.

Add email notifications

  1. Under the True box, select the Add an action button.

  2. Search for and select Office 365 Outlook in the text box.

  3. Search for send and select Send an email in the text box.

  4. Select the Sign in button.

  5. Follow the prompts in the popup window to complete signing in to Office 365 Outlook.

  6. Enter your email address in the To box.

  7. Click inside the Subject box and click on the Body item under TweetSentimentFunction. If the Body item isn't shown in the list, click the See more link to expand the options list.

  8. After the Body item in the Subject, enter the text Tweet from:.

  9. After the Tweet from: text, click on the box again and select User name from the When a new tweet is posted options list.

  10. Click inside the Body box and select Tweet text under the When a new tweet is posted options list. If the Tweet text item isn't shown in the list, click the See more link to expand the options list.

  11. Select the Save button on the toolbar to save your progress.

The email box should now look like this screenshot.

Run the workflow

  1. From your Twitter account, tweet the following text: I'm enjoying #my-twitter-tutorial.

  2. Return to the Logic Apps Designer and select the Run button.

  3. Check your email for a message from the workflow.

Clean up resources

To clean up all the Azure services and accounts created during this tutorial, delete the resource group.

  1. Search for Resource groups in the top search box.

  2. Select the tweet-sentiment-tutorial.

  3. Select Delete resource group

  4. Enter tweet-sentiment-tutorial in the text box.

  5. Select the Delete button.

Optionally, you may want to return to your Twitter account and delete any test tweets from your feed.

Logic301 Twitter

Next steps





Comments are closed.