Creating An Alexa Bot Using The Microsoft Bot Framework

Dec 9

Written by:
12/9/2018 2:23 PM  RssIcon

image

One of the main reasons you would desire to use the Microsoft Bot Framework for your Chat Bot is that it automatically exposes your Bot to many channels… except Amazon Alexa.

If you desire to add support for Amazon Alexa, you will have to use custom code. The open source project, Bot Builder Community - .NET Extensions has recently added an Alexa Adapter middleware that makes integration easy. They even created a Sample to get you started.

To complete this tutorial you will need the following:

 

Get The Sample Code

image

The sample code is located at: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/master/samples/Alexa%20Adapter%20Sample.

image

However, to get to it, go to: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet and download it as a .zip file.

image

Unzip the code.

image

Navigate to ../botbuilder-community-dotnet-master\botbuilder-community-dotnet-master\samples\Alexa Adapter Sample and open the Alexa Adapter Sample.csproj file in Visual Studio.

image

The project will open in Visual Studio.

Rebuild the Solution.

The code will currently repeat whatever is sent to it. After you get it working, you would come back and alter this code.

Deploy To Azure

image

Right-click on the project node and select Publish.

image

Follow the directions in the article:

Creating a Hello World! Bot (MS Bot Framework V4)

to publish the bot and Connect The Bot To The Azure Bot Service.

image

You will now have an App Service and a Bot Channels Registration.

image

Note the URL of your App Service.

You will need to point the Alexa Skill (to be created in later steps), to the URL with /api/skillrequests added to it.

For example: https://alexaadaptersample.azurewebsites.net/api/skillrequests

Create The Alexa Skill

image

Note: All the steps we will now do are also covered on the GitHub page for the sample code at: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/master/samples/Alexa%20Adapter%20Sample.

Go to: https://developer.amazon.com/alexa and click Sign In (Note: If you need to, you can also create a new account by clicking the Sign In link).

Note: If you want to test this on an actual Amazon Alexa device, you must log in using the account that the Alexa device is registered under.

image

Next, go to: https://developer.amazon.com/alexa/console/ask and click Create Skill.

image

Give the skill an original two word name, select Custom for the model, and click Create skill.

image

For template, choose Start from scratch.

Click the Choose button.

image

Choose JSON Editor.

image

Open another web browser, and go to: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/master/samples/Alexa%20Adapter%20Sample and copy the JSON example on that page.

image

Return to the web browser that has the Amazon Alexa portal opened and…

  1. Paste the JSON into the box
  2. Change the invocationName to the name of your Alexa skill
  3. Click Save Model
  4. Click Build Model

image

The Model will build.

image

When the build is complete:

  1. Click Endpoint.
  2. Select HTTPS to indicate we will host the code on our own server (on Microsoft Azure)
  3. Enter the address of the Azure App Service URL with /api/skillrequests added to it (for example: https://alexaadaptersample.azurewebsites.net/api/skillrequests).
  4. In the dropdown select: My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority (this is the second option in the dropdown).

 

image

At the top of the page, click Save Endpoints.

image

  1. Click Invocation
  2. Click Save Model
  3. Click Build Model

Wait until the build is complete.

Test It Out

image

Click the Test tab.

Click the slide to enable testing for the skill.

image

Now you can enter a message in the box and press enter.

You will see the response in the chat window.

If your skill is called adapter sample and the invocation name was also set as adapter sample, you would enter:

alexa launch adapter sample

and press Enter.

Alexa will indicate, in the chat window, that the skill has been launched.

You can then enter:

alexa ask adapter sample hello from AiHelpWebsite

and press Enter.

image

The Microsoft Bot Framework code, running in Microsoft Azure, will repeat back whatever you send it.

image

You can now interact with the Alexa Skill with any Alexa device that is registered to the developer account the Alexa Skill is created under.

image

To distribute the Alexa Skill to others, click the Distribution link in the Alexa developer console and follow the directions there.

 

Troubleshooting

image

An Alexa Skill needs a response within 8 seconds, so if your web app (on Azure) has gone to sleep, the first request may fail while it wakes up. To prevent this, enable always on.

Also, ensure you are just invoking the skill in a way that Alexa will recognize. For example, instead of saying "Alexa invoke”,  use "Alexa launch".  You can also use a phase such as "Alexa tell adapter sample hello world" to call it.

 

The Man Who Made This Happen

I’m just  documenting the process. Gary Pretty created the code and literally had to jump into my Amazon Developer account to fix my configuration issues.

You can connect with him through Twitter:

image

https://twitter.com/GaryPretty

 

Links

Bot Builder Community - .NET Extensions

Alexa Adapter

Amazon Alexa Developer Site

Manage Amazon Alexa Skills in the Developer Console

Microsoft Bot Framework

Creating a Hello World! Bot (MS Bot Framework V4)

5 comment(s) so far...


Gravatar

Re: Creating An Alexa Bot Using The Microsoft Bot Framework

Hello,

The article is really great. Can you also share a blog where we can integrate it with Google home and BOt framework.

By Siddharth on   2/7/2019 12:51 PM
Gravatar

Re: Creating An Alexa Bot Using The Microsoft Bot Framework

I followed all the steps in the blog, but for me it throws error like there was aproblem with the requested skill response. I had one question. if you give endpoint alexaadaptersample.azurewebsites.net/api/skillrequests but there is not mention anything in the bot, Do we need to give the end point in .bot file. What about the Direct line secret ? how can we integrate that ?

By Siddharth on   2/7/2019 1:23 PM
Gravatar

Re: Creating An Alexa Bot Using The Microsoft Bot Framework

@Siddharth - You will want to reach out to Gary Pretty (see link in the article) if you have further questions on Alexa configuration and integration. Thanks!

By Administrator on   2/7/2019 1:54 PM
Gravatar

Re: Creating An Alexa Bot Using The Microsoft Bot Framework

I have been integrating the enterprise Bot template with Alexa over voice. My only concern with Alexa is how to authenticate the user via voice on Alexa. I thought of the idea of passwordless authentication but still it popups an SOS window to authenticate. Do you have any suggestion on how I can come up with a solution for it? Because to authenticate a user in Azure tenant via voice is something I am looking for. Is it even possible to authenticate via voice to do that? because via webchat it is possible to do passwordless authentication but not over voice.

By Siddharth on   3/5/2019 3:04 PM
Gravatar

Re: Creating An Alexa Bot Using The Microsoft Bot Framework

@Siddharth - Wow you are pretty advanced. I just heard about the Azure voice verification only yesterday :) Gary Pretty (see link in the article) is the number one person I would consult for what you need.

By Administrator on   3/5/2019 6:11 PM