-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (45 loc) · 1019 Bytes
/
Copy pathapp.js
File metadata and controls
49 lines (45 loc) · 1019 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express');
const {PORT, CONFIRMATION} = require('./config');
const processing = require('./processing');
const app = express();
const bodyParser = require('body-parser');
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 at http://localhost:${PORT}`)
});
/*
{
type: 'message_new',
object: {
id: 2,
date: 1599945694,
out: 0,
user_id: 8627789,
read_state: 0,
title: '',
body: 'qwerty',
owner_ids: []
},
group_id: 25357393,
event_id: 'e0734038fa3d2e5e11d3c0ed5fed7b06d6ba07f2'
}
*/