Email Voice Service
After thinking about Voice assistants and how much they help in day to day life for its users the thinking of its potential and what it could do appose to what it can do now. So I thought of creating an voice application that will allow people to have their emails displayed back to them on there smart home assistants with voice telling the user things like “who has emailed me today” and “show me todays emails”. I started of by reserching the UX of voice, the approach needed to make this application, Why this application would be of relevence to use, Who the target auidence is, how long it would take as well as How to build the application, etc.
When I was finished with the reserch that was neccacery before I would start to build the application I came across some people who had managed to do it before, one was an Company called Newton who were an email mangment company that allowed users from mutipul devices to acess there emails in an merged inbox for example the user could have both their Gmail & Outlook connected to an account so they recive the emails in 1 inbox. Newton had an Alexa Application that would allow users to connect to their accounts & be able to have their emails read back to them. The other person who I had found who had built the application was Becky Richas who created the skill that would allow users to connect their gmail & have the ability to not only have emails read back to them but also save attatchments in Google Drive . Becky had created an guide with all the neccary files to build this email application and the steps on how to build it which is what this guide is based off but is an more up to date version as this guide was created in 2016 & with the development site of Amazons always changing some of the things in her guide are slightly incorrect so this guide is to tell you how to build this application as of 2019.
Introduction
This is an guide on how to create an Alexa Application that allows users to send & recive email from their Gmail account that is based off Becky Richas Guidefrom 2016.
Guide
This Guide Shows how to build the Alexa Application.
Before you start
There are certian things that are required before you can build this application. The following things are.
- Set up an Google Account if you do not have one already. You do not require an developer account as it's not neccacry as you can just use one link to acess your Google Developer Console
- You will require an AWS Lambda account. It is an Amazon service that hosts the skills code, you will be required to enter an payment method however there are no charges to using this service
- You will require an Amazon account if you wish to use the skill on any of your devices & also will need to use the same email as the Lambda in order to automaticaly have your skilll on your account otherwise you will have to manualy add the user for them to get the skill unless you publish the app publicly.
Step: 1 Google Developer Console Setup:
- Open up https://console.developers.google.com if you do not obtian an account already just agree to the terms & services
- On the navigation menu which is on the left side find & open credentials, once you have done this create an project, you can name it what you please and it is not needed by the skill
- Now close the popup box & go back to the creditail screen where at the top select oauth consent screen where you will enter the information that users will see when asked to confirm the skill. You can put whatever you wish to on there but it is good to know for making your own skills later on & remember to SAVE when you have finished.
- Click on credentials to create credentials and select Oauth client ID
- Under the Application Type select “web application” and give the credential any name you choose. This will be used later on as we shall be able to input the JavaScript Origins and Redirect URLs. At this moment in time click create, once this is done a box will appear with your oauth client information that will be required later on. Keep this open as it will be easist later for when you need to copy over the links that you require.
- Open up the Navigation menu and find the dashboard as you will need to add some spcfic API's these being the following you may use the links below to automatacly find these API's, don't worry about them taking a little longer than expected to load as this is so that it opens up on your project.
Once you have added these they should appear at the bottom of the dashboard. We have finished here for now but you may wish to keep it open for later on.
You are now finished with this step move onto Step 2
Step: 2 Setting up AWS Lambda
- Open up https://aws.amazon.com/lambda/ Click "get started with AWS Lambda" which you'll find near the center of the page
- Then sign in to your account, if you do not have an account plaese create an account & follow the instructions that they provide. You will be asked to require an payment method which you MUST enter however there are unlikley to be any costs to creating, THIS APPLICATION IS COMPLETLY FREE. If you are building this Application in the UK set the Region to EU Irleand & not London as currently as you cannot add the Alexa Skills Kit if the region is set as EU London for some unknown reason so you must use EU Irland.
- When you are in the console navigate under services to Lambda
- You should find a button to "create function" press this & create an function from skratch for the name use one you'll remember the runtime should use node.js, any version can be used but using the most upto date version would be advised, for this application and the role you should create an custom role which will redirect you to a page called IAM on there choose create an new IAM role & an auto genrated name should come up "lambda_basic_execution" leave this select save which should take you back to the create an function page & now select chose an existing role and select the role you have just made and you will be redircted an page with your function.
- On the configuration page on the top right of the page you should see your user name & your location please ensure that the location is correct so if you are building in the UK ensure that it is Ireland & not London if you are in the incorrect location then when you set it to the correct location you may not see your function which means you need to redo the previous stage but in the correct location.
- Scroll down & you should find an section called "Function Code" in this you should find entry type and choose upload from zip which you should upload code.zip then click save and the code should be visable in the Function Code section. Also ensure that the runtime is on a version Node.js
- Further down the page under basic settigns you will want to amend the memory to 256MB and an timeout of 45 seconds and in the discriptiion call this memory timeout.
- Once all is set correctly then you should see that theres an add trigers section in here click on the "Alexa Skills Kit" then on on your function as you will configure the Skills Kit later on so DO NOT CLOSE THIS TAB. Also in the top right you should see somthing called "ARN" with a big long code looking like this "arn:aws:lambda:{region}-1:{a bunch of numbers}:function:{your function name} save this for later on as it will be needed.
You are now finished with this step move onto Step 3
Step: 3 Alexa Developer Console Setup
- Open up https://developer.amazon.com
& sigin in to your account or signup if you need to. Once you are logged in press the Alexa button & you will be directed to https://developer.amazon.com/alexa click "Create Alexa Skills" & start a Skill. This should give you a list of your skills if this is blank then that's because you havn't created an skill before if not it will show all your skills that you have created. On here you want to click the button to "Create Skill".
- You will be asked to create an skill name for this enter as you please select your languague which should either be English (US) or (UK) and custom for the model, once selected you will be directed to a page asking you to chose an template which you should select "start from scratch"
- You should now be on a page which should have somthing called "Interaction Model" on the left hand side underneath that should have Invocation click on this and it will already have an name which is rereived from the name you gave the skill you can change this to what you wish just remember that when the skill is built to activate the skill you will need to say "Alexa ask (Invocation Name)".
- Click on Intents which you should already have 5 installed these should be Fallback,Cancel,Help,Stop,NaviagetHome. If you have all the following then go to the JSON editor & you shuld be able to "drag or drop a .json file" here you want to drop the Interaction Modal.json File once you hav done this click save, there shouldnt be any errors. If you wish to learn more about the code please delve in & take a look at the code.
- Now go to EndPoint & for Service Endpoint Type select AWS Lambda ARN
- Under the Defualt Region paste in the the ARN you got at the end of setting up your lambda function
- Click save & navigate to account linking
- There should be a box asking "Do you allow users to create an account or link to an existing account with you?" please enable this option
- Under Security Provider Information select the grant type as "Auth Code" & fill the form with the details below
- Authorization URL: https://accounts.google.com/o/oauth2/auth?access_type=offline&response_type=code
- Access Token URL: https://accounts.google.com/o/oauth2/token
- Client ID: This will be found if you return to your creditails in your google developer console
- Client Secret: Will be found underneath creditails in your google developer console
- Client Authentication Scheme: HTTP Basic
- Scope:
- https://www.googleapis.com/auth/cloudprint
- https://www.googleapis.com/auth/gmail.modify
- https://www.googleapis.com/auth/script.external_request
- https://www.googleapis.com/auth/drive
- https://mail.google.com/
- Once all these have been completed Save
You are now finished with this step move onto Step 4
Step: 4 Set up Google Apps Script
- Go to http://script.google.com, this should lead you to a page called “untitled project” on here you need to overwite the function that is present with the text provided in the google apps script.txt
- Under resources click on cloud platform project & you should find a pop up window saying change project & giving you an option to enter a project number here you need to paste the client ID you got from the Google Developer Console
- Once sucessfully changed close the window go to resources then liberies & copy the project key that you can find under File > Project Properties, once entered make sure to SAVE
- Now select Publish > Deploy as API executable, enter any description you wish and click “deploy,” then “continue, Copy the long string from the “current API ID” box and put it somewhere you can find it. (if it is not selectable, close this and re-open the “deploy as API” dialogue).
You are now finished with this step move onto Step 5
Step: 5 Linking it all together
- Return to AWS Lambda, open your function go to the functional code & make sure that it is all correct & then move on to Enviromental Variables where you will create 2 variables.
On the “code” tab, first make sure there is not an error on the first line. I have had issues uploading the code and finding a period inserted at the first character. If there, delete that and press save. (you will know because there will be a warning symbol along the left).
- The first one Name as scriptsID (case matters), enter it's value as the Project Key which you can obtian in the project proprties in Google Scripts you may also use the Current API ID as this is the same key, you can find this in the last step of step 4
- For the second variable, call this appID (case matters) and it's value is the ID of your Alexa Skill it should start with "amz1.ask…", this can be found in the endpoint in Amazon Developer Console
- Now Save this on Lambda & return to the Google Developer Console
- Open the credentials that was made in step 1 and there should be an option to add authorized JavaScript origins and authorized redirect URIs. For Javascript origins add the following as displayed
- https://layla.amazon.com
- https://pitangui.amazon.com
- https://alexa.amazon.co.jp
-
For the authorised redirict URLs they can be retrevied from Amazon Developer Console in the account linking where at the bottom of the page you should find 3 redirect URLs looking like the following.
- https://layla.amazon.co.uk/api/skill/link/[ID number]
- https://pitangui.amazon.com/api/skill/link/[ID number]
- https://alexa.amazon.co.jp/api/skill/link/[ID number]
copy these over & then ensure that you SAVE.
From doing this you have just allowed your Alexa Skill to get the acess tokens from Google, your Lambda code knows which Alexa Skill is authorized to use GMail Scripts (Where we set the enviroment variables). Google also knows what Amazon sites are authorised to call it (redirect & orgin URL's we pasted in) and now knows the app is authourised to you (Your client ID & Secret you placed on Alexa Skill Account Linking)
You are now finished with this step move onto Step 6
Step: 6 Finished Project
Now you should be able to go to the Alexa App and go to Your Skills & under developer find your Alexa Application avliable which you can enable link your account & try it out. When linking you will be told that the link is insucure but the only reason that this comes up is because there hasn't been an terms of use URL & Privacy Policy but these are not required unless you wisth to publish this application or put the application in BETA mode which is used so that you allow users you want to test the skill.
Once linked you will open the applicatiion up & you will be asked to set up a PIN which if you choose to set up will ask you for this everytime you open the application before you can do anything, if you choose not have a pin then you can just acess your information freely.
However if you come across the issue that you have forgotton your PIN then you can retrieve this from your Google Drive which will be in a file called Alexa PIN & if you are still having trouble then if you delete this file you will automaticaly have removed this PIN & can set an new one if you wish to.
Files
Download all the neccacary files you need
Files Required
These are all the required files you will need to build the application
- Code.Zip
- InteractionModel.json
- google apps script.txt
Usful Links
These are the links that you require to build this application
File Links
If you download this master zip it will contain all the neccacery files that are required to build the application
alexa-gmail-master.zip
About
Who we are and what we do.