-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (27 loc) · 833 Bytes
/
server.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
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io').listen(server);
var port = process.env.PORT || 8080;
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/webhook', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('payload', function(msg)
{
io.emit('payload', msg);
});
});
app.post('/webhook', function(req, res){
var payload = req.body;
io.sockets.emit('payload', payload);
console.log("Payload = " + payload.text + " : " + payload.user_name);
res.end("Message Received...");
});
server.listen(port, function(){
console.log('listening on '+ port);
});