This tutorial will show you how to easily connect Amazon’s Alexa-controlled device to Medium One cloud without any additional hardware. You will utilize Alexa’s voice control interaction with Medium One.
The example used in this tutorial is quite trivial; you will ask Alexa to generate a random number. Per your voice-controlled request, Alexa will provide a random number, which is generated by M1 workflow executed on fly at the moment of Alexa’s request.
The simplicity of this example was chosen to underline the easiness at which Medium One and Alexa-controlled device seamlessly interact.
For this tutorial you need:
- Familiarity with Medium One Getting Started Guide
- Any Medium One project and the activation email that came with it
- An Amazon Developer account (https://developer.amazon.com/)
- An Echo Dot, Echo, or Tap
Step 1: Create your Alexa Skill
Log into your Amazon Developer account at https://developer.amazon.com/. Click on “Alexa” from your dashboard.
Click “Get Started” under the Alexa Skills kit:
Click “Add A New Skill.”
On the Skill Information page:
- For Skill Type, click “Custom Interaction Model”
- For Name, put “Generate random number demo”
- For Invocation name, put “medium one”
- In Global Fields, select “no” for Audio Player
Once saved, click “Next” to move to the next page.
On the Interaction Model page, copy and paste the following into “Intent Schema:”
Your “Intent Schema” should look similar to this:
Now, you need to define the question through which you require Alexa’s response.
In Sample Utterance window, type in the following text:
SensorStatusIntent for random number
Your “Sample Utterances” should look similar to this:
Note: This correspond to a following request to Alexa: ‘Alexa, ask medium one for random number.’
Click on the “Save” button. It will take a few seconds to build the model. Leave this page open for now, you will need to come back to it in the next step.
Step 2: Create an Alexa Stream
Log into Medium One. Open your project; in this tutorial, we created tenant called ‘Ask Alexa for random number demo.’
Click on “Config→ Data Streams”. Scroll to the bottom and click “Create New Stream.”
In Create New Data Stream page, name the stream “alexa_requests”; then, click “Save Data Stream.”
Once saved, your Config Data Streams page should look similar to this:
Step 3: Linking Alexa and Medium One
For this step, you will need to switch between the Amazon Developer configuration page and the Medium One’s OAUTH Clients Page.
In your Medium One Sandbox account, go to “Setup” -> “Manage OAuth Clients”. Click on “Add New OAuth Client.”
On Authorize a OAuth Client page, enter Name and Additional login message for the OAuth page, as shown below.
Under Permissions, leave “Stream Access Permission”, then click on the plus sign to the right. Check both, the read and write permissions, and choose “alexa_requests” as the Stream Access Permission.
This gives Alexa a skill permission to send data to this stream. Leave this as is, and switch back to your Amazon Developer page.
This tutorial assumes that you have not navigated away from anything on this page since Step 1.
Click on the “Configuration” tab.
On the Configuration page, under Global Fields, configure appropriate Endpoint and Account Linking.
- For the Service Endpoint Type, select “HTTPS”
- For Geographical region, select “North America”
Once the region is selected, paste following link “https://assistant-sandbox.mediumone.com/alexa_request?stream=alexa_requests”
In Account Linking, select “Yes” to allow users to link the account.
Still in Account Linking, paste “https://auth-sandbox.mediumone.com/oauth2/authorize” in Authorization URL at the top, and “https://auth-sandbox.mediumone.com/oauth2/token” lower down where it says Access Token URI. Make sure “Auth Code Grant” is selected.
Take note of the two Redirect URLs in the blue box.
Switch back to Medium One Sandbox account tap that you left opened.
Copy and paste these Redirect URIs. Use the plus button to add the second URI. Click “Save.”
Once saved, your page should look similar to this.
Take note of the Client ID in the green box, and the Client Secret in the orange box. Copy and paste these into the green and orange boxes on the Amazon Developer page:
Once copied, your Account Linking should look similar to this:
You do not need to put anything for Domain List and Scope.
Finally, on SSL Certificate page, configure Certificate for NA Endpoint.
Select the middle option, then click “Save”.
Step 4: Link your account
Go on the Alexa App on your phone or the desktop version here. Make sure you are logged into your Amazon Account and you have already configured your Echo device. This tutorial shows how to link your account to Alexa using your mobile device; however, the mobile app and website look very similar. Navigate to skills.
Click on Your Skills on the upper right-hand corner.
Navigate to the skill you created. In this tutorial, the skill is called “Microchip LED Generate Random Number Demo.”
Click “Link Account.”
Note: If you ever want to link to a new user, you’ll have to disable the skill then re-enable it to unlink.
Enter the Username and Password of the user “device” that you received the login info for in the activation email for this project.
You should see this on the next page, with your skill name:
Go to your Amazon Developer account.
On the Test page, try to simulate command for Alexa.
Go to Service Simulator section and type in “ask for random number”; then, click the “Ask Generate random number demo” button.
You will see “There was an error calling the remote endpoint”. This is OK, as you have not created the workflow that generates that required random number yet!
Note: Once you sent this request, your Sandbox account shows the received request in Real Time Stream Events log file. Please note, that all appropriate tags were also created. Your log file should report a similar message:
Finally, you can easily confirm the sent request by viewing it in Data Viewer.
Go to “Data Viewer” -> “Data Streams”, then click on ‘alexa_requests.’
You should see one event like the photo below.
Step 5: Create Workflow
Go to your Workflow Studio and create a new workflow called “Generate number for alexa.”
In Tags and Triggers, under alexa_requests, drag “alexa_requests:request.intent.name.”
In Modules, under Foundation, and drag Base Python. Connect in1 to the green box. In Outputs, drag Processed Stream- Single to the screen. Connect out1 from the blue box to in1 on the orange box.
Double click on the Base Python and replace the code with the code in this link:
Then, click “Save and Activate.”
Your workflow should look like this:
Go back to the Test page of Amazon developer’s website.
In Service Simulator, enter utterance “ask for random number.” You should see JSON type event come up in the response section, as shown below.
Step 6: Talk to Alexa
Now, you’re ready to ask Alexa to get your random number.
“Alexa, ask Medium One to generate random number.” Alexa responds by saying a random number. The number was generated on fly by Medium One workflow at the moment of Alexa’s request.
You have successfully connected your Echo device to Medium One!
Feel free to modify/create new workflows to respond to different Alexa commands.