forked from seattleacademy/spring23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadamsample.js
56 lines (50 loc) · 1.49 KB
/
adamsample.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
var https = require('https');
var fs = require('fs');
var quotes = [];
quotes.push("what did zero say to eight? nice belt!");
quotes.push("what did the blind man say when he walked into the bar? ouch!");
quotes.push("error");
quotes.push("connection refused");
quotes.push("fifth quote");
function getRandomQuote() {
return quotes[Math.floor(Math.random() * quotes.length)];
}
var options = {
key: fs.readFileSync('/etc/ssl/server.key'),
cert: fs.readFileSync('/etc/ssl/server.crt')
};
function respond(theText) {
theResponse = {
version: '1.0',
response: {
outputSpeech: {
type: 'PlainText',
text: theText
},
card: {
type: 'Simple',
title: 'Sample',
subtitle: 'Spring 23',
content: theText
},
shouldEndSession: 'true'
}
}
return (theResponse);
}
https.createServer(options, function(req, res) {
if (req.method == 'POST') {
var jsonString = '';
req.on('data', function(data) {
jsonString += data;
});
req.on('end', function() {
console.log(JSON.parse(jsonString));
});
}
myResponse = JSON.stringify(respond(getRandomQuote()));
res.setHeader('Content-Length', myResponse.length);
res.writeHead(200);
res.end(myResponse);
console.log(myResponse);
}).listen(443); //Put number in the 3000 range for testing and 443 for production