This simple GMail Alexa skill allows users to authenticate into a GMail account and retrieve the unread messages, and either read it aloud or skip.
To run this skill you need to deploy the code in lambda and configure the Alexa skill to use lambda.
- Sign into the AWS console (aws.amazon.com) and click on the Lambda link. Make sure you are in us-east.
- Click create a Lambda Function
- Skip the blueprint
- Configure triggers by adding "Alexa Skill Kit"
- Name the function "GMail-Reader-Skill"
- Select the runtime as Node.js
- Select all the files and create a zip file. (Remember to run "npm install" inside your directory to install all the dependencies.)
- Select Code entry type as "Upload a .ZIP file" and then upload the .zip file to the Lambda
- Keep the Handler as index.handler (this refers to the main js file in the zip).
- Create a basic execution role and click create.
- Leave the Advanced settings as the defaults.
- Click "Next" and review the settings then click "Create Function"
- Copy the ARN from the top right to be used later in the Alexa Skill Setup
- Go to the Alexa Console (developer.amazon.com) and click Alexa > Get Started > Add a New Skill.
- Select Custom Interaction Model as the skill type. Set "GMailReader" as the skill name and "G mail reader" as the invocation name.
- Copy the Intent Schema from the included IntentSchema.json
- Copy the Sample Utterances from the included SampleUtterances.txt
- Select the Lambda ARN for the skill Endpoint and paste the ARN copied from above.
- Click yes to enable account linking. Set the GMail Authorization URL and visit the Google API Console to obtain OAuth 2.0 credentials. (You need a client ID and client secret that are known to both Google and your application).
- Add https://mail.google.com/ and https://www.googleapis.com/auth/gmail.modify to scope.
- Select "Implicit Grant" as the Authorization Grant Type.
- Add https://www.google.com/intl/en_us/mail/help/terms.html as privacy policy URL.
- Add the CLIENT_ID, CLIENT_SECRET, and REDIRECT_URL variables in index.js.
- [optional] go back to the skill Information tab and copy the appId. Paste the appId into the index.js file for the variable APP_ID, then update the lambda source zip file with this change and upload to lambda again, this step makes sure the lambda function only serves request from authorized source.
- Your skill is now ready to test!
User: Alexa, ask G Mail reader to check mail.
Alexa: You have 3 unread messages in your account. Do you want me to list them?
User: Yes
Alexa: Message from Jennifer Lawson received on Monday August 4 at 2:40 P M with subject Hello World
User: Read
Alexa: Hello! How are you doing? End of message. Do you want to list the next message?
User: Yes
Alexa: Message from Ashley Brown received on Sunday September 2 at 4 P M with subject Meeting
User: Next
Alexa: Message from Pandora received on Friday September 6 at 3:20 P M with subject New music
User: Next
Alexa: There are no more unread messages to list. Goodbye.