1 | import superscript from 'superscript';
|
2 | import express from 'express';
|
3 | import bodyParser from 'body-parser';
|
4 |
|
5 | const server = express();
|
6 | const PORT = process.env.PORT || 5000;
|
7 |
|
8 | server.use(bodyParser.json());
|
9 |
|
10 | let bot;
|
11 |
|
12 | server.get('/superscript', (req, res) => {
|
13 | if (req.query.message) {
|
14 | return bot.reply('user1', req.query.message, (err, reply) => {
|
15 | res.json({
|
16 | message: reply.string,
|
17 | });
|
18 | });
|
19 | }
|
20 | return res.json({ error: 'No message provided.' });
|
21 | });
|
22 |
|
23 | const options = {
|
24 | factSystem: {
|
25 | clean: true,
|
26 | },
|
27 | importFile: './data.json',
|
28 | };
|
29 |
|
30 | superscript.setup(options, (err, botInstance) => {
|
31 | if (err) {
|
32 | console.error(err);
|
33 | }
|
34 | bot = botInstance;
|
35 |
|
36 | server.listen(PORT, () => {
|
37 | console.log(`===> 🚀 Server is now running on port ${PORT}`);
|
38 | });
|
39 | });
|