-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (49 loc) · 1.34 KB
/
index.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
56
57
require('localenv');
var mintpeaks = require('./lib/mintpeaks');
const APPLICATION_ID = process.env.APPLICATION_ID;
if (!APPLICATION_ID) {
throw 'No application ID configured';
}
exports.handler = function (event, context) {
console.log('at=handler status=starting application_id=' + APPLICATION_ID);
try {
if (event.session.application.applicationId !== APPLICATION_ID) {
console.warn('at=handler event.session.application.applicationId=' + event.session.application.applicationId);
context.fail('Invalid Application ID');
}
console.log('at=handler event.request.type=' + event.request.type);
if (event.request.type === 'LaunchRequest' || event.request.type === 'IntentRequest') {
mintpeaks.get(
event.request,
event.session,
function callback(speech) {
context.succeed(
buildResponse(
buildSpeechletResponse(speech)
)
);
}
);
} else {
context.succeed();
}
} catch (e) {
context.fail('Exception: ' + e);
}
};
function buildSpeechletResponse(output) {
return {
outputSpeech: {
type: 'PlainText',
text: output
},
shouldEndSession: true
};
}
function buildResponse(speechletResponse) {
return {
version: '1.0',
sessionAttributes: {},
response: speechletResponse
};
}