-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (37 loc) · 1.57 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
const hostname = 'dungeon.mitchgordon.me';
const port = '443';
const input_router = require('./input_router.js');
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const https = require('https');
const fs = require('fs');
var files = require('./files.js');
var log = require('./log.js');
const express = require('express');
var expressApp = express();
const bodyParser = require('body-parser');
expressApp.use(bodyParser.json());
if (!fs.existsSync(files.SAVE_DIRECTORY)) {
fs.mkdir(files.SAVE_DIRECTORY);
}
if (!fs.existsSync(files.LOGS_DIRECTORY)) {
fs.mkdir(files.LOGS_DIRECTORY);
}
expressApp.post('/', function(req, res) {
const app = new ActionsSdkApp({request: req, response: res});
app.askSSML = function (text, dialogState) { app.ask(`<speak> ${text} </speak>`, dialogState); };
app.askWithListSSML = function (prompt, list, dialogState) {
app.askWithList(`<speak> ${prompt} </speak>`, list, dialogState);
};
const actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, input_router.acceptMain);
actionMap.set(app.StandardIntents.TEXT, input_router.acceptInput);
actionMap.set(app.StandardIntents.OPTION, input_router.acceptOption);
app.handleRequest(actionMap);
log.logInput(app);
});
var options = {
ca: fs.readFileSync('/home/ubuntu/https_certs/dungeon_mitchgordon_me.ca-bundle'),
key: fs.readFileSync('/home/ubuntu/https_certs/dungeon_mitchgordon_me.key'),
cert: fs.readFileSync('/home/ubuntu/https_certs/dungeon_mitchgordon_me.crt')
};
https.createServer(options, expressApp).listen(443);