Skip to content

Instantly share code, notes, and snippets.

@djbelieny
Forked from sjoerdvisscher/slackbot.js
Created August 18, 2017 15:59
Show Gist options
  • Select an option

  • Save djbelieny/a19f8aedd1e5e2df2beda63da58db1fa to your computer and use it in GitHub Desktop.

Select an option

Save djbelieny/a19f8aedd1e5e2df2beda63da58db1fa to your computer and use it in GitHub Desktop.
Create Slack bots with Meteor!
function slackpost(channel, name, text) {
HTTP.post("https://q42.slack.com/services/hooks/incoming-webhook", {"params":
{"token": "TODO: fill in token!",
"payload": JSON.stringify({
"channel": "#" + channel,
"username": name,
"text": text,
"icon_emoji": (name.indexOf("bot") > -1 ? ":ghost:" : "")
})
}}
);
}
if (Meteor.isServer) {
Router.map(function () {
var that = this;
function command(name, body, hideCommand) {
that.route(name, {
where: 'server',
path: '/' + name,
action: function () {
var p = this.params;
if (!hideCommand)
slackpost(p.channel_name, p.user_name, "/" + name + " " + p.text);
body(function(t) { slackpost(p.channel_name, name + "bot", t) }, p.text, p);
this.response.writeHead(200, {'Content-Type': 'text/html'});
this.response.end(name + " command executed!");
}
})
}
command("hoi", function(post, text) {
post("<http://static.q42.nl/images/employees/" + text + "gif.gif>");
});
command("stock", function(post, text) {
post("<http://chart.finance.yahoo.com/t?s=" + text + "&lang=en-US&region=US&width=300&height=180>")
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment