-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (33 loc) · 1.05 KB
/
Copy pathserver.js
File metadata and controls
42 lines (33 loc) · 1.05 KB
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
const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(express.static('public'));
const events = JSON.parse(fs.readFileSync('events.json'));
const faqs = JSON.parse(fs.readFileSync('faqs.json'));
app.post('/chat', (req, res) => {
const userQuestion = req.body.question.toLowerCase();
let response = 'Sorry, I do not have an answer for that.';
// Check FAQs
for (let faq of faqs) {
if (userQuestion.includes(faq.question.toLowerCase())) {
response = faq.answer;
break;
}
}
// Check Events
if (response === 'Sorry, I do not have an answer for that.') {
for (let event of events) {
if (userQuestion.includes(event.name.toLowerCase())) {
response = `Event: ${event.name}, Date: ${event.date}, Description: ${event.description}`;
break;
}
}
}
res.send({ answer: response });
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});