-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (37 loc) · 999 Bytes
/
server.js
File metadata and controls
44 lines (37 loc) · 999 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
var bodyParser = require('body-parser');
var doots = require('./doots.js');
var express = require('express');
var request = require('request');
var app = express();
var port = process.env.PORT || 3000;
var postOptions = {
url: 'https://api.groupme.com/v3/bots/post',
method: 'POST'
};
app.use(bodyParser.json());
app.route('/')
.get(function(req, res) {
sayBot(res);
//res.end('Thanks');
})
.post(function(req, res) {
if(req.body.name.toLowerCase().indexOf('doot bot') < 0 && req.body.text.toLowerCase().indexOf('doot') > -1) {
setTimeout(sayBot(res), 4000);
}else {
res.send('Thanks');
}
});
function sayBot(res) {
var botData = {
bot_id: process.env.BOT_ID,
text: doots[Math.floor(Math.random()*doots.length)]
};
postOptions.json = botData;
request(postOptions, function(error, response, body) {
res.end('Thanks');
});
}
app.listen(port, function(){
console.log('The magic happens on port ' + port);
});
exports.app = app;