/
index.js
58 lines (50 loc) · 1.36 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
'use strict';
const https = require('https');
require("dotenv").config();
const api_url = "https://teamdashboard.site/api/teams"
const team_id = 1
const api_token = process.env.API_TOKEN;
function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
return {
outputSpeech: {
type: 'PlainText',
text: output,
},
card: {
type: 'Simple',
title: `SessionSpeechlet - ${title}`,
content: `SessionSpeechlet - ${output}`,
},
reprompt: {
outputSpeech: {
type: 'PlainText',
text: repromptText,
},
},
shouldEndSession,
};
}
exports.handler = function (event, context, callback) {
//let quote = apiClient.getRandomQuote();
let body = '';
console.log(event);
const req = https.request(`${api_url}/${team_id}/quotes/random?api_token=${api_token}`, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
body = JSON.parse(body);
let formatted = `${body.quote} by ${body.by}`;
// var response = {
// statusCode: 200,
// body: formatted
// };
//console.log("response: " + response.body)
let response = buildSpeechletResponse(
"Daily Quote", formatted, null, true
);
callback(null, response);
});
});
req.on('error', callback);
req.end();
};