-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 832 Bytes
/
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
const config = require("./config");
const alexa = require("./alexa");
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
alexa.login();
setInterval(function () {
alexa.login();
}, config.timerRefreshCookie * 60 * 60 * 1000);
app.get('/', function (req, res) {
res.send('Nodejs server TTS for Echo!');
});
app.get('/tts/:msg', (req, res) => {
let msg = req.params.msg;
fs.readFile(path.join(__dirname, config.cookieFile), 'utf8', function (err, fileData) {
if (err) {
console.log(err);
return;
}
alexa.sendTtsToAlexa(JSON.parse(fileData), msg).then(r => {
if (!r) return res.send(false);
return res.send(true);
});
});
});
app.listen(config.port, () => console.log(`Example app listening on port ${config.port}!`));