-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
63 lines (46 loc) · 1.41 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
58
59
60
61
62
63
var ab = require('alexa-ability');
var Ability = ab.Ability;
var events = ab.events;
var handleAbility = require('alexa-ability-lambda-handler').handleAbility;
// create our skill
var app = new Ability({
applicationId: 'my-application-id'
});
// add middleware function that run before every request
app.use(function(req, next) {
console.log('Handling:', req);
next();
});
// handle LaunchRequest - "Alexa, launch MyApp"
app.on(events.launch, function(req, next) {
var cardTitle = 'Greetings';
var cardContent = 'Hello world!';
var speech = [
'<speak>',
'Hello <break time="100ms" /> world',
'</speak>'
].join('');
req.show(cardTitle, cardContent).say('ssml', speech).send();
});
// handle SessionEndedRequest - "Alexa stop"
app.on(events.end, function(req, next) {
console.log(`Session ended because: ${req.reason}`);
req.say('Goodbye!').end();
});
// handle custom intents
app.on('MeaningOfLifeIntent', function(req, next) {
asyncRequest(function(err) {
if (err) return next(err);
req.say('42').end();
});
});
// catches any unhandled requests
app.use(function(req, next) {
req.say('I don\'t know what to say').end();
});
// gracefully handles any uncaught errors
app.use(function(err, req, next) {
req.say('Uhoh, something went wrong').end();
});
// export as a lambda handler
module.exports.handler = handleAbility(app);