Bridge to connect Amazon Alexa to Api.ai using an AWS Lambda Function.
- Navigate to the Amazon Developer Portal. Sign in or create a free account.
- Select "Getting Started" under Alexa Skills Kit.
- Select "Add a New Skill".
- Select English (U.S.) as the Skill language.
- Select the Custom Interaction Model Skill type.
- Add the Name and the Invocation Name of the skill.
-
Use the next JSON as Intent Schema:
{ "intents": [ { "intent": "ApiIntent", "slots": [ { "name": "Text", "type": "AMAZON.LITERAL" } ] }, { "intent": "AMAZON.CancelIntent" }, { "intent": "AMAZON.StopIntent" } ] }
-
Create a Custom Slot Type:
- Type:
list_test
- Values:
test
- Type:
-
Use the next Sample Utterances:
ApiIntent {test|Text} ApiIntent {hello test|Text}
-
Copy the Alexa App Id (upper-left corner) to use it later in the Final Configuration section.
- Select AWS Lambda ARN (Amazon Resource Name) as Service Endpoint Type.
- Select Region depending on your Lambda region and paste your Lambda ANR into the Endpoint field when you have it.
- Log in to the Api.ai console.
- Create a new agent and fill all necessary information. Then click Save to continue.
-
Select Default Welcome Intent:
- Add
WELCOME
as a trigger Event. - Add or modify any text responses which will be triggered as the first welcome response.
- Add
-
Select Default Fallback Intent:
- Add
FALLBACK
as a trigger Event. - Add or modify any text responses which will be triggered if a user's input is not matched by any of the regular intents or enabled domains.
- Add
-
Create a new Intent called Default Bye Event:
- Add
BYE
as a trigger Event. - Add or modify any text responses which will be triggered as a goodbye response.
- Add
- Select the the gear icon (upper-left corner) and go to Settings.
- Copy your Developer access token to use it later in the Final Configuration section.
- If you do not already have an account on AWS, go to Amazon Web Services and create an account.
- Log in to the AWS Management Console and navigate to AWS Lambda.
- Click the region drop-down in the upper-right corner of the console and select either US East (N. Virginia) or EU (Ireland) (choosing the right region will guarantee lower latency).
- If you have no Lambda functions yet, click Get Started Now. Otherwise, click Create a Lambda Function.
- Select Blank Function as blueprint.
- When prompted to Configure Triggers, click the box and select Alexa Skills Kit, then click Next.
-
Enter a Name and choose Node.js 4.x as the Runtime.
- Download the
AlexaApiAiBridge.zip
file from the latest release of this repo. - Drop down the Code entry type menu and select Upload a .ZIP file.
- Click on the Function package upload button and choose the file you just downloaded.
- Set your handler and role as follows:
- Keep Handler as ‘index.handler’.
- Drop down the Role menu and select “Create a new custom role”. This will launch a new tab in the IAM Management Console. (Note: if you have already used Lambda you may already have a
lambda_basic_execution
role created that you can use.) - You will be asked to set up your Identity and Access Management or “IAM” role if you have not done so. AWS Identity and Access Management (IAM) enables you to securely control access to AWS services and resources for your users. Using IAM, you can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources. We need to create a role that allows our skill to invoke this Lambda function. In the Role Summary section, select "Create a new IAM Role" from the IAM Role dropdown menu. The Role Name and policy document will automatically populate.
- Select “Allow” in the lower right corner and you will be returned to your Lambda function.
- Keep the Advanced settings as default and select ‘Next’.
- Download the
- Review the lambda details and select ‘Create Function’.
-
Copy the Lambda ARN (upper-right corner) and use in the Alexa Skill Configuration section.
-
Go to your Lambda Code tab.
-
Replace
ALEXA_APP_ID
with your Alexa App Id andAPIAI_DEVELOPER_ACCESS_TOKEN
with your Api.ai Developer Access Token:const ALEXA_APP_ID = 'amzn1.ask.skill.app.your-skill-id'; const APIAI_DEVELOPER_ACCESS_TOKEN = 'your-apiai-developer-access-token';
-
Go to Alexa Manager and change the language of your device to English (United States) inside the Settings menu.
- Your device and the Alexa Skills has to use English (United States) language because it's the only way to use LITERAL slot types to recognize words without converting them.
- The Lambda region has to be either US East (N. Virginia) or EU (Ireland) because those are the only two regions currently supported for Alexa skill development on AWS Lambda.