Skip to content

Commit 1598ba4

Browse files
committed
Initial spike
0 parents  commit 1598ba4

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node index.js

config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
port: process.env.PORT || 3000,
3+
slack: {
4+
domain: process.env.SLACK_DOMAIN,
5+
token: process.env.SLACK_TOKEN
6+
},
7+
hipchat: {
8+
token: process.env.HIPCHAT_TOKEN,
9+
room: process.env.HIPCHAT_ROOM
10+
}
11+
};

index.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var config = require('./config');
2+
3+
var express = require('express');
4+
var morgan = require('morgan');
5+
var web = express();
6+
web.use(morgan());
7+
web.listen(config.port);
8+
wlog("Listening for http on " + config.port);
9+
10+
var Slack = require('node-slack');
11+
var slackbot = new Slack(config.slack.domain, config.slack.token);
12+
13+
var Hipchat = require('node-hipchat');
14+
var hipbot = new Hipchat(config.hipchat.token);
15+
16+
web.get('/', function(req, res){
17+
res.end("I AM WIZARDBOT");
18+
});
19+
20+
21+
function wlog () {
22+
var args = [].slice.apply(arguments);
23+
args.unshift("WIZARDBOT:");
24+
console.log.apply(console, args);
25+
}
26+
27+
// slackbot.send({
28+
// text: 'Howdy!',
29+
// channel: '#test',
30+
// username: 'Bot'
31+
// });
32+
33+
var getHipChatMessages = function (cb) {
34+
35+
var ignorebot = function(data, err){
36+
if (err) { return cb(err, data); }
37+
38+
// filter out messages from the api, eg the bot
39+
data = data.messages.filter(function(msg){
40+
return msg.from.user_id !== 'api';
41+
});
42+
43+
data = data.map(function(msg) {
44+
msg.username = msg.from.name;
45+
msg.text = msg.message;
46+
return msg;
47+
});
48+
49+
cb(err, data);
50+
};
51+
52+
hipbot.getHistory({
53+
room: config.hipchat.room
54+
}, ignorebot);
55+
};
56+
57+
getHipChatMessages(function(err, data){
58+
if (err) { return console.error(err); }
59+
console.log(data);
60+
});
61+
62+
// hipchatter.get_room(config.hipchat.room, console.log);
63+
64+
// hipchatter.notify('test',{
65+
// message: '<b>I AM A ROBOT</b>',
66+
// token: 'O82nQQEk88uFR6PYAec2JsFs3r6RGol0RRM569SG',
67+
// }, console.log);

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "wizardbot",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git://github.com/wizarddevelopment/wizardbot.git"
12+
},
13+
"author": "",
14+
"license": "BSD-2-Clause",
15+
"bugs": {
16+
"url": "https://github.com/wizarddevelopment/wizardbot/issues"
17+
},
18+
"dependencies": {
19+
"node-slack": "0.0.3",
20+
"node-hipchat": "~0.4.5",
21+
"express": "~4.1.1",
22+
"morgan": "~1.0.1"
23+
}
24+
}

0 commit comments

Comments
 (0)