How to Upload a Video to Twitter Microsoft Expressions

Subscribing to Tweets using Azure Logic Apps

A tutorial for using Azure Logic Apps to monitor recent tweets on Twitter. The app sends an email notification to subscribers when new tweets are posted matching a search term.

Technologies Used

  • Azure Logic Apps - Manage subscriptions, monitor tweets, and transport email notifications to subscribers
  • Azure Table Storage - Store persistent data like subscriptions

Prerequisites

  • An Azure subscription
    • If you don't accept ane, sign up for costless.
    • If you're a pupil, you can sign upwardly for costless without requiring a credit card at sign-up.
  • An email account (Office 365 or Outlook for all features, Gmail if blessing emails are not required)
  • A Twitter account
  • A web browser
  • Azure Storage Explorer (optional, just recommended for working with Azure Table Storage)

Create Azure resources

Logics Apps allow you to build and examination your application entirely from the Azure Portal using the Logic Apps Designer. Permit's get started past creating a few Logic Apps and a storage business relationship.

Sign in to the Azure portal

  1. Become to the Azure portal and sign in with your Azure account credentials.

    Meet Prerequisites for sign upward links if you don't have an account

Create a Logic App to manage subscribers

  1. From the primary Azure carte du jour, choose Create a resource > Web > Logic App.

  2. Provide details near your Logic App as shown hither. Afterwards you're done, choose Create.

    Belongings Value Description
    Name TwitterSubscriptionManager The name for your Logic App
    Subscription <your-Azure-subscription-name> The name for your Azure subscription
    Resource group Create new > TwitterLogicAppSample The proper noun for the Azure resources grouping used to organize related resources
    Location East US The region where your Logic App is hosted
    Log Analytics Off Keep the Off setting for diagnostic logging.

Create a Logic App to monitor tweets and send notifications to subscribers

  1. From the main Azure menu, choose Create a resource > Web > Logic App.

  2. Provide details about your Logic App equally shown here. After you're done, cull Create.

    Property Value Description
    Name TwitterNotifier The name for your Logic App
    Subscription <your-Azure-subscription-name> The name for your Azure subscription
    Resource grouping Utilise existing > TwitterLogicAppSample Use the same resources grouping as the Logic App
    Location Eastward US The region where your Logic App is hosted
    Log Analytics Off Keep the Off setting for diagnostic logging.

Create a Storage Business relationship

  1. From the main Azure menu, choose Create a resource > Storage > Storage account - blob, file, table, queue.

  2. Provide details about your Storage Account as shown here. After you're washed, choose Create.

    Belongings Value Description
    Name <your-name>twitterdata The name for your Storage Account
    Deployment model Resources manager Use Resource Director for new applications and for the latest Azure features
    Account kind Storage (general purpose v1) The type of storage account. V1 has everything nosotros need just you tin utilize V2 if you lot similar.
    Location East U.s.a. The region where your app'southward data is hosted
    Replication Locally-redundant storage (LRS) The to the lowest degree durable simply lowest toll storage
    Performance Standard Standard storage accounts are backed by magnetic drives and provide the lowest cost per GB
    Secure transfer required Enabled At that place's no reason non to use HTTPS
    Subscription <your-Azure-subscription-name> The name for your Azure subscription
    Resource group Utilise existing > TwitterLogicAppSample Use the same resource group as the Logic App
    Log Analytics Off Keep the Off setting for diagnostic logging.

Create a table in the storage account

Azure Tabular array Storage will be used to persist data virtually subscribers and tweets between executions of the Logic App.

  1. From the master Azure menu, choose Resource groups > TwitterLogicAppSample.

  2. Choose the <your-name>twitterdata Storage Business relationship that was created earlier.

  3. The storage business relationship overview will open. Under Services cull Tables.

  4. Click the + Table button at the peak to add together a new tabular array named subscriptions and choose OK.

Configure the TwitterSubscriptionManager Logic App

This Logic App will accept subscribe and unsubscribe requests from users to/from a Twitter search term of their choosing. It will too verify the request was intentional past sending a verification e-mail to the user prior to honoring their request.

Logic App Designer view of the final TwitterSubscriptionManager Logic App

Configure the trigger for the TwitterSubscriptionManager Logic App

Every Logic App must outset with a trigger, which fires when a specific event happens or when a specific condition is met. Each fourth dimension the trigger fires, the Logic Apps engine creates a Logic App instance that starts and runs your workflow.

  1. From the main Azure carte du jour, choose Resource groups > TwitterLogicAppSample.

  2. Choose the TwitterSubscriptionManager Logic App that was created earlier.

  3. The Logic Apps Designer will open and evidence a page with an introduction video and commonly used triggers. Nether Get-go with a mutual trigger, choose When a HTTP request is received.

  4. Utilize the Save button at the acme of the screen to salve the Logic App. Observe that a unique URL to trigger your Logic App was populated in the HTTP POST URL box. Your Logic App workflow will exist triggered when a Mail asking is received at this URL.

Configure the parameters for the HTTP trigger

Your Logic App will need some information from the user to subscribe/unsubscribe them to/from a Twitter search term or hashtag. Namely, we'll need the email address of the subscriber, the search term, and whether the request is to subscribe or unsubscribe.

  1. In the When a HTTP request is received trigger, click the Edit link next to Using the default values for the parameters. In the box that appears, we'll provide a JSON schema of the asking format our Logic App should expect.

    1. Under the Request Trunk JSON Schema box, click the Use sample payload to generate schema link.
    2. In the Enter or paste a sample JSON payload dialog, paste the JSON beneath.
                        {   "action": "subscribe",   "email": "instance@example.com",   "term": "#microsoft" }                                  
    3. Choose Done.

  2. Salvage the Logic App.

Send an approval email to validate the request

  1. Choose + New stride in the Logic Apps Designer.

  2. Under Cull an action, enter "send approving email" equally your filter. From the actions list, select the Ship approving email action for the electronic mail provider that you want.

    1. To filter the deportment list to a specific app or service, yous can select that app or service get-go:
      • For personal Microsoft accounts, select Outlook.com.
      • For Office 365 piece of work or school accounts, select Office 365 Outlook.

      The Gmail service does not support sending approving emails. If you just have a Gmail account, you can still use the Transport an e-mail action just your Logic App volition not be able to receive responses to the email.

  3. If asked for credentials, sign in to your email account and then that Logic Apps can create a connectedness to your email account.

  4. In the Ship approval email action, specify the data that you want the email to include.

    1. Click inside the To box. The dynamic content dialog will appear. Choose email from the Dynamic content tab under the When a HTTP asking is received heading. This will use the email address provided in the body of the HTTP asking that triggered the workflow.
    2. If you like, edit the Bailiwick of the e-mail. Y'all can include other parameters from the HTTP request using the dynamic content dialog. For instance, yous may want to change the subject to "Please approve <action> request for notifications nearly <term> tweets" where the <action> and <term> strings are replaced with the parameter values from the HTTP request.

  5. Save the Logic App.

Cheque if the request was canonical

Afterward the approving email is sent, the Logic App volition wait for the user to click either the "Corroborate" or "Turn down" link in the email. In one case the user clicks one of those links, the Logic App volition need to determine what to do next based on the response.

  1. Choose + New step in the Logic Apps Designer.

  2. Nether Cull an action, enter "condition" every bit your filter. From the actions list, cull the Condition Control action.

  3. In the Status activity, populate the tree of conditions to evaluate.

    1. Leave the And driblet downwardly as is.
    2. Click inside the Choose a value box. The dynamic content dialog volition announced. Cull SelectedOption from the Dynamic content tab under the Transport approval e-mail heading.
    3. Leave the value of the is equal to condition unchanged.
    4. In the Choose a value box, enter Approve.

  4. Salve the Logic App.

Check if the asking was for subscribing or unsubscribing

Once the request is approved the Logic App volition demand to perform the requested action (subscribe or unsubscribe the user). In this step, we'll determine which activeness to perform.

  1. Cull Add an action within the If true block beneath the Status in the Logic Apps Designer.

  2. Under Cull an action, enter "switch" as your filter. From the actions list, choose the Switch Control action.

  3. In the Switch action, populate the On value to tell the control action what value should be used to decide the next stride.

    1. Click inside the On box. The dynamic content dialog volition announced. Choose action from the Dynamic content tab under the When a HTTP asking is received heading.

  4. Below the Switch action, locate the Case block. Populate the Equals box with the text subscribe.

  5. Click the (+) button between the Example block and the Default block. A Case ii block will be added.

  6. Inside the Instance 2 block, populate the Equals box with the text unsubscribe.

    If you like, you can rename these example blocks using the Rename pick inside the ··· menu of each block.

  7. Salve the Logic App.

Add together an entry to the subscriptions table if the request was to subscribe

  1. Choose Add an action within the Case cake containing "Equals subscribe."

  2. Under Choose an activeness, enter "insert or replace" as your filter. From the actions list, choose the Insert or Supercede Entity Azure Table Storage activity.

  3. In the Insert or Supplant Entity activeness, specify the table and the entity to insert or replace.

    1. You lot may be prompted for a Storage Account connection

      1. In the Connection Name box, provide a proper name like TwitterLogicAppStorage.
      2. Choose the Storage Business relationship created earlier, <your-proper name>twitterdata.
      3. Click Create.

    2. In one case the connexion is created, cull subscriptions from the Tabular array drib down.

    3. Click inside the Partition Key box. The dynamic content dialog will appear. Switch to the Expression tab and enter uriComponent(toLower(triggerBody()['email'])) into the expression box. Click OK to ready the expression as the sectionalisation fundamental value.

      This expression converts the email field from the POST asking to lower example and then URI-encodes it. Converting to lower case will ensure that the user can unsubscribe hands later without the demand to apply the exact casing as when they subscribed. The encoding is necessary in case the user enters a character that is non permitted in segmentation keys or row keys, such as #.

    4. Click inside the Row Key box. The dynamic content dialog will announced. Switch to the Expression tab and enter uriComponent(toLower(triggerBody()['term'])) into the expression box. Click OK to set up the expression every bit the row key value.

    5. In the Entity box, enter the JSON below.

                        {   "LastTweetId": "" }                                  

      The LastTweetId property will exist used to rails the nearly recent tweet our Logic App found that matches the provided search term. It will simplify determining which tweets are "new" afterward.

  4. Salve the Logic App.

    You can read more about partition keys, row keys, and Azure Table Storage in full general hither.

Remove an entry from the subscriptions table if the asking was to unsubscribe

  1. Cull Add an activeness inside the Instance two block containing "Equals unsubscribe."

  2. Under Choose an action, enter "delete entity" as your filter. From the actions listing, cull the Delete Entity Azure Table Storage action.

  3. In the Delete Entity activeness, specify the table and the entity to delete.

    1. Choose subscriptions from the Table drop down.
    2. Click inside the Division Key box. The dynamic content dialog will announced. Switch to the Expression tab and enter uriComponent(toLower(triggerBody()['email'])) into the expression box. Click OK to set the expression as the partition key value.
    3. Click inside the Row Central box. The dynamic content dialog will announced. Switch to the Expression tab and enter uriComponent(toLower(triggerBody()['term'])) into the expression box. Click OK to set the expression as the row key value.
    4. Leave the ETag box empty.

  4. Salvage the Logic App.

Test out the TwitterSubscriptionManager Logic App

Congratulations! The Logic App should now be fix for use. Allow'due south test it out!

  1. Save whatever outstanding changes made to the Logic App using the Salvage button at the top of the Logic Apps Designer.

  2. Click the When a HTTP request is received trigger to expand it. Re-create the value of the HTTP POST URL using the Re-create URL button. Store this for later use.

  3. Make a HTTP POST request to the URL copied in the last footstep.

    • On Windows, this can be done using a PowerShell control like this:
                        Invoke-RestMethod -Method Mail -Body (@{ "action" = "subscribe"; "email" = "instance@case.com"; "term" = "#azure" } | ConvertTo-Json) -ContentType "application/json" -Uri "the-url-of-your-logic-app"                                  
    • On Mac/Linux/Windows Subsystem for Linux, this tin exist done using a curlicue command like this:
                        curl --request POST --data '{"action":"subscribe","e-mail":"example@example.com","term":"logic apps"}' --header "Content-Type: application/json" "the-url-of-your-logic-app"                                  
  4. Close the Logic Apps Designer using the X in the height right corner of the blade.

  5. Cull Refresh at the peak of the Logic App overview bract.

  6. Nether the Run history section of the Logic App overview blade, find the most contempo run of the Logic App. Click its row to view a visualization of the executed workflow.

  7. Optionally, employ Azure Storage Explorer to browse to the <your-proper noun>twitterdata Storage Business relationship and verify an entity was added to the subscriptions table.

Configure the TwitterNotifier Logic App

This Logic App volition periodically query tweets from a Twitter search API based on the subscriptions in the Azure Table and inform subscribers of new tweets via email.

Logic App Designer view of the final TwitterNotifier Logic App

Configure the trigger for the TwitterNotifier Logic App

This Logic App's trigger volition exist a recurrence, meaning the Logic App volition execute itself automatically based on a configurable time interval.

  1. From the principal Azure carte, choose Resource groups > TwitterLogicAppSample.

  2. Choose the TwitterNotifier Logic App that was created before.

  3. The Logic Apps Designer volition open and prove a folio with an introduction video and unremarkably used triggers. Under Starting time with a common trigger, cull Recurrence.

  4. Keep the default recurrence frequency or update it if y'all similar.

  5. Employ the Salve button at the top of the screen to save the Logic App. If you chose a frequent interval for the Logic App, you may wish to render to the Logic App's overview bract and disable the Logic App until it is consummate.

Read subscriptions from the Table Storage

  1. Choose + New footstep in the Logic Apps Designer.

  2. Under Choose an activity, enter "go entities" every bit your filter. From the actions listing, select the Go entities Azure Tabular array Storage activity.

  3. In the Get entities action, specify the details of subscriptions tabular array created earlier.

    1. You may be prompted for a Storage Business relationship connection
      1. In the Connection Proper name box, provide a proper noun similar TwitterLogicAppStorage.
      2. Choose the Storage Account created before, <your-name>twitterdata.
      3. Click Create.
    2. One time the connection is created, choose subscriptions from the Table drop down.

  4. Salve the Logic App.

Select the subscription details from the entities

Adjacent well map each Table Storage entity to an object with more convenient property names and URI-decoded versions of the segmentation key and row cardinal.

  1. Choose + New pace in the Logic Apps Designer.

  2. Under Choose an activeness, enter "select" as your filter. From the actions list, choose the Select Data Operations action.

  3. In the Select action, specify the properties to select from the table entities.

    1. Click inside the From box. The dynamic content dialog will appear. Choose Get entities event List of Entities from the Dynamic content tab.

    2. In the Map fields, enter the following mappings

      Key Value Details
      Email Encoded Become entities result An entity Segmentation Key Cull this value from the Dynamic content tab
      Search Term Encoded Get entities outcome An entity Row Key Choose this value from the Dynamic content tab
      Email uriComponentToString(item()['PartitionKey']) Enter this value into the Expression tab of the Dynamic content dialog
      Search Term uriComponentToString(item()['RowKey']) Enter this value into the Expression tab of the Dynamic content dialog
      Final Tweet ID detail()['LastTweetId'] Enter this value into the Expression tab of the Dynamic content dialog

      The item() portion of the expression is a function that returns the item that is in the current iteration of a repeating action. It may be helpful to think of this as the chemical element at the current index of a loop over an array.

  4. Save the Logic App.

Create a loop to iterate through the subscription objects

  1. Choose + New step in the Logic Apps Designer.

  2. Nether Cull an action, enter "for each" as your filter. From the actions listing, choose the For each Control activeness.

  3. In the For each action, specify the output of the Select action as the value for the Select an output from previous steps box. Click within the box and choose Output under the Select pace header of the Dynamic content tab.

  4. Save the Logic App.

Get recent tweets from the Twitter "Search tweets" API

Twitter offers an API that provides the nigh recent tweets matching a search term (discussion, phrase, or hashtag). We'll query that API for each subscribed search term within our Logic App. The API is bachelor equally a Microsoft Connector. A connector is a proxy or a wrapper around an API that allows the underlying service to talk to Microsoft Catamenia, PowerApps, and Logic Apps. You can read more well-nigh the Twitter Connector here.

  1. Cull Add an action within the For each loop in the Logic Apps Designer.

  2. Under Choose an action, enter "search tweets" as your filter. From the deportment listing, choose the Search tweets Twitter action.

  3. If asked for credentials, sign in to your Twitter business relationship and then that Logic Apps tin can create a connectedness and phone call the Twitter API.

  4. In the Search tweets action, specify the properties of the API request.

    1. Click within the Search text box. The dynamic content dialog volition appear. Switch to the Expression tab and enter item()['Search Term'] into the expression box. Click OK to save the expression.
    2. Click the Show avant-garde options link within the Search tweets activeness.
    3. If you wish, increase the Maximum results to 100.
    4. Click within the sinceId box. The dynamic content dialog will appear. Switch to the Expression tab and enter particular()['Concluding Tweet ID'] into the expression box. Click OK to salve the expression.

      This will ask the Twitter API to only return tweets that were created after the specified tweet ID.

  5. Salve the Logic App.

Check if in that location are new tweets matching the search term

Nosotros want to bank check if whatsoever new tweets matching the search term have been posted since the last time our Logic App executed. Since we asked the Twitter API to just return tweets since the last tweet ID our Logic App encountered, we can check the number of tweets returned by the API to determine if we should notify the subscriber of new tweets.

  1. Choose Add an action within the For each loop in the Logic Apps Designer.

  2. Under Choose an action, enter "condition" as your filter. From the actions list, choose the Condition Control action.

  3. In the Condition action, populate the tree of weather condition to evaluate.

    1. Leave the And drop down equally is.
    2. Click inside the outset Choose a value box. The dynamic content dialog will appear. Switch to the Expression tab and enter length(trunk('Search_tweets')) into the expression box. Click OK to relieve the expression.

      This expression volition return the number of tweets in the body of the Twitter API response.

    3. Modify the value of the is equal to condition to is greater than.
    4. In the Choose a value box, enter 0.

  4. Save the Logic App.

Update the Final Tweet ID for the subscription in Azure Table Storage

  1. Cull Add together an action within the If truthful block below the Status in the Logic Apps Designer.

  2. Under Choose an action, enter "merge entity" as your filter. From the deportment list, choose the Merge Entity Azure Tabular array Storage action.

  3. In the Merge Entity activity, specify the table entity to update.

    1. In the Table box, cull subscriptions from the driblet downward.
    2. Click inside the Partition Key box. The dynamic content dialog will appear. Switch to the Expression tab and enter item()['Email Encoded'] into the expression box. Click OK to salve the expression.
    3. Click inside the Row Central box. The dynamic content dialog will appear. Switch to the Expression tab and enter item()['Search Term Encoded'] into the expression box. Click OK to save the expression.
    4. In the Entity box, enter the JSON template below.
                        {   "LastTweetId": <id> }                                  
      1. Later populating the field, highlight the <id> portion of the field's value and delete it.
      2. With your cursor at the position where <id> used to exist, click the Expression tab in the Dynamic content dialog.
      3. In the expression box, enter first(trunk('Search_tweets'))['TweetId'] and cull OK. This will update the ID of the nearly recent tweet in the table entity.
    5. In the ETag box, enter *. This volition update the tabular array entity regardless of whether it has changed since nosotros queried information technology.

  4. Relieve the Logic App.

Send a notification email if there are new tweets matching the subscribed term

  1. Choose Add an activeness within the If true cake below the Merge Entity activeness in the Logic Apps Designer.

  2. Under Cull an activity, enter "ship an e-mail" as your filter. From the actions list, select the Send an email activity for the email provider that you lot want.

    1. To filter the actions list to a specific app or service, you can select that app or service first:
      • For personal Microsoft accounts, select Outlook.com.
      • For Office 365 work or school accounts, select Office 365 Outlook.
      • For personal Google accounts, select Gmail.
  3. If asked for credentials, sign in to your electronic mail account so that Logic Apps can create a connection to your electronic mail account.

  4. In the Send an e-mail activity, specify the data that you want the email to include.

    1. Click inside the To box. The dynamic content dialog will appear. Switch to the Expression tab and enter particular()['Email'] into the expression box. Click OK to salve the expression.
    2. In the Field of study box, enter the value <number> new tweets matching <term>.
      1. After populating the field, highlight the <number> portion of the field'due south value and delete it.
      2. With your cursor at the position where <number> used to be, click the Expression tab in the Dynamic content dialog.
      3. In the expression box, enter length(body('Search_tweets')) and choose OK. This will insert the number of new tweets into the subject at the right position.
      4. Now highlight the <term> portion of the field's value and delete it.
      5. With your cursor at the position where <term> used to be, click the Expression tab in the Dynamic content dialog.
      6. In the expression box, enter item()['Search Term'] and choose OK. This will insert the subscribed search term into the subject at the correct position.

      OPTIONAL To be grammatically correct, we should make the word "tweets" singular if the number of new tweets is 1. If you like, replace the word "tweets" with this expression: if(equals(length(torso('Search_tweets')), 1), 'Tweet', 'Tweets').

    3. In the Torso box, enter any value you similar. If you don't want to include anything, just enter a space.
      1. If you lot would like to include the content of the nigh contempo tweet, click within the Trunk box and enter whatever explanatory text along with the expression first(body('Search_tweets'))['TweetText'] via the dynamic content dialog.

        If you would like to include other backdrop of the almost recent tweet in the email body, refer to the list of property paths available in the TweetModel. Simply replace TweetText in the expression with one of the other belongings paths, such as TweetedBy.

  5. Save the Logic App.

Test out the TwitterNotifier Logic App

Congratulations! The Logic App should now be ready for utilise. Let'south test it out!

  1. Save any outstanding changes fabricated to the Logic App using the Relieve push at the summit of the Logic Apps Designer.

  2. Close the Logic Apps Designer using the X in the top right corner of the bract.

  3. If you previously disabled the Logic App while creating information technology, click the Enable button at the height of the Logic App overview blade.

  4. One time the Logic App is enabled, cull Run Trigger > Recurrence at the top of the Logic App overview blade.

    Alternatively, wait for the recurrence trigger to fire as scheduled.

  5. Cull Refresh at the top of the Logic App overview bract.

  6. Nether the Run history section of the Logic App overview bract, detect the virtually recent run of the Logic App. Click its row to view a visualization of the executed workflow.

mcarthurtherroys.blogspot.com

Source: https://docs.microsoft.com/en-us/samples/azure-samples/azure-serverless-twitter-subscription/azure-serverless-twitter-subscription/

0 Response to "How to Upload a Video to Twitter Microsoft Expressions"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel