Slack-bot, Integrating Slack with Meteor-Telescope app — Entertainment in Slack!

Abhay Talreja
3 min readOct 12, 2016

--

So, now that I have my app setup — https://coolmoviebites.com — I thought why not automate stuff. Especially, i spend a lot of time in slack.

Here is the link to my team. If you need help setting up your team login button, check out this article.

So, why not have entertainment mixed with work all in one place. So, I pulled up my socks and started working on connecting slack to my Telescope based Meteor app.

The integration turned out to be rather easy! I will just show you how to write the meteor method. So, you can integrate it with any of the Meteor apps, including Telescope — I do it on post approval.

Step 1: Create the slack channel you need to add the feeds to.

Step 2: Create an incoming-webhook

Go to the below url and you will be able to create a new app in slack.

https://<replace-your-slack-team>.slack.com/apps/build

For me it was

https://coolmoviebites.slack.com/apps/build

This is what you

The next thing to do is, select Incoming Webhooks and then the channel you need to send the updates to. You can programmatically, decide which channel the updates should go to (more on this later).

Select Channel
Finally!

This should give you a webhook url — Make a note of it. Something like.

https://hooks.slack.com/services/SomeGibberish

Add this url to your settings.json file. It should look something like

{
"public": {
"title": "Coolmoviebites | Your Daily bite of entertainment ",
...
},
"slack":{
"webhookUrl": "https://hooks.slack.com/services/SomeGibberish"
}
}

Step 3: Get the slack-bot package

Go to Npm — Get this package — https://www.npmjs.com/package/slack-bot

There are many, but this is the one that I used.

npm install slack-bot (save)
var slackBot = require('slack-bot')(Meteor.settings.slack.webhookUrl);function postToSlack(message, channel){
// console.log(message);
Meteor._sleepForMs(4000); //I put a delay, just so that the React Head Tags get loaded, OpenGraph, Twitter, meta, etc.
slackBot.send({
channel: channel,
username: 'new-updates',
text: message,
unfurl_links: true,
unfurl_media:true,
}, function (err, res) {
if (err) { throw err; }
// console.log(res);
});
}
Meteor.startup(function () {
Meteor.methods({
postToSlack: function(message, channel){
postToSlack(message, channel);
}
});
});

And Boom! your code is all set. Just make the method call at the triggering point of this action.

In my case, it was on post Approval. So, whenever I approve a post, I send this to slack!

Step 4: Dynamic Channels

Do you see, that we added a channel parameter to our method? I have it configured based on language and category. So, people can subscribe to any of the channels.

    let channel = "#latest-updates";
for (var i =0; i < post.categories.length; i++) {
let category = Categories.findOne(post.categories[i]);
if(category.slug === 'devotional'){
channel = "#devotional";
break;
}
if(category.slug === 'music'){
channel = "#music";
break;
}
}

That’s it, happy slacking and getting entertained!

IF you like entertaiment and loved this piece. Please join my slack team - The first of it's kind for entertainment!Ofcourse, if you are ready to help out in growing the community! Let's do it together!

Signing off!

--

--

Abhay Talreja

A passionate Technologist with over 16 years of experience in software and web development. Saas Products that I Build Fast, Validate Fast, Earn Fast!