I think if Alexa could actually do my taxes then Jeff Bezos would be the richest man on earth /s
This tutorial is a light introduction into getting a basic skill setup on Amazon Alexa, using AWS Lambda and CapitalOne's UK developer API.
Before we get started we need 2 accounts:
- AWS Account - https://aws.amazon.com/Sign-Up
- Amazon Developer Account - https://developer.amazon.com/
It should be pretty quick setting both of these things up, your AWS account may require card info but it won't charge your account unless you start using chargable resources. The material in this tutorial DOES NOT cause any charges to your account. Unless you make over 1million requests to your Lambda within a month, in which case I accept no responsibility for that cost.
For those that are interested, you can view the free tier Lambda model here
After you've setup and logged into the https://developer.amazon.com/ console we can create a simple skill.
- Click on
Your Alexa Consoles->Skills - Now
Create Skill - Name your skill something appropraite for instance "banking app"
a. Language - English(UK)
b. Under the choose a model section, select - Custom (should be selected by default)
c. When choosing a method to host your skills resources - Custom (should also be default)
d.
Create Skill - Choose a template - Start from scratch
Congrats, the skills created, although it's nothing more than a shell with a name that literally does nothing - lets give it a purpose (insert Rick & Morty robot joke here)
- Copy the contents of the model.json file found in this repo under the models folder, or click here
- On the left of your developer console go to the
JSON EditorunderInteraction Model - Paste the contents of the json file here and click
Save Modelat the top
Should everything have worked correctly you will now see 2 intents having appeared under your invocation model:
- GetAccountInfo
- ListPendingTransactions These are the function calls you'll be passing into the backend service, and if you check out there sample utterances you'll see some sample phrases prepopulated that can be used on Alexa for calling this specific function - feel free to add more, just make them relevant.
We've got mose of our skill setup done now, so open a new tab and we'll move onto the backend functionality that's going to "do my taxes".
Make sure you're logged into https://aws.amazon.com
I've already created a sample Lambda which you'll be able to build on make go ahead and download it from the following link: https://s3-eu-west-1.amazonaws.com/ryan109-workshop-storage/alexa-tutorial/lambda_function.zip
- Type
Lambdainto the aws search box Create FunctionAuthor from scratcha. Give your function a relevant name "alexa_banking_skill" b. Runtime -> Python 3.6 c. Create Lambda- Scroll down to the
Function Codesection, underCode entry typechooseUpload a .zip filea. Select the downloaded lambda zip b. PressSaveat the top right - Save the updated function
- Configure a new test event using the drop down beside the test button
- Copy getAccountInfo & getPendingTransactions json models saved in this repo, and create a test event for each one.
- Press
test, on the log output you should get a response relevant to the event you're testing.
Note: The transaction test may time out from time to time, this is a problem with API it's trying to hit.
Now that our Lambda is working we need to plug it in to our Alexa skill so she can finally do our taxes, for this naviagte to the deisinger tab at the top of the page:
- Click the Alexa skills kit from the left hand side, this should add it to your stack.
- Click on
configuration requiredunder the newly added trigger - Swap tabs back over to your skill and click on the
Endpointsection from the drop down on the left a. Select AWS Lambda b. Copy your skill ID - Swap back over to the Lambda console and paste your skill ID in the required box.
- Now copy the ARN of your Lambda which you can find in the top right of your console e.g:
arn:aws:lambda:eu-west-1:0000000000000:function:example_lambda - Swap back over to your skill and paste it in the
default regionbox just under where Skill ID is noted. - Save both your Skill and your Lambda.
Now say the magic words and pray to whatever serpent God you believe in...geddit, Python? (Still have no idea why I chose programming over stand up)
It's time to start chatting up Alexa and see what she can do.
Go to your Alexa Skill and along the top click on the testing tab, then make sure the Skill testing is enabled in - Development.
On the left you'll see the Alexa simulator where you can have a conversation with her by typing, all going well it should go something like this: Me: "open banking skill" (Or whatever the name of your skill is) Alexa: "Welcome to your example credit card. Why don't you ask me about your account information or pending transactions." Me: "account information" Alexa: "This account is a capitalone credit card and the card number associated with it ends in XXXX" Me: "pending transactions" Alexa: "Of the last X transactions, a total of X are pending"
Mic. Drop. There you have it folks, a super simple Alexa skill pieced together using Lambda & Python. Why don't you take a closer look at the code to see how it's done, or try expanding your function to introduce some new features.
The ability of the CapitalOne API we're using is still in it's infancy, but as that's built out I'll continue to add new features to this tutorial.
Disclaimer: I am not a Python dev nor do I claim to be, this tutorial was the begining of my Python days so please feel free to critique. If you'd like to expand on this or contribute just get in touch or throw in a PR.