74
Writing Alexa Voice Skills With NodeJS (with a little IoT)

Writing Alexa Voice Skills With NodeJS (with a little IoT)

Embed Size (px)

Citation preview

Page 1: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Writing Alexa Voice Skills With NodeJS(with a little IoT)

Page 2: Writing Alexa Voice Skills With NodeJS (with a little IoT)

David Janes@dpjanes

[email protected]://iotdb.org/social/imadeit/

October 2016

Page 3: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Introduction

Page 4: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Important Links

• Alexa Skills Console https://developer.amazon.com/edw/home.html#/skills/list

• Sample Code & Skill https://github.com/dpjanes/homestar-alexa

Page 5: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Topics Covered

• Choosing an Architecture

• Creating a Skill

• Interaction Model

• Skills for the IoT

• Testing your Skill

Page 6: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Emphasis

• We'll focus on core concepts

• Intent, Slots, Utterances

• From definition to implementation

Page 7: Writing Alexa Voice Skills With NodeJS (with a little IoT)

About IOTDB

• Open Source IoT Platform

• Based on Semantics

• Natural fit for voice control

• https://github.com/dpjanes/node-iotdb

Page 8: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Architecture

Page 9: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Many Moving Parts

• Home

• Amazon Echo

• IoT Device

• Iot Controller

• Amazon

• Alexa Voice Skill

• Cloud

• Skill Server

• Vendor Server

• Proxy Server

Page 10: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Typical Alexa Voice Skill(hosted)

Page 11: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Typical Alexa Voice Skill(AWS Lambda)

Page 12: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Cloud Based

Page 13: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Home Based

Page 14: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Proxy Based

Page 15: Writing Alexa Voice Skills With NodeJS (with a little IoT)

This Presentation

• Focus on writing Alexa Voice Skill

• Communications between Cloud and your Home will be "open"

Page 16: Writing Alexa Voice Skills With NodeJS (with a little IoT)

e.g. mainly this

Page 17: Writing Alexa Voice Skills With NodeJS (with a little IoT)

CreatingAlexa Voice Skills

Page 18: Writing Alexa Voice Skills With NodeJS (with a little IoT)

e.g. here

Page 19: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Getting Started

• https://developer.amazon.com/edw/home.html#/skills/list

• Create an Account if you don't have one

• will require SMS verification

• Select "Add a New Skill"

Page 20: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Alexa Skill Editor

Page 21: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Alexa Skill Editor

• We'll focus on

• Skill Information

• Interaction Model

• Configuration

• Test

Page 22: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Editor: Skill Information

Page 23: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Alexa Skill Editor

Page 24: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Creating New Skill: Skill Information

Page 25: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Information: Skill Type

• Different types of Skills

• Custom: the most flexible

• Smart Home Skill: don't have to use the "magic word" (the Invocation Name)

• Flash Briefing: news

Page 26: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Information: Skill Type

• What will appear in your Skills List

• What will appear in the App Store

Page 27: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Information: Invocation Name

• The "Magic Word"

• Alexa, ask HomeStar to …

• Alexa, tell HomeStar to …

• Not needed with Smart Home Skills

Page 28: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Editor:Interaction Model

Page 29: Writing Alexa Voice Skills With NodeJS (with a little IoT)
Page 30: Writing Alexa Voice Skills With NodeJS (with a little IoT)

This is the Cool Part

• The Interaction Model determines how Alexa interprets your voice commands

Page 31: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Interaction Terminology

• Utterances

• Slots

• Intents

Page 32: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances

• Step 1 in writing your Alexa Voice Skill

• Write down things you want to say

• Look for Patterns

Page 33: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances"Ask HomeStar…"

• turn on Stove

• turn off Stove

• turn on Light

• turn on Light in the Kitchen

• turn off TV

• turn off Living Room TV

• turn off everything

• to turn off everything

• to turn off everything in the Living Room

• turn down TV

• turn down TV in the Living Room

Page 34: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances"Ask HomeStar…"

• turn on {Thing}

• turn off {Thing}

• turn on {Thing}

• turn on {Thing} in the Kitchen

• turn off {Thing}

• turn off Living Room {Thing}

• turn off {Thing}

• to turn off {Thing}

• to turn off {Thing} in the Living Room

• turn down {Thing}

Page 35: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances"Ask HomeStar…"

• turn on {Thing}

• turn off {Thing}

• turn on {Thing}

• turn on {Thing} in the {Zone}

• turn off {Thing}

• turn off {Zone} {Thing}

• turn off {Thing}

• to turn off {Thing}

• to turn off {Thing} in the {Zone}

• turn down {Thing}

• turn down {Thing} in the {Zone}

Page 36: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances"Ask HomeStar…"

• {Action} {Thing}

• {Action} {Thing}

• {Action} {Thing}

• {Action} {Thing} in the {Zone}

• {Action} {Thing}

• {Action} {Zone} {Thing}

• {Action} {Thing}

• to {Action} {Thing}

• to {Action} {Thing} in the {Zone}

• {Action} {Thing}

• {Action} {Thing} in the {Zone}

Page 37: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Utterances"Ask HomeStar…"

• {Action} {Thing}

• to {Action} {Thing}

• {Action} {Thing} in the {Zone}

• to {Action} {Thing} in the {Zone}

• {Action} {Zone} {Thing}

• to {Action} {Zone} {Thing}

Page 38: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Slots

• These are the {variables} in the Utterances

• e.g. {Thing}, {Zone}, {Action}

• two types of slots:

• Custom (e.g. above)

• Built-In

Page 39: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Slots (Built-In)

• Date

• Duration

• Four Digit Number

• Number

• Time

• Cities…

Page 40: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Slots {Thing}

• lamp

• light

• coffee maker

• kettle

• stove

• tv…

Page 41: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Slots {Action}

• turn off

• turn on

• turn down

• turn up

• open

• close

Page 42: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Slots {Zone}

• Back Door

• Back Garden

• Back Hall

• Back Porch

• Basement

• Basement Bathroom…

Page 43: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Intents

• Basically, Intents are "phases" of your conversation with Alexa

• If "single shot" then this isn't very complicated - just define a "FirstIntent", e.g. HomeStarFirst Intent

Page 44: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Putting it together

Page 45: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Putting it together

Page 46: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Editor:Configuration

Page 47: Writing Alexa Voice Skills With NodeJS (with a little IoT)
Page 48: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Configuration: Endpoint

• Two (major options)

• AWS Lambda

• Hosted - contacts a url

• Note the URL we are using - we'll see it again soon

Page 49: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Configuration: Account Linking

• Used for connecting to systems that have accounts!

• E.g. Smart Homes - what Smart Home does Alexa have to talk to

• Set up when user connects to Skill

Page 50: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Configuration: Account Linking

• Alexa calls your Authorize URL with a number of parameters

• Let the user do something on your website to confirm it

• Your website redirects back to Alexa with a number of magic parameters

Page 51: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Alexa Skill Endpoint /Your Server

Page 52: Writing Alexa Voice Skills With NodeJS (with a little IoT)

e.g. here

Page 53: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Sample Code

• url: https://github.com/dpjanes/homestar-alexa/

• ./hosted/monitor_1.js

Page 54: Writing Alexa Voice Skills With NodeJS (with a little IoT)

N.B.

• Alexa Skill is configured to hit https://alexa.homestar.io/request

• You must use HTTPS

• Amazon provides flexibility in certs

Page 55: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Sample Code (1)

Page 56: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Demo (1)"monitor_1.js"

Page 57: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request

Page 58: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request

• "session"

• a session of interactions (captured in Intents) between user and Alexa

• user login info (from Account Linking)

• "request"

• the Intent and Slot data

Page 59: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"session"

Page 60: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"session"

• "new": we can be continuing a session

• "sessionId": in case you are, for logging

• "user": all this is set up by Account Linking

• not required if just for yourself

Page 61: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"request"

Page 62: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"request"

• "type"

• "locale"

• "intent"

Page 63: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"request/intent"

• "name"

• "slots"

• Action / Query / Zone / Thing

• We defined these!

Page 64: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Request"request/intent"

• "request/intent/slots/Action/value": the {{ Action }}

• "request/intent/slots/Thing/value": the {{ Thing }}

Page 65: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Response

Page 66: Writing Alexa Voice Skills With NodeJS (with a little IoT)

The Response

• "response/outputSpeech/text": this is what Alexa will say to the user

• "response/shouldEndSession": make false if you want to keep going

Page 67: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Sample Code (II)

Page 68: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Demo (II)"monitor_2.js"

Page 69: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Skill Editor: Test

Page 70: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Test

Page 71: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Going Further

Page 72: Writing Alexa Voice Skills With NodeJS (with a little IoT)

IOTDB

• NPM modules

• iotdb

• homestar

• iotdb-commands

• takes Action / Thing / &c and does it

Page 73: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Demo (III)live

Page 74: Writing Alexa Voice Skills With NodeJS (with a little IoT)

Get in touch! David Janes

@[email protected]

http://iotdb.org/social/imadeit/