-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (45 loc) · 1.74 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const bodyParser = require('body-parser')
const ngrok = require('ngrok')
async function main() {
// create server
const app = express();
// being able to understand data send as as payload in post
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// ****************************************************************
// getting data from matrix
// ****************************************************************
app.post('/matrix', (req, res) => {
let payload = req.body;
console.log("---------- received MESSAGE from MATRIX -------------");
// tell matrix that the message arrived
res.sendStatus(200);
// print the received data
console.log("---------- Summary -------------");
console.log( payload );
if ( payload.before && payload.before.fields ) {
console.log("---------- Before Change Values -------------");
for (var idx=0;idx<payload.before.fields.length;idx++) console.log( payload.before.fields [idx]);
}
if ( payload.after && payload.after.fields ) {
console.log("---------- After Change Values -------------");
for (var idx=0;idx<payload.after.fields.length;idx++) console.log( payload.after.fields [idx]);
}
});
// ****************************************************************
// start webserver
// ****************************************************************
app.get('/', (req, res) => {
res.send("Test Server responding");
});
const PORT = 3000;
app.listen(PORT, async () => {
console.log('Server started on port '+PORT);
const tunnel = await ngrok.connect(PORT);
console.log("Server reachable at "+tunnel);
});
}
(async function() {
await main();
})();