Alexa Skills Kit (ASK) SDK for Node.js
repository·2.0.x·Indexed 25 days ago
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejsA high-level framework for building Alexa skills that abstracts JSON request/response models into TypeScript/JavaScript classes. The SDK includes core modules (ask-sdk-core, ask-sdk-model), persistence adapters for DynamoDB and S3, an Express adapter for custom web services, and tools for local debugging and SMAPI integration.
What's inside alexa-skills-kit-sdk-for-nodejs
- The ASK SDK Controls framework is a beta extension built on top of the ASK SDK for Node.js. It provides a scalable solution for developing large, multi-turn Alexa skills by using reusable components known as controls.
Overview of Alexa Skills Kit SDK for Node.js
2.0.xThe ASK SDK v2 for Node.js is designed to simplify the development of highly engaging Alexa skills by reducing boilerplate code. It allows developers to focus on implementing features rather than handling low-level request/response logic.
Key components include:
- ASK SDK v2: The standard distribution for building skills.
- ASK SDK Controls Framework (Beta): A scalable solution for large, multi-turn skills using reusable components called controls.
- ASK SMAPI SDK: A library for interacting with Skill Management APIs (SMAPI), including interaction models, intent request history, and in-skill purchasing APIs.
Supported Alexa Features in ASK SDK v2 for Node.js
2.0.xThe ASK SDK v2 for Node.js supports a wide range of Alexa features, including:
- Payments & Monetization: Amazon Pay and Monetization.
- Media & Display: Audio Player, Video, and Display (Body templates for screen devices).
- Interactions: Dialog Management, Entity Resolution, Dynamic Entity, and Name-free Interactions (Preview).
- Services & APIs: Directive Service (Progressive Response), Messaging, Reminders, Location Services, and Alexa Settings API.
- User Data & Identity: Account Linking, Device Address, Lists (Shopping and To-Do), and Request for customer contact information.
- Hardware: Gadgets Game Engine (Echo Buttons).
Note: Some features like Connections and Alexa Presentation Language (APL) are currently in Public Preview and their interfaces may change in future releases.
Understand the SDK Model Architecture
2.0.xThe SDK operates using model classes instead of raw Alexa JSON requests and responses. These model classes are generated from the official Request and Response JSON schemas. This abstraction allows you to work with typed objects rather than manually parsing JSON.Getting Started with the ASK SDK
2.0.xTo begin using the ASK SDK v2 for Node.js, you can follow these primary guides:
- Setting Up The ASK SDK: Instructions for installing the SDK as a dependency in your NPM project.
- Developing Your First Skill: A step-by-step walkthrough for building a 'Hello World' sample skill.
- ASK SDK Migration Guide: Instructions for migrating existing Alexa skills from SDK v1 to SDK v2.
Install the ASK SDK Express Adapter
2.0.xThe
ask-sdk-express-adapteris an addon package for the core SDK (ask-sdk-core). You must install both the core SDK and the adapter as peer dependencies in your NPM project.npm install --save ask-sdk-core npm install --save ask-sdk-express-adapterInstall the ASK SDK DynamoDB Persistence Adapter
2.0.xThe
ask-sdk-dynamodb-persistence-adapteris an add-on package for the core SDK (ask-sdk-core). Because it is an add-on, you must install both the core SDK and the adapter in your NPM project. Run the following commands in your terminal:npm install --save ask-sdk-core npm install --save ask-sdk-dynamodb-persistence-adapterTechnical Documentation Overview
2.0.xThe ASK SDK provides several core technical capabilities for skill development:
- Processing Request: Learn how to build request handlers, exception handlers, and request/response interceptors.
- Building Response: Use the
ResponseBuilderto compose text, cards, and audio into a single response. - Managing Attributes: Store and retrieve skill data using skill attributes.
- Calling Alexa Service APIs: Use service clients to access various Alexa APIs.
- Configuring Skill Instance: Learn how to configure and construct a skill instance.
- ASK SDK Utilities: Use utility functions provided by the SDK.
Explore Alexa Skill Samples
2.0.xThe repository provides several sample projects to demonstrate different implementation patterns:
- Basic/Hello World: Hello World and Hello World (Controls framework).
- Games: Trivia, Quiz Game, High Low Game, and Decision Tree.
- Templates: Fact (random facts), How To (parameter-based instructions), and City Guide (recommendations).
- Advanced/Specialized: Fruit Shop (Controls framework) (multi-modal shopping), Device Address API, and Audio Player.
Generate an Access Token using ASK CLI
2.0.xTo use the local debugging service, you need an access token generated via the ASK CLI.
- Install ASK CLI v2:
npm install ask-cli@2 -g. - Run the following command to generate LWA tokens with the required scope:
ask util generate-lwa-tokens --scopes alexa::ask:skills:debug - Follow the 'Login with Amazon' prompts in your browser. Retrieve the
ACCESS_TOKENfrom your terminal after signing in.
ask util generate-lwa-tokens --scopes alexa::ask:skills:debug- Install ASK CLI v2:
Use ASK SDK Runtime with TypeScript
2.0.xThe
ask-sdk-runtimepackage bundles TypeScript definition files. To use them, ensure your project meets these requirements:- Use TypeScript v2.x or higher.
- Install TypeScript definitions for Node.js using
@types/node.
To use the definitions in a TypeScript file, import the package as follows:
import * as Runtime from 'ask-sdk-runtime';Use the ASK SDK with TypeScript
2.0.xThe
ask-sdkpackage bundles TypeScript definition files. To use them in a TypeScript project, ensure you meet the following prerequisites:- Use TypeScript v2.x or higher.
- Include TypeScript definitions for Node.js by installing
@types/node.
Import the SDK in your TypeScript files using the following syntax:
import * as Alexa from 'ask-sdk';