Workflow Automation with Microsoft Power Automate
上QQ阅读APP看书,第一时间看更新

Creating your first flow

The best way to see Power Automate in action is to start creating a flow. In this example, we're going to create a flow that monitors Twitter for a certain hashtag and then posts a notification to a Teams channel. Such a flow might be useful if you're trying to gauge or capture customer sentiment for a product or service, track trending public health topics related to certain keywords, monitor engagement activity, or other topic-based alerts on a social media platform.

Understanding the flow components

This particular flow is going to rely upon a few components:

  • An identity for Twitter (username and password)
  • A trigger that monitors Twitter for certain words or phrases
  • An identity for Office 365 (username and password)
  • A Microsoft Teams team
  • An action that posts to Microsoft Teams

To complete this flow, we'll need to configure or obtain access to both Twitter and Office 365 identities, as well as a Microsoft Teams team where messages will be posted.

Then, we'll start creating the flow!

Creating and executing the flow

Once we have the prerequisite components for the flow (that is, the aforementioned identities and a team), we can begin the configuration. To build this sample flow, follow these steps:

  1. Log in to the Power Automate web portal interface (https://flow.microsoft.com). 
  2. On the left-hand side of the page, click + Create.
  1. On the Manage your flows page, under Start from blank, click Automated flow:

  1. Enter a name for the flow.
  1. In the Choose your flow's trigger box, start typing Twitter to filter triggers related to Twitter. Select When a new tweet is posted and click Create:

  1. Next, click Sign in to provide the necessary Twitter credentials to access the Twitter API:

  1. Enter the credentials of a Twitter account and then select Authorize app:

  1. In the Search text box, enter the text that you want to search for. In this case, the flow will be configured to monitor new instances of #learningpowerautomate:
All Twitter interactions with the hashtag will be queried, not just tweets posted by the account whose credentials were provided.

  1. Click + New step.
  2. Under Actions, search for the Microsoft Teams Post a message action and select it:

  1. Select a Team and a Channel where you have access to post messages.
  1. Populate the Message field. Many flows will give you access to dynamic content (data that is automatically populated, calculated, or retrieved) based on the context of the flow's connected data sources and actions. In this example, the dynamic content values, Tweeted by and OriginalTweet, have been selected to surface data provided by Twitter:

  1. Scroll to the bottom of the page and select Save.

Now that the flow has been created and saved, you can test it by generating content and then checking to see whether the content gets posted to the Microsoft Teams channel as you'd expect:

At any time, you can use a feature called Peek code that allows you to look at the underlying JSON code that controls how a step functions. To access the JSON, click the ellipsis (...) for a step and then select Peek code:

You can't directly edit them in the Power Automate user interface, but you can export it and edit it in an editor such as Visual Studio.

This flow built on your previous knowledge of flow components by adding dynamic content. We'll get into more dynamic content concepts in later chapters, but as you can see, being able to use dynamic content placeholders and references will increase the richness of the flows you create.