Showing
3 changed files
with
40 additions
and
0 deletions
Experiments/messenger/webhook/app.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +const bodyParser = require('body-parser'); | ||
3 | +var app = express(); | ||
4 | +app.use(bodyParser.json()); | ||
5 | + | ||
6 | +app.post('/hook', function (request, response) { | ||
7 | + | ||
8 | + var eventObj = request.body.events[0]; | ||
9 | + var source = eventObj.source; | ||
10 | + var message = eventObj.message; | ||
11 | + | ||
12 | + // request log | ||
13 | + console.log('======================', new Date() ,'======================'); | ||
14 | + console.log('[request]', request.body); | ||
15 | + console.log('[request source] ', eventObj.source); | ||
16 | + console.log('[request message]', eventObj.message); | ||
17 | + | ||
18 | + response.sendStatus(200); | ||
19 | +}); | ||
20 | + | ||
21 | +var server = app.listen(23023, function () { | ||
22 | + var host = server.address().address | ||
23 | + var port = server.address().port | ||
24 | + console.log("Example app listening at http://%s:%s", host, port) | ||
25 | +}) |
This diff is collapsed. Click to expand it.
Experiments/messenger/webhook/package.json
0 → 100644
1 | +{ | ||
2 | + "name": "webhook", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "app.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "body-parser": "^1.19.0", | ||
13 | + "express": "^4.17.1" | ||
14 | + } | ||
15 | +} |
-
Please register or login to post a comment