12/9/2018 Webmaster

Creating An Alexa Bot Using The Microsoft Bot Framework


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)

An error has occurred. This application may no longer respond until reloaded. Reload 🗙