Turning your chatbot into an Alexa skill: a step-by-step 1 hour tutorial

More and more chatbots are being created every day, basically covering every automatable use case. Most of these chatbots are textual, we can discuss with them either on Messenger, SMS, website chat, etc. They’re very accessible and easy to use, but I’m sure you’d love to be able to speak to them as well as write to them. Sometimes, speaking is the most natural and easiest way to interact, say when you’re at home cooking or reading. I’ve got some news for you: you can build your own Alexa bot backed by Recast.AI! Why would you do that? Well, Recast.AI’s language technology allows you to build a skill in any language much faster than any other provider. It’s a great solution to become a master bot maker and pimp your home.

A simple but very useful use case is the banking assistant. Wouldn’t it be marvellous if you could manage your daily finances directly by speaking with your banking assistant?

In this article, I’ll explain how you can create your own Alexa bot, powered by Recast.AI’s NLP, like you’ve seen above.

Deep dive

To begin, you’ll need your bank to have API endpoints to have a real integration but others use cases follow the same pattern.

Here is the global design of our project:

  1. Login or create an account on the Amazon Developer console: https://developer.amazon.com
  2. Go to the “Alexa” tab and click on “Get started” under “Alexa skills”, then “Add a new skill”

Skill configuration

Now let’s configure each tab:

Skill information tab

Under the “Skill information” tab, fill in the information as shown below:

Interaction model tab

Now, the most important tab, the interaction model. Amazon doesn’t allow us to get the user’s input, so we have to use a little trick. We’ll configure a slot (an entity) matching all the user’s input.
 To do this, enter this JSON configuration in the “Intent Schema” text area:

{
"intents": [
{
"slots": [
{
"name": "sentence",
"type": "AMAZON.LITERAL"
}
],
"intent": "SaySomething"
}
]
}

In “Sample Utterance”, enter this example which matches the whole input:

SaySomething {do something | sentence}

Configuration tab

Next, the “Configuration” tab. If you’ve mastered lambda, you can configure your lambda endpoint here directly, but to make things as generic as possible, we’ll use a simple https endpoint using ngrok.

To do so, install ngrok and create a tunnel (we’ll add the code server later) :

ngrok http 3000

Enter the https url provided by ngrok in the “Default” input.

Leave other configurations with default values.

SSL certificate tab

An “SSL certificate” tab should have appeared. Select “My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority”. This way, we tell Amazon to let us (ngrok) manage the SSL certificate.

Test tab

Now we can test it by entering a sample utterance. We won’t get any response from our bot because we haven’t configured it, but we can see the JSON sent by Amazon to our bot. The whole sentence is in the slot “sentence”.

Publishing information and Privacy & Compliance tabs

You won’t need these details until you want to deploy your Alexa bot to the world.

Alexa configuration

If you have an Alexa device under the same account as your Amazon developer account, you can integrate your skill into Alexa.

Note: The following steps come from the Amazon help page: https://developer.amazon.com/docs/custom-skills/test-a-custom-skill.html#h2_register.

To integrate your skill, go to the Alexa configuration page. This is the web versions of the mobile Alexa app. Once logged in, go to the Skills tab, and click on “Your skills” in the top right corner. You should see your newly created skill. Click on it and check that it’s enabled for your Alexa.

At this point, you should be able to ask Alexa to open your skill using your invocation name configured in the “Skill information” tab. For instance: “Alexa, open banking assistant.”. Alexa should understand the skill and reply with an error (“There was a problem with the requested skill response”). That’s normal, as we haven’t configured our bot yet, but it shows Alexa is now aware of the skill! Well done.

Bot configuration

First, create a bot on Recast.AI. If you haven’t used Recast.AI in the past, this tutorial will explain how to create a bot easily.

You can also fork a sample banking chatbot here.

Now that we have a trained bot, we have to code the integration between Alexa and Recast.AI. You can use this code, which is an adaptation of Recast.AI’s starter kit.

Once cloned, simply run this command:

REQUEST_TOKEN=xxxxxxxxxx node server.js.

This will start a server on port 3000, to which ngrok will send Alexa’s requests.

You should now be able to talk to Alexa, invoking your skill and talking with it, as defined in your Recast.AI Bot Builder.

Next steps

Congrats! You now have a talking Alexa chatbot, backed by Recast.AI’s NLP. You can now start customizing your use case and the code. It’s simple and well commented so it should be easy to work with.

When you’re ready for production or if you wish to have your bot always up, deploy it to a custom server or to a lambda, either using Bot Hosting or the Alexa integration in the “Configuration tab.”

Finally, to submit your skill and make it available to every Alexa owner, follow the instructions on the “Publishing Information” and “Privacy & Compliance” tabs.

That’s it, you know everything! Enjoy experimenting and feel free to come and discuss it on our Slack Community. Cheers!


Originally published at Recast.AI Blog.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.