Getting started with Smart Speakers & Voice Interfaces Ben Teese Darren Cibis
What we’re going to do •Demo •Amazon Echo •Google Home •Parting thoughts
Demo
The Interweb
Amazon Echo
Lambda Alexa Skill Function
The Lambda Function exports.handler = function(event, context, callback) { const request = event.request; const session = event.session; const type = request.type; if (type === 'LaunchRequest') { … } else if (type === 'IntentRequest') { onIntent(request, session, callback); } else { … } };
Drilling in… function onIntent(request, session, callback) { const intent = request.intent; const intentName = intent.name; if (intentName === 'AMAZON.HelpIntent') { … } else if (intentName === 'AMAZON.StopIntent') { … } else if (intentName === 'SetLampColour') { setLampColor(intent, session, callback); } }
f unction setLampColor(intent, session, callback) { const position = intent.slots.position.value || session.attributes.position; let newSessionAttributes, responseText; if (position) { const colour = intent.slots.colour.value; newSessionAttributes = { position }; responseText = "Setting " + position + " lamp colour to " + colour; // Call Lif-X service with the position and colour … } else { responseText = "I'm not sure which lamp you want to use. Please try again.”; } callback(null, { version: '1.0', sessionAttributes: newSessionAttributes, response: { outputSpeech: { type: ‘PlainText', text: responseText, }, shouldEndSession: false } }); }
Alexa Skill Key Concepts •Intents •Sample Utterances •Slots •Dialog Model
Google Home
Actions on API.AI Cloud Google Agent Function
Cloud Function exports.apiDemo = function apiDemo (req, res) { const http = require(‘https'); var color = req.body.result.parameters.Color; var position = req.body.result.parameters.Position; const options = { protocol: "https:", hostname: "api.lifx.com", path: "/v1/lights/label:" + position + "/state", method: "PUT", headers: {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} }; const httpReq = http.request(options); httpReq.on('error', (e) => { console.log('problem with request: ${e.message}'); }); httpReq.write(JSON.stringify({color: color})); httpReq.end(); res.send(); };
Webhook Responses
API.AI Agent Key Concepts •Intents •User Expressions •Entities •Context
It’s About Conversational Interfaces
Thanks @benteese @darren_cibis
Recommend
More recommend