-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (46 loc) · 1.56 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
'use strict';
const Alexa = require('alexa-sdk');
const fetch = require('node-fetch');
const {apiUrl, appId} = require('./config');
const HELP_MESSAGE = 'You can say tell me a space fact, or, you can say exit... What can I help you with?';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Goodbye!';
const SKILL_NAME = 'Dolores';
const handlers = {
'LaunchRequest': function () {
this.emit('LightIntent');
},
'LightIntent': function (){
const speechOutput = 'Light toggled';
fetch(apiUrl)
.then((res) => {
this.response.cardRenderer(SKILL_NAME, speechOutput);
this.response.speak(speechOutput);
this.emit(':responseReady');
})
.catch((err) => {
this.response.speak("Some error occured");
this.emit(':responseReady');
});
},
'AMAZON.HelpIntent': function () {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
}
}
exports.handler = (event, context, callback) => {
const alexa = Alexa.handler(event, context, callback);
alexa.appId = appId;
alexa.registerHandlers(handlers);
alexa.execute();
};