How to Create an Alexa Skill to Manage Your To-Do Lists

As a busy software engineer, I‘m always looking for ways to improve my productivity and organization. Recently I‘ve been exploring how to leverage voice assistants like Alexa to manage my daily to-do lists hands-free. It turns out Alexa provides a robust set of features to build custom skills for to-do list tracking.

In this guide, I‘ll walk through how to create your own Alexa skill to manage to-do lists, including:

  • An overview of the architecture and components involved
  • Step-by-step instructions for setting up the skill
  • Best practices for designing effective voice interactions
  • How to publish the skill so others can use it

By the end, you‘ll have all the knowledge you need to build a fully-functional Alexa to-do list skill. Let‘s get started!

Architecture Overview

There are a few key components that work together to power a custom Alexa skill:

Alexa Skills Kit (ASK): This is the framework provided by Amazon for creating Alexa skills. It includes the tools, APIs, and documentation for building and publishing Alexa skills.

AWS Lambda: Alexa skills are cloud-based applications that run on AWS Lambda, Amazon‘s serverless compute platform. You provide the code for your skill as a Lambda function.

DynamoDB: For our to-do list skill, we‘ll use Amazon DynamoDB, a NoSQL database service, to store and retrieve the user‘s list data.

Here‘s a high-level diagram of how these components fit together:

Diagram of Alexa to-do list skill architecture

The user interacts with the skill through an Alexa-enabled device like an Echo. Their voice input is sent to the Alexa cloud platform, which interprets the speech and triggers the appropriate intent in your skill‘s backend Lambda function.

The Lambda contains the core logic for processing the intents and generating responses back to the user. It also handles reading and writing list data to the DynamoDB database.

Now that we understand the overall architecture, let‘s walk through the process of actually building the skill.

Setting Up the Alexa Skill

All Alexa skills start in the Alexa Developer Console. Here you configure the skill‘s invocation name, interaction model, and other key settings.

Step 1: Create a new skill
From the Alexa Developer Console, click "Create Skill". Choose a name for your skill (I called mine "My To-Do List") and select "Custom" as the model. Choose "Provision your own" for the backend resources and click "Create skill".

Step 2: Set up the interaction model
The interaction model defines how users interact with your skill through voice. It includes:

  • Invocation name: This is the name users say to invoke your skill. I set mine to "my to do list".

  • Intents: Intents represent the actions users can take in your skill. For our to-do list skill, we‘ll need intents for creating a new list, adding an item to a list, reading the items on a list, and deleting a list.

  • Sample utterances: For each intent, you provide sample phrases for how a user might express that intent. For example, "create a new list called {ListName}" or "add {Item} to my {ListName} list."

  • Slots: Slots are variables within the sample utterances that capture user-specified data, like the name of a list or item to add to a list.

Here are the intents, utterances, and slots I configured for the to-do list skill:

CreateListIntent create a new list called {ListName}
                 start a list named {ListName}
                 make a new list for {ListName}

AddItemIntent    add {Item} to my {ListName} list  
                put {Item} on the {ListName} list

ReadListIntent   read my {ListName} list
                 what‘s on my {ListName} list

DeleteListIntent delete my {ListName} list
                 remove the {ListName} list

AMAZON.HelpIntent help
                  assistance
                  how do I use this

AMAZON.CancelIntent cancel
                    nevermind  

AMAZON.StopIntent stop
                  off

{ListName} // Slot Type: AMAZON.SearchQuery  
{Item}     // Slot Type: AMAZON.SearchQuery

Configure these intents, utterances, and slots in the JSON Editor under the Interaction Model tab.

Step 3: Write the Lambda Function
Next we need to write the code that will process these intents and handle the list management logic. From the sidebar menu, go to "Code" and select "Create Lambda Function" to create a new function from a blueprint.

For the function code, use the Alexa Skills Kit SDK for Node.js. Here‘s a basic outline to get started:

const Alexa = require(‘ask-sdk-core‘);

const CreateListIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === ‘IntentRequest‘
      && handlerInput.requestEnvelope.request.intent.name === ‘CreateListIntent‘;
  },
  async handle(handlerInput) {
    const listName = handlerInput.requestEnvelope.request.intent.slots.ListName.value;

    // TODO: Create a new list with the given name in DynamoDB

    const speechText = `Ok, I created a new list called ${listName}.`;
    return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
  }
};

// ... Other intent handlers for AddItemIntent, ReadListIntent, etc ...

exports.handler = Alexa.SkillBuilders.custom()
  .addRequestHandlers(
    CreateListIntentHandler,
    AddItemIntentHandler,
    ReadListIntentHandler,
    DeleteListIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
  )
  .addErrorHandlers(ErrorHandler)
  .lambda();

This code defines handlers for each intent that will process the user‘s request and generate a response. The handlers use the Alexa Skills Kit SDK to parse the incoming request and construct responses.

The actual logic for creating, reading, and deleting lists will be done through the DynamoDB DocumentClient. You‘ll need to require the aws-sdk module and initialize the DynamoDB client:

const AWS = require(‘aws-sdk‘);
const docClient = new AWS.DynamoDB.DocumentClient();

Then within each intent handler, you can call DynamoDB methods like put, get, and delete to interact with the list data. For example, when handling the CreateListIntent:

async handle(handlerInput) {
  const listName = handlerInput.requestEnvelope.request.intent.slots.ListName.value;

  const params = {
    TableName: ‘ToDo-Lists‘,
    Item: {
      ‘userId‘: handlerInput.requestEnvelope.session.user.userId,
      ‘listName‘: listName,
      ‘items‘: []
    }
  };

  await docClient.put(params).promise();

  const speechText = `Ok, I created a new list called ${listName}.`;
  return handlerInput.responseBuilder
    .speak(speechText)
    .getResponse();
}

This code takes the list name provided by the user, creates a new item in DynamoDB to represent the list, and generates a response confirming the new list was created.

The other intent handlers will work similarly, querying and manipulating list data in DynamoDB and generating appropriate voice responses using the Alexa Skills Kit response builder.

Be sure to also implement handlers for built-in intents like AMAZON.HelpIntent to provide instructions for using the skill.

Step 4: Enable List Permissions
Since the to-do list data is private to each user, you need to enable List Read/Write permissions for your skill so it can store this data securely.

In the Alexa Developer Console under "Permissions", enable the toggle for Lists Read and Lists Write. Then under "Consent", provide a suitable privacy policy explaining how you will use the user‘s list data.

The user will need to grant these permissions through the Alexa app before using the skill.

Step 5: Test and Publish
Once your interaction model and Lambda function are complete, it‘s time to test the skill out using the Test tab in the developer console. Here you can simulate requests and see the full request/response JSON to help debug any issues.

When you‘re ready to publish, go to the "Distribution" tab and fill out all the required metadata about your skill – description, example phrases, keywords, icons, etc. Once everything looks good, click "Submit for certification".

The Amazon certification team will review the skill and provide feedback if any changes are needed before approving it for publication.

Designing Voice-First Interactions

Compared to traditional GUI-based apps, voice interaction requires a different mindset and flow. Here are a few best practices to keep in mind when designing your Alexa skill:

Keep interactions brief and to-the-point. Voice interactions should be quick and focused on accomplishing the user‘s goal. Avoid long, open-ended prompts.

Offer contextual help. First-time users will need guidance on how to use the skill. Implement a robust help intent and offer tips if the user seems stuck or confused.

Confirm destructive actions. Before performing an action like deleting a list, ask the user to confirm their intent.

Let users review and edit. After collecting a set of information (like the list name and items to add), allow the user to review and make corrections before confirming.

Gracefully handle errors. Use try/catch and .catch() reject handlers to handle any errors that occur within intent handlers. Provide helpful error messages to the user.

By keeping these tips in mind, you can craft a natural, frictionless voice experience for your Alexa skill.

Conclusion

Congrats! You now have all the knowledge needed to build your own Alexa skill for managing to-do lists. As you can see, the Alexa Skills Kit provides a powerful set of tools for creating engaging voice experiences.

Building an Alexa to-do list skill is a great way to become familiar with the core concepts and workflow behind Alexa skill development – defining an interaction model, wiring up a Lambda function, integrating with backend services like DynamoDB, designing for voice interaction, and publishing a finished skill.

To dive deeper, check out these additional resources:

I hope this guide has inspired you to start building your own Alexa skills. With a little creativity and coding skills, the possibilities are endless. Happy building!

Similar Posts