Simon A. Kingaby

Data-Driven Alexa Skills

Voice Access to Rich Data Sources for Enterprise Applications

1st ed.
Simon A. Kingaby
La Vergne, TN, USA
ISBN 978-1-4842-7448-4e-ISBN 978-1-4842-7449-1
© Simon A. Kingaby 2022
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.

The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.

This book is dedicated to all who have caught or want to catch the vision of ambient computing.

Introduction

Welcome to the wonderful world of data-driven Alexa skills. Come along as we take a journey beyond the typical Hello World examples and design and build innovative, custom, data-driven Alexa skills for your home or business that integrate Alexa with online APIs, rich data sources, and powerful applications. If you have basic Python skills, this book will show you how to build data-driven Alexa skills. You will learn to use data to give your Alexa skills dynamic intelligence, in-depth knowledge, and the ability to remember.

Data-driven Alexa Skills takes a step-by-step approach to skill development. You will begin by configuring a skill in the Alexa Skill Builder Console. Then you will develop an advanced custom skill that uses the latest Alexa Skill Development Kit features to integrate with lambda functions, Amazon Web Services (AWS), and Internet data feeds. These skills enable you to link user accounts, query and store data using a NoSQL database, and access stock prices and more via web APIs.

What you learn from this book will help you to integrate Alexa with software-as-a-service and platform-as-a-service applications and environments such as Salesforce, ServiceNow, Microsoft Azure, and AWS.

This book is for the next generation of Alexa skill developers who want to use data to make Alexa smarter, more relevant, and more helpful. To move closer to the goal of ambient computing, Alexa will need to access and combine data from many sources in many ways. If you imagine the day when Alexa can intelligently manage your email, the day when she can reconcile your schedules from Outlook, Google, Apple, and Calendly, the day when you can ask her to tell you your net worth, or the day when you can ask her to log a ticket in ServiceNow, this book is for you.

Part I: Getting Started

In this first part of the book, we will introduce you to voice user interface development. Then we will build a Routine and a couple of Alexa skills from Blueprints. Then we set up some accounts you will need so that you can develop Alexa skills. Now you are ready to create a skill, starting with creating an Alexa Conversations voice user interface, followed by coding and testing the back end in Python and VS Code. In the last chapter of Part I, you will publish your new skill to the Alexa Skills Store!

Chapter 1: Voice User Interfaces

An introduction to the world of voice user interface development. Chapter 1 includes a brief history of voice development leading up to today’s voice landscape. It also answers the questions: Why voice? Why Alexa? Why now?

Chapter 2: Routines and Blueprints

The easiest way to create new skills for Alexa is with Routines and Blueprints. This chapter walks you through the process of creating these no-code skills.

Chapter 3: The Developer Accounts

You will need to create and configure a lot of accounts to develop Alexa skills. This chapter guides you through the creation of these accounts.

Chapter 4: Creating the VUI for a Custom Data-Driven Skill

Now that the accounts are set up, we’re ready to create the base Alexa skill. For the remainder of Part I, we will create a Body Mass Index skill. In this chapter, we configure the voice user interface, including the conversational dialog, the user utterances, the slot values, and Alexa’s responses.

Chapter 5: Writing the Back-End Code

With the VUI created, we’re ready to write some code. Of course, you will need to install the tools, including VS Code and Anaconda, among others. Chapter 5 lists the tools you’ll need and where to find them on the Internet. Then it walks you through configuring an Anaconda environment for Python development. Next, we create the back-end code for the BMI Alexa skill. We end the chapter by testing our code.

Chapter 6: Publishing an Alexa Skill

After creating the VUI in Chapter 4 and coding the back-end in Chapter 5, you will be ready to publish your new Alexa skill to the Alexa Skills Store. By the end of Chapter 6, you will have done just that!

Part II: Custom Skill Development

After creating your first skill in Part I, we take a deep dive into many of the components of the skill development process. Building a 90-year calendar skill, we will cover the Alexa Interaction Model including Intents, Slots, and Utterances. We will use the Alexa Presentation Language to draw the 90-year calendar on devices with screens. We’ll use account linking to allow us to gather the events of your life safely and securely. We’ll create a custom lambda function – the brains of our skill. Lastly, we use a DynamoDb persistence layer to store your information so that Alexa remembers you.

Chapter 7: Custom Alexa Skills

Now that you’ve created an Alexa-hosted skill in Part I, we are ready to create a fully custom skill and see how to use some of the more advanced features of the Amazon Web Services (AWS) cloud as your Alexa skill back end. You’ll need some AWS accounts and services to get started.

Chapter 8: Beyond Hello World

With the accounts set up and the basic requirements defined, we’re ready to design the voice user interface. Dialog design is notoriously difficult, but there are tools, like Botmock, that make it much easier. In this chapter, we lay out the dialog for the 90-year calendar skill.

Chapter 9: Configuring the VUI

After designing the dialog in Botmock, we are ready to transfer the design into a new Alexa skill.

Chapter 10: Using APL to Present on Screens

With the dialog sorted out, the next step is to create the visualization for Alexa devices with screens. For this, we need to use the Alexa Presentation Language, which is covered in Chapter 10.

Chapter 11: Coding the Lambda Function

Now that the VUI and the APL have been created and written, we can write the back-end code. For this, we will use a fully custom lambda function. We will build out the intent handlers, do the math to draw the calendar, and create the dataset to bind to the APL template.

Chapter 12: Unit Testing an Alexa Skill

With the code written, we should probably do some testing. In Chapter 12, we look at several ways to test the intent handlers and Alexa’s responses. These include unit testing the code in the lambda function and in VS Code, as well as testing Alexa’s natural language understanding and automated speech recognition.

Chapter 13: Storing the Data

With the skill working as designed, we are ready to take it to the next level by capturing the events of your life. This will be done with account linking to ensure that the data is safely and securely stored in a DynamoDB NoSQL database. The chapter ends with some suggestions for next steps to build out the remainder of the 90-year calendar skill.

Part III: Using APIs in Advanced Skills

Now that you’ve learned how to create Alexa skills, we will begin working with Application Programming Interfaces (APIs). These are a common way of gathering data over the Internet. We will use two APIs in particular to build a Personal Net Worth skill that will tell you the value of your home and investments. Of course, such a skill will have its hands on some of your personal data, but all that data will be safely ensconced in a secured database and encrypted for your protection. In all cases, you will have the option of using a test account for development purposes, so no REAL data need be involved at all.

Chapter 14: A Personal Net Worth Skill

Imagine Alexa being able to tell you your net worth. By using account linking and DynamoDB, we can safely store your personal data. In this chapter, we flesh out the VUI and work out the back-end lambda function. But once we have the dialog model sorted out, how do we get the value of your assets? The answer is found on the Web using APIs.

Chapter 15: The Real Estate API

Using a website named Rapid API, we find several APIs that can price our homes. Realty Mole stands out with its Sales Price Estimator. In this chapter, we figure out how to get the price of your home using the address we gave to Alexa in Chapter 14.

Chapter 16: The Stock Market API

After selecting one of the hundreds of stock price APIs to choose from, we plug it into our lambda function. This chapter expands on the unit testing done in Chapter 12, as we test several different scenarios to ensure your stock portfolio is properly valued. The chapter ends with some suggestions for improving our skill.

Chapter 17: What’s Next?

Within this book, you have worked with various data sources, including databases like DynamoDb, and APIs like the Realty Mole Property API. In addition, you have created and tested lambda functions that are back-end applications in the cloud. These Lambda back-ends can pull data from anywhere and expose it through an Alexa skill interface. What’s next? This book is just the beginning of your data-driven Alexa skill journey. I can’t wait to hear what you build.

Acknowledgments

My thanks to my family, especially my wife, who supported me through this process. Thanks to my friends who read through the chapters and provided edits and recommendations. Special thanks to José and Joan for testing the code. Thanks to the Alexa Evangelists, Jeff Blankenburg and Justin Jeffress, who taught me so much. Thanks to the Alexa Community for their support and encouragement, especially Tradelast, Goldzulu, Oxygenbox, and Xeladotbe (see also https://apl.ninja ).

Table of Contents
Part I: Getting Started1
Part II: Custom Skill Development143
Index 407
About the Author
Simon A. Kingaby

is a software developer, programming professor, and public speaker residing in middle Tennessee. He believes that voice user interfaces will change the world and that tools like Alexa are just the tip of the iceberg. He spends his days moving data for Deloitte Global and teaching DataViz and FinTech at universities around the country. In 2016, he published his first Alexa skill and has been enthralled by voice development ever since. In 2017, his uncle suddenly went blind, and Simon began exploring ways Alexa could be used to help the blind with skills from “What’s the time?” and home navigation skills to smart home skills like “Turn on the coffee pot.” In 2019, that same uncle committed suicide, and Simon turned his attention to mental health issues and using Alexa to help identify and prevent suicidal behavior. Now he is focused on enabling developers to use their programming abilities to build data-driven Alexa skills that will make a real difference in the world.

 
About the Technical Reviewer
Jose Rivera

has been in the IT industry for over 20 years, ranging from help desk, DBA, programming, and business intelligence and analytics. He mentors junior developers when joining companies and works with leads in making architecture reviews on programming solutions.

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.27.45