-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (26 loc) · 832 Bytes
/
index.ts
File metadata and controls
33 lines (26 loc) · 832 Bytes
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
import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as packageInfo from './package.json';
import createBot from './src';
const app = express();
const feedbackChat = process.env.CHAT_ID;
const bot = createBot();
process.on('unhandledRejection', (err) => {
bot.sendMessage(feedbackChat, `#SRS_ERROR: ${err}`);
});
app.use(bodyParser.json());
app
.get('/', (req, res) => {
res.json({ version: packageInfo.version });
})
.options('/feedback', cors())
.post('/feedback', cors(), (req, res) => {
bot.sendMessage(feedbackChat, `#FEEDBACK_WEB:\n${req.body.message}`);
res.json({ success: true });
})
.post(`/${bot.token}`, (req, res) => {
bot.processUpdate(req.body);
res.sendStatus(200);
});
app.listen(process.env.PORT || 3000);