slack-notifier 0,0,0,2,0 editorconfig rspec travis-ci ruby Rubygems

A simple wrapper for posting to slack channels

A simple wrapper to send notifications to Slack webhooks.

Build Status Code Climate


require 'slack-notifier'

notifier = "WEBHOOK_URL" "Hello World"
# => if your webhook is setup, will message "Hello World"
# => to the default channel you set in slack


Install the latest stable release:

$ gem install slack-notifier

Or with Bundler, add it to your Gemfile:

gem 'slack-notifier'

Setting Defaults

On initialization you can set default payloads by passing an options hash.

notifier = "WEBHOOK_URL", channel: '#default',
                                              username: 'notifier' "Hello default"
# => will message "Hello default"
# => to the "#default" channel as 'notifier'

To get WEBHOOK_URL you need:

  1. go to
  2. choose your team, press configure
  3. in configurations press add configuration
  4. choose channel, press “Add Incoming WebHooks integration”

Once a notifier has been initialized, you can update the default channel and/or user.  = '#default'
notifier.username = 'notifier' "Hello default"
# => will message "Hello default"
# => to the "#default" channel as 'notifier'

These defaults are over-ridable for any individual ping. = "#default" "Hello random", channel: "#random"
# => will ping the "#random" channel


Slack requires links to be formatted a certain way, so slack-notifier will look through your message and attempt to convert any html or markdown links to slack’s format before posting.

Here’s what it’s doing under the covers:

message = "Hello world, [check]( it <a href=''>out</a>"
# => "Hello world, <|check> it <|out>"


Slack supports various different formatting options. For example, if you want to alert an entire channel you include <!channel> in your message

message = "<!channel> hey check this out" message

#ends up posting "@channel hey check this out" in your Slack channel

You can see Slack’s message documentation here


Since sequences starting with < have special meaning in Slack, you should use notifier.escape if your messages may contain &, < or >.

link_text = notifier.escape("User <[email protected]>")
message = "Write to [#{link_text}](mailto:[email protected])" message

Additional parameters

Any key passed to the ping method is posted to the webhook endpoint. Check out the Slack webhook documentation for the available parameters.

Setting an icon: "feeling spooky", icon_emoji: ":ghost:"
# or "feeling chimpy", icon_url: ""

Adding attachments:

a_ok_note = {
  fallback: "Everything looks peachy",
  text: "Everything looks peachy",
  color: "good"
} "with an attachment", attachments: [a_ok_note]

HTTP options

With the default HTTP client, you can send along options to customize its behavior as :http_options params when you ping or initialize the notifier.

notifier = 'WEBHOOK_URL', http_options: { open_timeout: 5 } "hello", http_options: { open_timeout: 10 }

Note: you should only send along options that Net::HTTP has as setters, otherwise the option will be ignored and show a warning.

Custom HTTP Client

There is a packaged default client wrapping Net::HTTP, but your HTTP needs might be a little different. In that case, you can pass in your own wrapper to handle sending the notifications. It just needs to respond to ::post with the arguments of the endpoint URI, and the payload pretty much the same as Net:HTTP.post_form.

A simple example:

module Client
  def uri, params={}
    Net::HTTP.post_form uri, params

notifier = 'WEBHOOK_URL', http_client: Client

It’s also encouraged for any custom HTTP implementations to accept the :http_options key in params.

Setting client per ping

You can also set the http_client per-ping if you need to special case certain pings. "hello", http_client: CustomClient

Setting a No-Op client

In development (or testing), you may want to watch the behavior of the notifier without posting to slack. This can be handled with a no-op client.

class NoOpHTTPClient
  def uri, params={}
    # bonus, you could log or observe posted params here

notifier = 'WEBHOOK_URL', http_client: NoOpHTTPClient


Since version 1.0 has been released, the aim is to follow Semantic Versioning as much as possible. However, it is encouraged to check the changelog when updating to see what changes have been made.

To summarize the reasoning for versioning:

Given a version number MAJOR.MINOR.PATCH, increment:

- MAJOR version when incompatible API changes are made
- MINOR version for adding functionality in a backwards-compatible manner or bug fixes that *may* change behavior
- PATCH version for make backwards-compatible bug fixes


$ rspec

There is also an integration test setup to just double check pinging across the supported rubies. To run:

  1. Copy the .env-example file to .env and replace with your details.
  2. Make sure bin/test is executable
  3. then run and watch for the pings in your slack room
$ bin/test


If there is any thing you’d like to contribute or fix, please:

  • Fork the repo
  • Add tests for any new functionality
  • Make your changes
  • Verify all new & existing tests pass
  • Make a pull request


The slack-notifier gem is distributed under the MIT License.

Related Repositories



A simple wrapper for posting to slack channels ...


slack-notify notifier ...



Receive Slack notifications for new releases of your favorite software on GitHub. ...



GoCD ( plugin to push build notifications to Slack ...



A simple php wrapper for slack notification (incomming webhook) ...

Top Contributors

stevenosloan dlackty ushu bhuga sars monkbroc razielgn siegy22 keithpitty s-osa olivierlacan patrickdavey snow waynn


-   1.5.1 zip tar
-   1.5.0 zip tar
-   1.4.0 zip tar
-   1.3.1 zip tar
-   1.3.0 zip tar
-   1.2.1 zip tar
-   1.2.0 zip tar
-   1.1.0 zip tar
-   1.0.0 zip tar
-   0.6.1 zip tar
-   0.6.0 zip tar
-   0.5.0 zip tar
-   0.4.1 zip tar
-   0.4.0 zip tar
-   0.3.2 zip tar
-   0.3.1 zip tar
-   0.3.0 zip tar
-   0.2.0 zip tar
-   0.1.1 zip tar
-   0.1.0 zip tar
-   0.0.1 zip tar