-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcardskill.js
62 lines (55 loc) · 2.14 KB
/
cardskill.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
'use strict';
const Alexa = require("alexa-sdk");
const cards = require('./data.json');
exports.handler = function(event, context, callback) {
const alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
const handlers = {
'LaunchRequest': function () {
this.emit('WantACard');
},
'NextCardIntent': function () {
this.emit('WantACard');
},
'WantACard': function () {
var randomCardIndex = Math.floor(Math.random() * Math.floor(cards.length));
this.attributes['lastRandomCard'] = cards[randomCardIndex];
this.response.speak(cards[randomCardIndex].question)
.listen('Say give me the answer to get the answer.');
this.emit(':responseReady');
},
'AnswerCardIntent': function () {
this.emit('AnswerTheCard');
},
'AnswerTheCard': function () {
var lastRandomCard = this.attributes['lastRandomCard'];
if (lastRandomCard != null) {
this.response.speak(lastRandomCard.answer + ' <break time="1s"/> Say give me the next card to get another card.')
.listen('Say give me the next card to get another card.');
} else {
this.response.speak('Please ask for a card first. <break time="1s"/> Say give me a card to get a card.')
.listen('Say give me a card to get a card.');
}
this.emit(':responseReady');
},
'AMAZON.HelpIntent': function () {
const speechOutput = 'This is the Flash Card Skill. ';
const reprompt = 'Say give me a new card, to get a new card.';
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak('Goodbye!');
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak('See you later!');
this.emit(':responseReady');
},
'Unhandled': function () {
this.response.speak('I did not understand the request. To ask for help say help.');
this.emit(':responseReady');
}
};