-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (40 loc) · 1.41 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
// =================================================================================
// App Configuration
// =================================================================================
// https://1a087932.ngrok.io/webhook
const app = require('jovo-framework').Jovo;
const webhook = require('jovo-framework').Webhook;
const Handler = require('./src/handlers');
const fs = require('fs');
// Listen for post requests
webhook.listen(8008, () => {
console.log('Local development server listening on port 8008...');
});
const handlerDE = new Handler('de');
const handlerEN = new Handler('en');
webhook.post('/api/hiking', (req, res) => {
switch (req.body.request.locale) {
case 'de-DE':
app.handleRequest(req, res, handlerDE.handler);
break;
case 'en-US':
app.handleRequest(req, res, handlerEN.handler);
break;
default:
console.log('Unknown language', req.body.request.locale);
}
app.execute();
});
webhook.get('/api/hiking/image/', (req, res) => {
fs.readFile(`../images/${req.query.image}`, (err, content) => {
if (err) {
res.writeHead(400, { 'Content-type': 'text/html' });
console.log(err);
res.end('No such image');
} else {
// specify the content type in the response will be an image
res.writeHead(200, { 'Content-type': 'image/jpg' });
res.end(content);
}
});
});