Difficulty – Beginner Skill
Time – 2 – 3 hours with the tutorial
In this post we will look at how you can upload files with your desired text content using your voice and Echo enabled device, which could be the Echo itself, or your phone using Reverb app.
The article assumes that the reader has previous elementary experience with making Alexa Skills and understands the concept of how skills are made, but we will cover all of the important aspects to make this skill.
This tutorial consists of 3 parts:
- Uploading the code to AWS Lambda service
Setting up the Google Drive API and Account Linking
- Authenticating the user
So let’s get started with the first section.
1. Uploading the code to AWS Lambda service
First, we need to make a Lambda function and put our Python 3.6 code into it. This is the stuff that does all the backend logic for us when we ask Alexa to do something.
The first issue is, given that the skill has certain dependancies (python modules that the skill uses), we cannot just paste the code into the code editor, we need to make a so called Deployment Package (http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html). To make a long story short, we just need to download ’googleapiclient’ , ’httplib2’ and ’oauth2client’ packages and put them into the same location on our computer as the file with the lambda function code itself is and compress it (make a .zip file).
We will then upload this .zip file into AWS lambda.
The code itself is found in the ConnectToDriveApp.py file ( https://drive.google.com/drive/folders/0B6brXj4ch4-ycnNocXd6WjNaRVE?usp=sharing )
Copy ARN the text in the red field( *1 )– we will use this later in the Development portal
2. Setting up the Google Drive API and Account Linking
Next we want to set up the application on Google’s side, where we obtain certain IDs, which we will use later for linking the Amazon Skill and our Google account.
We have to go to https://console.developers.google.com, log in with our Google account and Create a project. Choose any name you want.
Then we go to Credentials > Create credentials > OAuth Client ID and there we select Application type: Web Application
Then we choose some name, leave the other parts empty and click Create. A pop-up windows will appear and we copy both ClientID ( *2 ) and Client Secret ( *3 ), we will use that later.
We open another tab and go here: https://developer.amazon.com
We go to Alexa tab and create a new skill, set up the name and Invocation name.
Then we open the Interaction Model tab and Alexa Skill Builder opens. We open the Code editor tab and paste there the content of InteractionModel.json. We click on Build Model, wait couple of minutes and then go to Configurations tab, this will close the Skill Builder interface.
On the Configuration page, we choose AWS Lambda endpoint, select North America and copy previously saved ARN ( *1) from Amazon Console into the field.
Now we are going to set up the Account Linking, which will enable the Skill to call the Drive API after receiving an access token from Google, which will authorise the user upon each request.
Authorization URL – This is where you have to authenticate and allow the Amazon Skill to access the DRIVE API. You give the permission only once through the Alexa app on your phone.
Be careful to change the redirect_uri part to the pitangui link in Redirect URIs section under Scope.
Client ID ( *2 ) and Client Secret ( *3 ) are the ones you have from Google Console.
Access Token URI is: https://accounts.google.com/o/oauth2/token?grant_type=authorization_code
Now comes an important step. Copy both Redirect URIs from the Account Linking Section and go back to your Project in https://console.developers.google.com. Go to Credentials and click on the Credentials you created. Paste both Redirect URIs from Amazon Developer Console to Redirect URIs field in Google Developer Console. This was the final step in linking both services together.
3. Authenticating the user
Now you only need to download the Alexa app on your phone ( you need to use an Apple ID with U.S. location to be able to download the app if you are using iPhone), log in with your account, click on Skills > Your Skills and enable the skill you just created and link the accounts. You should be redirected to the Authorization URI you set in the Amazon Developer Console. You sign in with your Google account there and from then on each request to Alexa Skill Service should now contain the Access token.
Good job, you are now ready to make notes with your Echo and upload them to your Google Drive.