A dockerized Alexa Skill API using flask-ask with a MySQL database. This is a clean base template.
- amazon developer account (see https://developer.amazon.com/)
- noip Account (see https://www.noip.com/)
- docker
- docker-compose
- openssl
- Create a NoIP Hostname on https://www.noip.com/ (e.g. myapi.ddns.net)
- Navigate to the api folder of the repository
- Create a self signed certificate (you may also see https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https)
openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
- Please fill the following prompts along your circumstances:
- Country Name (2 letter code) [AU]: DE
- State or Province Name (full name) [Some-State]: Saarland
- Locality Name (eg, city) []: Saarbrücken
- Organization Name (eg, company) [Internet Widgits Pty Ltd]: My ASK Business
- Organizational Unit Name (eg, section) []:
- Common Name (e.g. server FQDN or YOUR name) []: myapi.ddns.net (NoIP hostname belongs here)
- Email Address []:
- Navigate back to the repository root and execute:
docker-compose up
- Enter the amazon developer console
- Create a new alexa skill
- Enter the skill name (this is only the display name on your amazon developer console)
- Choose a default language (this will be the language in which you communicate with alexa)
- Choose a model to add to your skill: Custom
- Choose a method to host your skill's backend resources: Provision your own
- Select Create Skill (button)
- Choose a template: Strat From Scratch
- Select Choose (button)
- Navigate to JSON Editor, delete the whole code and copy the following code:
{
"interactionModel": {
"languageModel": {
"invocationName": "<here comes your invocation name>",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "YesIntent",
"slots": [],
"samples": [
"natürlich",
"ja"
]
},
{
"name": "AnswerIntent",
"slots": [
{
"name": "first",
"type": "AMAZON.NUMBER"
},
{
"name": "second",
"type": "AMAZON.NUMBER"
},
{
"name": "third",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"{first} {second} and {third}",
"{first} {second} {third}"
]
}
],
"types": []
}
}
}
- Do not forget to change the invocationName in the JSON code (this will be the name to call your skill on alexa)
- Select Save Model (button)
- Navigate to Endpoit
- For Service Endpoint Type check HTTPS
- As Default Region enter your NoIP hostname (here: myapi.ddns.net)
- For the SSL certificate type choose: *I will upload a self-signed certificate in X 509 fomat
- Select Save Endpoint (button)
- Select Click here to upload your certificate and provide the cert.pem in the api folder
- Select Save Endpoint (button)
- Navigate to Invocation
- Select Build Model
- Navigate to Test in your amazon developer console
- Set Skill testing is enable in to Developmet
- Hold the mic button and start talknig to Alexa!
When cloning this repo, the database will load a static table from the db/init folder of the repository.
Warning: At that time the database is not persistent. Every change to the database will be lost on container restart!
After the first container start, copy the mysql data to localhost as follows:
- Get the database container id using
docker ps
- Navigate to the repository root
- Copy mysql folder (unfortunately it is not possible to specify folder/* to copy all files from a folder):
docker cp r CONTAINER_ID:/var/lib/mysql db
- Move files from within mysql into storage and remove the mysql folder:
mv -r db/mysql/* db/storage/ && rm -r mysql
- Edit docker-compose.yml
- Disable
- ./db/init:/docker-entrypoint-initdb.d
- /var/lib/mysql
- Enable
- ./db/storage:/var/lib/mysql:rw
- Save the file and restart the containers
https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https