Connect Your Own AI Chatbot to Amazon Alexa
Learn how to connect your chatbot to Alexa.
Join the DZone community and get the full member experience.
Join For FreeMore and more chatbots are being created every day, basically covering every automatable use case. Most of these chatbots are textual, and we can interact with them 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 SAP Conversational AI. We made this integration very easy, so let’s dive in, step-by-step.
1. Create Your Bot
For the purpose of this Alexa integration with SAP Conversational AI, we’ll make it easy and use one of our previously created bots: the “joke bot.” This bot simply returns some random good jokes when you ask!
Once you’ve created your bot and you’re happy with it, return here and we’ll go to Step 2.
2. Add a Dedicated Intent and Skill
As we’ll see later, your Amazon Skill will be triggered by using an “invocation” (aka a “keyword”). Using this invocation will start the bot and tell Alexa to go to SAP Conversational AI to handle the conversation. Then, we have to tell your bot how to properly react when the user uses the invocation. If not, your Alexa skill will still work, but it won’t know what to answer and will ask for the Fallback skill, which can be very disappointing for the user.
For that, we’ll create an intent and a skill (or, in this particular case, modify an existing skill).
a. Go to the Train tab and click +CREATE. I chose to name my intent conversation-start, but you can choose whatever you want.
In this intent, we’ll add a single expression: CONVERSATION_START. This time, don’t use anything but this specific expression. This expression is what Alexa considers the beginning of the conversation with your bot, once you’ve called the “invocation.”
b. You can create a specific skill to handle the answer of the CONVERSATION_START trigger, but I chose something simpler: the Greetings skill that you already have in your joke bot. The result is that Alexa will answer with a greeting message when using your invocation: “Start funny bot” > “Hello :)”.
On your Build tab, choose the skill Greetings, and go to the Trigger tab. Add a condition with an OR boolean and simply choose “if @conversation-start is present.”
Once you’ve done that, go to the Actions tab and add a condition to the first action, with an OR boolean, and again type “if @conversation-start is present.”
With that done, your bot will use the Greetings when prompting the invocation, as if you were simply greeting it.
This is the only modification you’ll have to do to make your bot Alexa-compatible.
3. Create an Amazon Alexa Developer Account
If you already have an Amazon Alexa developer account, nothing more to do! Just log in. If not, go here and create one. It’s completely free!
Once you’ve created an account, don’t create a skill through the Amazon platform. We handle itfor you through your bot’s Connect tab.
4. Authorize Amazon to Connect to Your SAP Conversational AI
Go to the Connect tab of your bot and click Amazon Alexa. Go to Step 6 (under Amazon Alexa on the Connect tab) and click LOGIN WITH AMAZON. Once you’ve done that, you won’t have to go back to this action.
5. Choose an Invocation Name and Generate Your Alexa Skill
We’re almost done!
Under Amazon Alexa on the Connect tab, stay on Step 6 and choose a name for your Alexa skill. Feel free to personalize it.
Choose an invocation name. As I was previously saying, this is the “magic” word that will make Alexa switch to your SAP Conversational AI bot. I chose funnybot. Note that you can change it later, so don’t worry if you made a mistake!
Once you’ve chosen an invocation name, click the CREATE CHANNEL button and wait. The system will take a few seconds to reload and then the Vendor and Locales lists will be available.
Choose the unique option in the Vendor list and choose US in the Locales list. Then click DEPLOY SKILL TO AMAZON ALEXA.
There we are! Connection’s done!
6. Test Your Skill on Alexa
Go to your Amazon Alexa dev page and refresh the page. Your skill will now appear! Click on your skill’s name and go to the Test tab.
In the Skill testing is enabled in: field at the top left, choose Development to enable the testing window.
Time to Test!
Try prompting “Start funnybot.” The skill will answer with a greeting answer. Once you’ve done that, you can follow your conversation as if you were using your bot in another context (test chat, webchat, Messenger, etc.). Type “Can you tell me a joke?” and see what happens!
Of course, you can mix both messages and directly ask Alexa “Ask funnybot to tell me a joke”. Again, the most important thing is having the invocation keyword in your sentence.
If you change something in your bot, you don’t have to “rebuild” your Alexa connection. Just refresh the Test page and start a new conversation. Don’t forget to use your invocation before any questions to your bot.
Next Steps
Congrats! You now have a talking Alexa chatbot, backed by SAP Conversational AI.
When you’re ready for production and to make your skill available to every Alexa owner, follow the instructions on your Amazon Alexa dev page on the Distribution tab.
That’s it, you know everything! Enjoy experimenting, and remember, you’re very welcome to contact us if you need help, through the comment section below, via Slack, or using our dedicated tag on StackOverflow.
Published at DZone with permission of Paul Pinard. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments