Getting started with Smart Speakers & Voice Interfaces
Ben Teese Darren Cibis
Getting started with Smart Speakers & Voice Interfaces Ben - - PowerPoint PPT Presentation
Getting started with Smart Speakers & Voice Interfaces Ben Teese Darren Cibis What were going to do Demo Amazon Echo Google Home Parting thoughts Demo The Interweb Amazon Echo Lambda Alexa Skill Function The Lambda
Ben Teese Darren Cibis
The Interweb
Alexa Skill
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') {
} else { … } };
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); } }
function 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: {
type: ‘PlainText', text: responseText, }, shouldEndSession: false } }); }
Actions on Google
Cloud Function
API.AI Agent
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(); };
@benteese @darren_cibis