cancel
Showing results for 
Search instead for 
Did you mean: 
ThatAPIGuy

Alexa, ask Microsoft Flow to read out my latest e-mail

https://twitter.com/that_API_guy/status/1104836878107373570

I posted this on twitter and got a lot of requests to create a blog on this , so here you go –

 

Why are we doing this?

We are all surrounded by different smart home devices and voice assistants around us. Wouldn’t it be great if we could use them to –

  • Add a task to To-Do
  • Read email/ send email
  • Read out calendar
  • Create a meeting invite
  • Add an item to SharePoint list and much more…

 

What do we need?

  1. Alexa device / Alexa app
  2. Alexa Developer console account  – Here is an overview of the developer console for your reference – https://www.youtube.com/watch?v=q-mrSBrlDso

Concept –

The idea is to create an Alexa Skill that can trigger a Flow when invoked from an Alexa device (like Echo) and send the response back from Flow to the Alexa device so that it can speak/read it out for you.

concept.png

 

 

How will we do this?

Step 1 : Creating an Alexa Skill

Don’t worry if this sounds alien to you. We will go through all the steps as if this was the first time you are creating an Alexa Skill.

Go to the https://developer.amazon.com/alexa/console/ and sign up for an account. If you already have an amazon account, you can log in with the same credentials.

Click on the “Create Skill” button.2019-03-11-05_44_21-alexa-developer-console.png

 

 

Enter a name for the skill , say “Microsoft Flow” and select the “Custom” model and “Provision your own” method for hosting the skill. Hit the “Create Skill” button.

 

2019-03-11-05_50_24-new-tab.png

 

Choose the “Start from scratch” template and click on the “Choose” button. If you want to learn more about Alexa skills, you can choose the other templates to understand how they work.

2019-03-11-05_54_40-alexa-developer-console.png

 

You will see this dashboard on your screen –

2019-03-11-05_55_27-new-tab.png

 

Let’s set the Invocation name first, which will be used to call the skill e.g. – “Alexa, ask Microsoft Flow to .. ” . Note: this name can be different from the skill name.

2019-03-11-05_58_46-alexa-developer-console.png

 

For this blog, I will trigger the Flow to get my last e-mail which will be then sent to Alexa that will read it out to me. So, let’s add an intent for this – “GetLatestEmail”. Click “Add Intent”, then enter the name of the intent and click “Create custom intent”

2019-03-11-06_02_10-alexa-developer-console.png

 

2019-03-11-06_03_16-alexa-developer-console.png

 

We need to enter some sample utterances that we willbuse to get the last email such as – “get my latest email”, “read out my last email”, “tell me my last email”. This will help Alexa know which intent you are trying to call. So, the complete expression that you will use –

“Alexa, ask Microsoft Flow to read out my last email”2019-03-11-06_11_13-alexa-developer-console.png

 

 

Next, we need to set the “Endpoint” from the menu on the left section and select “HTTPS”. This is where we will paste the URL generated by the HTTP request in Flow (Step 2).

 

Step 2 : Create a Flow with HTTP request and response

You can download the flow files here and directly import it if you want – https://github.com/thatapiguy/Trigger-Flow-from-Alexa-Microsoft-Flow

 

Otherwise-

Create a new blank flow. Use the Request trigger – “When an HTTP request is received”. This will be triggered when we invoke the Alexa skill from Step 1.

2019-03-07-20_08_15-create-your-flow-_-microsoft-flow.png2019-03-07-20_09_34-create-your-flow-_-microsoft-flow.png

2019-03-07-20_10_11-create-your-flow-_-microsoft-flow.png

 

 

For the “Request Body JSON Schema” – copy and paste the code from here https://gist.github.com/jeffhollan/f94234697ee02e9b5b86a3518ad05ebe . This is how the body in the HTTPS request from Alexa will be formatted. Here’s the code if you want to copy it from here –

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

{

  "properties": {

    "request": {

      "properties": {

        "inDialog": {

          "type": "boolean"

        },

        "intent": {

          "properties": {

            "name": {

              "type": "string",

              "x-ms-summary": "Intent Name"

            }

          },

          "type": "object"

        },

        "locale": {

          "type": "string"

        },

        "requestId": {

          "type": "string"

        },

        "timestamp": {

          "type": "string"

        },

        "type": {

          "type": "string"

        }

      },

      "type": "object"

    },

    "session": {

      "properties": {

        "application": {

          "properties": {

            "applicationId": {

              "type": "string"

            }

          },

          "type": "object"

        },

        "attributes": {

          "properties": {},

          "type": "object"

        },

        "new": {

          "type": "boolean"

        },

        "sessionId": {

          "type": "string"

        },

        "user": {

          "properties": {

            "userId": {

              "type": "string"

            }

          },

          "type": "object"

        }

      },

      "type": "object"

    },

    "version": {

      "type": "string"

    }

  },

  "type": "object"

}

 

Add an action “Get Emails” (Outlook 365 Connector) to get the latest email. To get the last email, enter the value 1 in the ‘Top’ property.

2019-03-11-06_37_46-edit-your-flow-_-microsoft-flow (1).png

 

Now, add the Request “Response” action to send the response back to the Alexa Skill.

2019-03-11-07_51_59-edit-your-flow-_-microsoft-flow.png

 

For the body, we will use the below code . You can see that I have used some expressions to read out different details of the email. To test the skill initially, you can just put some random text under “text” :”This is just a test” and once your skill is running fine you can come back and change it to below.

1

2

3

4

5

6

7

8

9

{

  "response": {

    "outputSpeech": {

      "text": "You received the last e-mail at @{formatDateTime(body('Get_emails')[0]['DateTimeReceived'],'h m tt')} from @{body('Get_emails')[0]['From']}, regarding  @{body('Get_emails')[0]['Subject']}. Here is an excerpt of the email -  @{body('Get_emails')[0]['BodyPreview']}",

      "type": "PlainText"

    }

  },

  "version": "1.0"

}

 

The Flow is complete now. Name the Flow something meaningful (this is important, you will realize it when you have more than 50 Flows  ) and hit the “Save” button. This will generate a URL in the HTTP request Trigger. Copy the URL and now let’s complete our Alexa Skill.

 

Step 3: Complete the Alexa Skill Endpoint details and Build the Skill

Under the Endpoint section, paste the copied URL from Step 2 and paste it in the Default Region. Select the SSL certificate as shown in the image below and click “Save Endpoints”.

2019-03-11-07_12_08-alexa-developer-console.png

 

Now, go to the Invocation Section and Click on “Build Model”. It might take some time to build the model the first time. (around 20-30 seconds)

2019-03-11-08_43_29-alexa-developer-console.png

 

And that’s it! The Skill is built now and ready to be used in Development mode. (You don’t want to share this with anyone because the Flow will use your outlook connection. )

 

Step 4: Fun time! Let’s Test the skill

The skill should be enabled by default in your Alexa settings.

Time to say the magic words –

 

Alexa, ask microsoft flow to read out my last email.

 

I will be doing a live AMA on this topic on Wednesday 13th March 6 PM Eastern – https://www.youtube.com/watch?v=K3G3k_Bamqg

 

Join me to dig deeper on this topic and ask any questions that you have.

 

Vivek Bavishi aka That API Guy

PowerApps MVP

Blog | Twitter | YouTube | Community Profile | GitHub

 

Comments

This is super creative... intimidating at first, but creative! Thanks for sharing

Anonymous

This is amazing this works perfectly.

 

If I wanted to adapt this so I can say " Hey Alexa, book a room in *room name* at 2pm" would this be possible. I tried to give it a go but I couldn't figure out how to change it.

 

Thanks so much

Great article. Only obstacle: to trigger a Flow via HTTP you now need a Premium account. And for doing some fun stuff I'm not willing to pay $$$.

@hjrb 

 

You can use a community plan (for individual use) to do this without paying anything.

 

https://powerapps.microsoft.com/en-us/communityplan/

I know I'm late to the party, but for anyone reading this, please don't follow this walkthrough until you know how to properly secure an M365 requests-triggered flow. Extremely unwise to do so.

 

Requests to trigger PA flows aren't authenticated by default. The general public would be able to trigger the PowerAutomate flow you create here. 

 

I'm especially concerned for anyone who followed this review indirectly to do something more dangerous, like send emails, messages, add items to lists, delete resources, edit DB data, etc. 

 

Just google "how to secure HTTP triggered flows". It's not very hard, and it's incredibly important if you don't like the idea of the general public using your M365 credentials to view or manipulate your private data.

 

-Logan

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/