-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (90 loc) · 2.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var alexa = require('alexa-app');
var app = new alexa.app('convey');
var _ = require('underscore');
var removeMd = require('remove-markdown');
var conveyPackage = require('./package.json');
var factsArray = require('./facts.json')
var alternativeFactGenerator = require('./services/alternative_fact_generator')
console.log(`Loaded convey ${conveyPackage.version}.`);
module.change_code = 1; // allow this module to be reloaded by hotswap when changed
app.launch(function(req, res) {
console.log('app.launch');
res
.say("We have Ms. convey on the line! Ask her for an alternative fact.")
.shouldEndSession(false, "Say help if you need help or exit any time to exit.")
.send();
});
app.intent('AMAZON.StopIntent', {
"slots": {},
"utterances": [
"stop"
]
},
function(req, res) {
console.log('app.AMAZON.StopIntent');
res.say("convey says Goodbye.");
res.send();
}
);
app.intent('AMAZON.CancelIntent', {
"slots": {},
"utterances": [
"cancel"
]
},
function(req, res) {
console.log('app.AMAZON.CancelIntent');
res.say("convey says Goodbye.");
res.send();
}
);
app.intent('AMAZON.HelpIntent', {
"slots": {},
"utterances": [
"help"
]
},
function(req, res) {
console.log('app.AMAZON.HelpIntent');
res.say("Convey can tell you random alternative facts. Ask her for an alternative fact.");
res.shouldEndSession(false);
res.send();
}
);
app.intent('AltFactIntent', {
'utterances': [
'for an alternative fact',
"today's alternative facts"
]
},
function(req, res) {
alternativeFactGenerator.altFactFromNews(5).then(function(alternativeFact) {
res.say(`Here are today's alternative facts: ${alternativeFact.join('; ')}`);
res.shouldEndSession(true);
res.send()
})
.catch(function(error) {
var randomFact = _.sample(factsArray)
var alternativeFacts = alternativeFactGenerator.alternetize(randomFact)
res.say(`Here are today's alternative facts: ${alternativeFact}`)
res.shouldEndSession(true);
res.send()
})
// return false immediately so alexa-app doesn't send the response
return false;
});
if (process.env['ENV'] == 'lambda') {
console.log("Starting Alternative Fact Alexa on AWS lambda.")
exports.handle = app.lambda();
} else if (process.env['ENV'] == 'development') {
console.log("Starting Alternative Fact Alexa in development mode.")
module.exports = app;
} else if (process.env['ENV'] == 'test') {
console.log("Starting Alternative Fact Alexa in test mode.")
module.exports = app;
} else {
var fs = require('fs');
fs.writeFileSync('schema.json', app.schema());
fs.writeFileSync('utterances.txt', app.utterances());
console.log('Schema and utterances exported.');
}