Setting up your Meteor app to post to Slack


by Ry Walker

It's really easy to get your Meteor app to talk to you via Slack. Once we get things setup, posting to slack will be as easy as logging to the console:

Slack.notify "*#{Meteor.user().email()}* just signed up"

And you'll see something like this in Slack...

So let's get started...

:::

Step 1: Get webhook URL from Slack

We’re going to use Slack's web hook integration feature.

  1. Visit https://XXXXXX.slack.com/services/new/incoming-webhook
  2. Choose a channel
  3. Get the URL

:::

Step 2: A little Meteor work

We're using meteor-workers in this example to queue background work, so the API call doesn’t block the main node process on the server. FYI, you should have a background worker strategy for your Meteor app, and meteor-workers is a pretty easy way to get started.

Add Meteor  packages

  meteor add http
  meteor add differential:workers

Add code

settings.json

{
  "slack": {
    "url": "https://hooks.slack.com/services/XXXXXXXX/XXXXXX/XXXXXXXXXXXXXXXXXX"
  }
}

slack.coffee

class @Slack
  @notify: (text) ->
    if process.env.NODE_ENV is "production"
      Job.push new SlackJob text: text

slackJob.coffee

class SlackJob extends Job
  handleJob: ()->
    HTTP.post Meteor.settings.slack.url,
      data:
        channel: "#useractivity"
        username: "The App"
        text: @params.text
        icon_url: "https://usercycle.com/img/icon.png"
        link_names: 1

:::

It's that easy.

Share Share on Twitter Share on Facebook Share on LinkedIn

How Can We Help?

Reaching out doesn’t mean you’re ready to start a project, but we’d love to learn more about the challenge you’re facing, answer any questions, and see if we might be a good fit for working together.

Contact Us