cancel
Showing results for 
Search instead for 
Did you mean: 

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

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

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor