Last active
August 16, 2016 01:04
-
-
Save TheConnMan/af69783075a5575441f4d5d8999ecb21 to your computer and use it in GitHub Desktop.
Bonsai Water Slack Relay Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine | |
RUN apk add --no-cache nodejs git | |
RUN npm install -g bower | |
WORKDIR /usr/src/app | |
COPY package.json /usr/src/app | |
RUN npm install | |
COPY . /usr/src/app | |
RUN bower install --allow-root | |
RUN npm remove -g bower | |
RUN apk del git | |
ENV API_KEY changeme | |
ENV HOOK_URL https://hooks.slack.com/services/test/hook/url | |
EXPOSE 3000 | |
CMD node index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var Slack = require('node-slack'); | |
var app = express(); | |
var slack = new Slack(process.env.HOOK_URL); | |
app.use(express.static('public')); | |
app.get('/api/slack', function(req, res) { | |
try { | |
var result = { | |
"ok": true | |
}; | |
var request = { | |
channel: '#testing', | |
username: 'Slack Relay' | |
}; | |
if (req.query.apiKey !== process.env.API_KEY) { | |
throw "Invalid API key"; | |
} | |
if (!req.query.text) { | |
throw "Requires a text parameter"; | |
} | |
request.text = req.query.text; | |
if (req.query.username) { | |
request.username = req.query.username; | |
} | |
if (req.query.channel) { | |
request.channel = req.query.channel; | |
} | |
slack.send(request); | |
res.json(result); | |
} catch (e) { | |
console.log(e); | |
res.json({ | |
"ok": false, | |
"error": e | |
}); | |
} | |
}); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment