-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
44 lines (37 loc) · 916 Bytes
/
app.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
const express = require('express');
const bodyParser = require('body-parser');
const { PORT, CONFIRMATION } = require('./config');
const processing = require('./processing');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', (req, res) => res.send('Hello World!'));
app.post('/', (req, res) => {
const { body } = req;
switch (body.type) {
case 'confirmation':
res.end(CONFIRMATION);
break;
case 'message_new':
processing(body.object);
res.end('ok');
break;
default:
res.end('ok');
break;
}
});
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`));
/*
{ type: 'message_new',
object:
{ id: 2,
date: 1530616850,
out: 0,
user_id: 453773759,
read_state: 0,
title: '',
payload: 1,
body: 'test' },
group_id: 165364631 }
*/