If you’re looking for a way to create an Alexa voice enabled bot then you’re on the right place!
Let’s create an Amazon Alexa bot from scratch using node server running on our localhost and tunneled through ngrok.
Sign up for an Amazon developer account, if you don’t have one
Go to Alexa developer page
Go to the Alexa console
Click on Create skill
Give a name to the skill, I have named mine TestSkill and click on Next
Choose a model to add to your skill, I’ve selected custom for my experiments
Click on Create skill
This way you reach to the Alexa skill dashboard
Now, we need to provide the endpoint to Alexa console but first we need to setup an endpoint.
Creating a node server
Create a server which can accept POST requests on default location i.e. “/”.
There are so many techniques for creating a server, I personally prefer node.
I assume that you’ve node, npm and Visual studio code already installed
For the specific requirements of this tutorial, we will create a Hello World node app following the steps below:
- Run
npm init
on a terminal and when asked for the package name Alexa
- Follow the terminal wizard
- Run
cd Alexa
- In the
package.json
file
Run npm i express http -save
and this will add the following entry in the package.json
file:
“dependencies”: {
“express”: “4.16.3”,
“http”: “0.0.0”
}
Set value to index.js
of the main key in the package.json
file
- Add a file
index.js
on same level
Àdd the following code to the index.js
file:
const express = require('express');
const app = express();
app.post('/', (req, res) =>
res.send({
version: '1.0',
response: {
shouldEndSession: false,
outputSpeech: {
type: 'SSML',
text: 'Hello World!',
ssml: 'Hello World!'
}
}
}));
app.listen(8080, () => console.log('Example app listening on port 8080!'));
Set value of scripts
to { “start”: “node index.js” }
- Run
npm start
on the terminal
Tunnel your localhost
Add a tunnel to the localhost on PORT 8080
running the node server using ngrok following the below steps:
- Download and install ngrok, if not already done
- Run
ngrok http 8080
on a terminal
- Copy the SSL enabled forwarded link, in my case https://6d0d6e60.ngrok.io is the SSL link
- provide the link in the Enter URL link
- Select HTTPS, and under SSL certificate type drop down select the 2nd option:
My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority
{
"interactionModel": {
"languageModel": {
"invocationName": "get me pizza",
"intents": [
{
"name": "PizzaOrderIntent",
"slots": [],
"samples": [
"Give me a pizza"
]
},
{
"name": "AMAZON.FallbackIntent",
"samples": [
"I didn't understand"
]
},
{
"name": "AMAZON.CancelIntent",
"samples": [
"cancel plz"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"help"
]
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
}
],
"types": []
}
}
}
- Click on Save Model and click on Build Model
Once, the skill model is build - we need to test it. Click on the Test tab and toggle ON the “Test is enabled for this skill”.
That’s it, you’ve created an Alexa bot connected to your locally running node project.
Questions? Comments? Do reach me at info@nordible.com
Read the full article