Flow + Alexa – Post Message to Teams
About a week ago, I did a video with Jon Levesque on his YouTube Channel on Alexa and Flow integration. In the video, I showed how to create an Alexa skill that calls a Flow which reads off your Planner tasks. The beauty of this approach is you can easily create an Alexa Skill with zero code because you use your existing Microsoft Flow skills to do all of the heavy lifting. If you missed the video and want to get up to speed on the basics of getting started with an Alexa skill you can watch below:
After posting that video, I noticed several people asking how you could make Alexa pass values back to Flow to perform an action. I started thinking about that and thought of a good use case. I use Microsoft Teams for most of the communication in my business. Wouldn’t it be cool if you could have Alexa post a message to Teams for you? Let’s walk through how to do this.
Create The Flow Structure
We’ll start by creating a new Flow with a trigger of “When an HTTP Request is Received”. We will come back to this trigger later and fill it in with a sample schema. Next, insert a Compose action which we will fill out later. Then, add a “HTTP Response” action. We’ll stop here for now and save the Flow so that we can get the HTTP Endpoint to use in our Alexa skill. We can finish configuring the Flow later on.
Creating the Alexa Skill
You’ll follow the same steps that I outlined in the video above to create your Alexa Skill. This includes pointing your Skill to the Rest HTTP EndPoint that you’ll copy from your Flow Trigger and creating an “Intent”. An Intent is where you tell Alexa what you want to do. You provide “sample utterances” which are what you might say to get Alexa to do what you want her to do.
Setting up the Parameter
We will need to do a couple extra configuration steps to get the skill to ask us for data and pass it back to our Flow. First, you’ll need to create a new “Slot” to hold the data you want to post to Teams. Amazon has a variety of pre-built Slot Types to choose from. For example, if you were wanting to pass in a date, there’s a corresponding Slot Type for that. If, like in this case, you are wanting to pass in free-form text, you can use the “SearchQuery” Slot Type. Just click the Add button next to Slot Types to get started:
Then Select, “Use an Existing Slot Type from Alexa’s Built in Library”. Choose the “Amazon.SearchQuery” type.
Now we need to go back to our Intent and fill in an Intent Slot. This will map what we tell Alexa we want to post back to our Slot Type so that we can pass it on to Flow. Just type in a name for your Slot Intent (I called mine Message) then map it to the SearchQuery Slot Type we defined earlier.
Where it asks “Is this Slot Type required to fulfill the intent”, choose yes.
Testing & Getting the Schema
Once you’re done, click Save Model ,then click Build Model. Once your Model is built, we need to go to the Test tab and run a Test. I know you’re probably thinking, this isn’t going to work because we didn’t finish configuring our Flow. Well, in order to finish configuring our Flow, we need to get a sample JSON schema for it and we get that by using the Testing mechanism.
You can type in your invocation like you see above. It will ask you for the message and then execute. What you want to do is copy the “JSON Input” block of text that it spits out. This is the JSON Schema for your Flow. Now let’s jump back over to Flow to finish this out.
Finishing the Flow
With the JSON Schema copied, you need to go back to Flow and click the “Use Sample Payload to Generate Schema” on the HTTP Trigger. Paste in the JSON you copied in the previous step:
Now that you have a sample schema, you need to extract the message. If you take a look at that JSON, you’ll see the Message is being stored in an object called “value”. To get that value, use the Compose Action below the HTTP Trigger. Use the Dynamic Content to input the Value object from the HTTP Trigger in the Compose.
Now insert a “Post a Message to Teams” action. Select what Team and Channel you want to post to from the dropdown boxes. If you want to make it Dynamic where you can tell Alexa what Team to post to you can, however, that’s more involved. The Team and Channel dropdown’s require you to pass it the ID’s instead of names. So you would have to use the Office Graph to get the ID’s before you could do that. For simplicity’s sake, I skipped that and hard-coded it to always post to a specific Team/Channel.
For the Body of your Post a Message action, put in the Compose action that was created earlier:
Now the last thing you have to do is return a success message back to Alexa. That’s done using the HTTP Response action that was created earlier. Just fill out the Body of that action with the following code:
{
"response": {
"outputSpeech": {
"text": "Your Message : @{outputs('MessageValue')} has been posted to the ThriveFast Channel",
"type": "PlainText"
}
},
"version": "1.0"
}
Click save and you’ll have a fully functional Alexa Skill that takes inputs and posts a message to Microsoft Teams! I’ve provided a video below which walks through this process as well.
Please tweet me or comment on this blog and tell me what you think would be cool to build with this functionality!
Great work