-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-alexa.app.js
55 lines (49 loc) · 2.01 KB
/
index-alexa.app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict'
/*
* An AWS Lambda function to control Alexa Skill MagicMirror requests.
*
*/
const Alexa = require('alexa-app');
const mirror = require('./iotgateway');
// Allow this module to be reloaded by hotswap when changed
module.change_code = 1;
// ------------ Define an alexa-app
var app = new Alexa.app('magicmirror')
app.id = require('./package.json').alexa.applicationId;
var mirrorConfig = require('./certs/deployConfig'); // This file is put here by the prepareDeploy.js utility
// ------------ Configure the IOT device
console.log("Calling mirror.setup()");
mirror.setup(mirrorConfig);
// ------------ Define the launch request
app.launch(function(req, res) {
var prompt = 'What can I do for you? Say help for help.';
res.say(prompt).reprompt(prompt).shouldEndSession(false);
});
// ----------- Define the Play Sonos intent
app.intent('PlaySonos',
{
'slots': {'WHAT': 'LITERAL', 'WHERE': 'LITERAL'},
'utterances': ['play {tunein|WHAT} in {office|kitchen|WHERE}', 'start {office|kitchen|WHERE}']
}, function(req, res) {
var what = req.slot('WHAT');
var where = req.slot('WHERE');
console.log("index.js: Got PlaySonos What="+what + " Where="+where);
mirror.play(what, where, function(err) {
if (err) {
console.log("AlexaComms - SERVICE_FAILURE: " + JSON.stringify(err), err);
res.say('Could not comply with that. Sorry.');
return;
}
console.log("index.js: Have sent the request PlaySonos What="+what + " Where="+where);
res.say('Ok. Done and done.');
/*if (what === undefined || what == '') {
res.say('Ok. Resuming in ' + where + '.');
} else {
res.say('Ok. Playing ' + what + ' in ' + where + '.');
}*/
});
//res.say('Ok. Playing ' + what + ' in ' + where + '.');
return false; // See example lambda.js in alexa-app (has something to do with async handler)
}
);
module.exports = app;