{"id":13647605,"url":"https://github.com/slack-notifier/slack-notifier","last_synced_at":"2026-02-11T04:01:04.618Z","repository":{"id":10457790,"uuid":"12629415","full_name":"slack-notifier/slack-notifier","owner":"slack-notifier","description":"A simple wrapper for posting to slack channels","archived":false,"fork":false,"pushed_at":"2023-04-24T07:03:26.000Z","size":204,"stargazers_count":1491,"open_issues_count":25,"forks_count":158,"subscribers_count":12,"default_branch":"main","last_synced_at":"2026-02-02T04:52:11.472Z","etag":null,"topics":["ruby","slack"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slack-notifier.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-05T21:29:45.000Z","updated_at":"2026-01-03T18:02:00.000Z","dependencies_parsed_at":"2024-05-01T13:20:14.568Z","dependency_job_id":"afba2fb0-8aeb-4292-8280-ed2a0738ba63","html_url":"https://github.com/slack-notifier/slack-notifier","commit_stats":null,"previous_names":["stevenosloan/slack-notifier"],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/slack-notifier/slack-notifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-notifier%2Fslack-notifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-notifier%2Fslack-notifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-notifier%2Fslack-notifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-notifier%2Fslack-notifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slack-notifier","download_url":"https://codeload.github.com/slack-notifier/slack-notifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-notifier%2Fslack-notifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29217757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T00:10:47.190Z","status":"online","status_checked_at":"2026-02-08T02:00:07.642Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","slack"],"created_at":"2024-08-02T01:03:40.168Z","updated_at":"2026-02-11T04:01:04.548Z","avatar_url":"https://github.com/slack-notifier.png","language":"Ruby","readme":"A simple wrapper to send notifications to [Slack](https://slack.com/) webhooks.\n\n[![Build Status](https://travis-ci.org/slack-notifier/slack-notifier.svg?branch=master)](https://travis-ci.org/slack-notifier/slack-notifier)\n[![Code Climate](https://codeclimate.com/github/slack-notifier/slack-notifier.svg)](https://codeclimate.com/github/slack-notifier/slack-notifier)\n[![Gem Version](https://badge.fury.io/rb/slack-notifier.svg)](https://rubygems.org/gems/slack-notifier)\n[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=slack-notifier\u0026package-manager=bundler\u0026version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=slack-notifier\u0026package-manager=bundler\u0026version-scheme=semver)\n\n## Example\n\n```ruby\nrequire 'slack-notifier'\n\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\"\nnotifier.ping \"Hello World\"\n# =\u003e if your webhook is setup, will message \"Hello World\"\n# =\u003e to the default channel you set in slack\n```\n\n\n#### Installation\n\nInstall the latest stable release:\n\n```\n$ gem install slack-notifier\n```\n\nOr with [Bundler](http://bundler.io/), add it to your Gemfile:\n\n```ruby\ngem \"slack-notifier\"\n```\n\n\n#### Setting Defaults\n\nOn initialization you can set default payloads by calling `defaults` in an initialization block:\n\n```ruby\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  defaults channel: \"#default\",\n           username: \"notifier\"\nend\n\nnotifier.ping \"Hello default\"\n# =\u003e will message \"Hello default\"\n# =\u003e to the \"#default\" channel as 'notifier'\n```\n\nTo get the WEBHOOK_URL you need:\n\n1. go to https://slack.com/apps/A0F7XDUAZ-incoming-webhooks\n2. choose your team, press configure\n3. in configurations press add configuration\n4. choose channel, press \"Add Incoming WebHooks integration\"\n\n\nYou can also set defaults through an options hash:\n\n```ruby\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\", channel: \"#default\",\n                                              username: \"notifier\"\n```\n\nThese defaults are over-ridable for any individual ping.\n\n```ruby\nnotifier.ping \"Hello random\", channel: \"#random\"\n# =\u003e will ping the \"#random\" channel\n```\n\n\n## Links\n\nSlack requires links to be formatted a certain way, so the default middlware stack of slack-notifier will look through your message and attempt to convert any html or markdown links to slack's format before posting.\n\nHere's what it's doing under the covers:\n\n```ruby\nmessage = \"Hello world, [check](http://example.com) it \u003ca href='http://example.com'\u003eout\u003c/a\u003e\"\nSlack::Notifier::Util::LinkFormatter.format(message)\n# =\u003e \"Hello world, \u003chttp://example.com|check\u003e it \u003chttp://example.com|out\u003e\"\n```\n\n## Formatting\n\nSlack supports various different formatting options.  For example, if you want to alert an entire channel you include `\u003c!channel\u003e` in your message\n\n```ruby\nmessage = \"\u003c!channel\u003e hey check this out\"\nnotifier.ping message\n\n#ends up posting \"@channel hey check this out\" in your Slack channel\n```\n\nYou can see [Slack's message documentation here](https://api.slack.com/docs/formatting)\n\n## Escaping\n\nSince sequences starting with \u003c have special meaning in Slack, you should use `Slack::Notifier::Util::Escape.html` if your messages may contain \u0026, \u003c or \u003e.\n\n```ruby\nlink_text = Slack::Notifier::Util::Escape.html(\"User \u003cuser@example.com\u003e\")\nmessage = \"Write to [#{link_text}](mailto:user@example.com)\"\nnotifier.ping message\n```\n\n## Blocks\n\nThis plugin supports the [Slack blocks format](https://app.slack.com/block-kit-builder/) and [block kit builder](https://app.slack.com/block-kit-builder/). This is useful for displaying buttons, dropdowns, and images.\n\n```ruby\nblocks = [\n  {\n    \"type\": \"image\",\n    \"title\": {\n      \"type\": \"plain_text\",\n      \"text\": \"image1\",\n      \"emoji\": true\n    },\n    \"image_url\": \"https://api.slack.com/img/blocks/bkb_template_images/onboardingComplex.jpg\",\n    \"alt_text\": \"image1\"\n  },\n  {\n    \"type\": \"section\",\n    \"text\": {\n      \"type\": \"mrkdwn\",\n      \"text\": \"Hey there 👋 I'm TaskBot. I'm here to help you create and manage tasks in Slack.\\nThere are two ways to quickly create tasks:\"\n    }\n  }\n]\n\nnotifier.post(blocks: blocks)\n```\n\n## Additional parameters\n\nAny key passed to the `post` method is posted to the webhook endpoint. Check out the [Slack webhook documentation](https://api.slack.com/incoming-webhooks) for the available parameters.\n\nSetting an icon:\n\n```ruby\nnotifier.post text: \"feeling spooky\", icon_emoji: \":ghost:\"\n# or\nnotifier.post text: \"feeling chimpy\", icon_url: \"http://static.mailchimp.com/web/favicon.png\"\n```\n\nAdding attachments:\n\n```ruby\na_ok_note = {\n  fallback: \"Everything looks peachy\",\n  text: \"Everything looks peachy\",\n  color: \"good\"\n}\nnotifier.post text: \"with an attachment\", attachments: [a_ok_note]\n```\n\n\n## HTTP options\n\nWith the default HTTP client, you can send along options to customize its behavior as `:http_options` params when you post or initialize the notifier.\n\n```ruby\nnotifier = Slack::Notifier.new 'WEBHOOK_URL', http_options: { open_timeout: 5 }\nnotifier.post text: \"hello\", http_options: { open_timeout: 10 }\n```\n\n**Note**: you should only send along options that [`Net::HTTP`](http://ruby-doc.org/stdlib-2.2.0/libdoc/net/http/rdoc/Net/HTTP.html) has as setters, otherwise the option will be ignored and show a warning.\n\n### Proxies\n\n`:http_options` can be used if you need to connect to Slack via an HTTP proxy.\nFor example, to connect through a local squid proxy the following options would be used.\n\n```ruby\nnotifier = Slack::Notifier.new 'WEBHOOK_URL', http_options: {\n                                                              proxy_address:  'localhost',\n                                                              proxy_port:     3128,\n                                                              proxy_from_env: false\n                                                            }\n```\n\n## Custom HTTP Client\n\nThere 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](http://ruby-doc.org/stdlib-2.1.2/libdoc/net/http/rdoc/Net/HTTP.html#method-c-post_form).\n\nA simple example:\n```ruby\nmodule Client\n  def self.post uri, params={}\n    Net::HTTP.post_form uri, params\n  end\nend\n\nnotifier = Slack::Notifier.new 'WEBHOOK_URL' do\n  http_client Client\nend\n```\n\nIt's also encouraged for any custom HTTP implementations to accept the `:http_options` key in params.\n\n**Setting client per post**\n\nYou can also set the http_client per-post if you need to special case certain pings.\n\n```ruby\nnotifier.post text: \"hello\", http_client: CustomClient\n```\n\n**Setting a No-Op client**\n\nIn 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.\n\n```ruby\nclass NoOpHTTPClient\n  def self.post uri, params={}\n    # bonus, you could log or observe posted params here\n  end\nend\n\nnotifier = Slack::Notifier.new 'WEBHOOK_URL' do\n  http_client NoOpHTTPClient\nend\n```\n\n\n## Middleware\n\nBy default slack-notifier ships with middleware to format links in the message \u0026 text field of attachments. You can configure the middleware a notifier will use on initialization:\n\n```ruby\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  middleware format_message: { formats: [:html] }\nend\n# this example will *only* use the format_message middleware and only format :html links\n\nnotifier.post text: \"Hello \u003ca href='http://example.com'\u003eworld\u003c/a\u003e! [visit this](http://example.com)\"\n# =\u003e will post \"Hello \u003chttp://example.com|world\u003e! [visit this](http://example.com)\"\n```\n\nThe middleware can be set with a their name, or by name and options. They will be triggered in order.\n\n```ruby\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  middleware :format_message, :format_attachments\nend\n# will run format_message then format_attachments with default options\n\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  middleware format_message: { formats: [:html] },\n             format_attachments: { formats: [:markdown] }\nend\n# will run format_message w/ formats [:html] then format_attachments with formats [:markdown]\n```\n\nAvailable middleware:\n\n**`format_message`**\n\nThis middleware takes the `:text` key of the payload and runs it through the [`Linkformatter`](#links). You can configure which link formats to look for with a `:formats` option. You can set `[:html]` (only html links), `[:markdown]` (only markdown links) or `[:html, :markdown]` (the default, will format both).\n\n**`format_attachments`**\n\nThis middleware takes the `:text` key of any attachment and runs it through the [`Linkformatter`](#links). You can configure which link formats to look for with a `:formats` option. You can set `[:html]` (only html links), `[:markdown]` (only markdown links) or `[:html, :markdown]` (the default, will format both).\n\n**`at`**\n\nThis simplifies the process of notifying users and rooms to messages. By adding an `:at` key to the payload w/ an array of symbols the appropriately formatted commands will be prepended to the message. It will accept a single name, or an array.\n\nFor example:\n\n```ruby\nnotifier.post text: \"hello\", at: :casper\n# =\u003e \"\u003c@casper\u003e hello\"\n\nnotifier.post text: \"hello\", at: [:here, :waldo]\n# =\u003e \"\u003c!here\u003e \u003c@waldo\u003e hello\"\n```\n\n**`channels`**\n\nIf the `channel` argument of a payload is an array this splits the payload to be posted to each channel.\n\nFor example:\n\n```ruby\nnotifier.post text: \"hello\", channel: [\"default\", \"all_the_things\"]\n# =\u003e will post \"hello\" to the default and all_the_things channel\n```\n\nTo send a message directly to a user, their username [no longer works](https://github.com/stevenosloan/slack-notifier/issues/51#issuecomment-414138622). Instead you'll need to get the user's ID and set that as the channel.\n\nAt the time of writing, one way to get a user's ID is to:\n\n- go to their profile\n- click **...** (\"More actions\")\n- click **Copy Member ID**\n\n### Writing your own Middleware\n\nMiddleware is fairly straightforward, it is any class that inherits from `Slack::Notifier::PayloadMiddleware::Base` and responds to `#call`. It will always be given the payload as a hash and should return the modified payload as a hash.\n\nFor example, lets say we want to replace words in every message, we could write a middleware like this:\n\n```ruby\nclass SwapWords \u003c Slack::Notifier::PayloadMiddleware::Base\n  middleware_name :swap_words # this is the key we use when setting\n                              # the middleware stack for a notifier\n\n  options pairs: [\"hipchat\" =\u003e \"slack\"] # the options takes a hash that will\n                                        # serve as the default if not given any\n                                        # when initialized\n\n  def call payload={}\n    return payload unless payload[:text] # noope if there is no message to work on\n\n    # not efficient, but it's an example :)\n    options[:pairs].each do |from, to|\n      payload[:text] = payload[:text].gsub from, to\n    end\n\n    payload # always return the payload from your middleware\n  end\nend\n\n\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  middleware :swap_words # setting our stack w/ just defaults\nend\nnotifier.ping \"hipchat is awesome!\"\n# =\u003e pings slack with \"slack is awesome!\"\n\nnotifier = Slack::Notifier.new \"WEBHOOK_URL\" do\n  # here we set new options for the middleware\n  middleware swap_words: { pairs: [\"hipchat\" =\u003e \"slack\",\n                                   \"awesome\" =\u003e \"really awesome\"]}\nend\n\nnotifier.ping \"hipchat is awesome!\"\n# =\u003e pings slack with \"slack is really awesome!\"\n```\n\nIf your middleware returns an array, that will split the message into multiple pings. An example for pinging multiple channels:\n\n```ruby\nclass MultiChannel \u003c Slack::Notifier::PayloadMiddleware::Base\n  middleware_name :channels\n\n  def call payload={}\n    return payload unless payload[:channel].respond_to?(:to_ary)\n\n    payload[:channel].to_ary.map do |channel|\n      pld = payload.dup\n      pld[:channel] = channel\n      pld\n    end\n  end\nend\n```\n\n\nVersioning\n----------\n\nSince version `1.0` has been released, the aim is to follow [Semantic Versioning](http://semver.org/) as much as possible. However, it is encouraged to check the [changelog](changelog.md) when updating to see what changes have been made.\n\nTo summarize the reasoning for versioning:\n\n```\nGiven a version number MAJOR.MINOR.PATCH, increment:\n\n- MAJOR version when incompatible API changes are made\n- MINOR version for adding functionality in a backwards-compatible manner or bug fixes that *may* change behavior\n- PATCH version for make backwards-compatible bug fixes\n```\n\nTesting\n-------\n\n```bash\n$ rspec\n```\n\nThere is also an integration test setup to just double check pinging across the supported rubies. To run:\n\n1. Copy the `.env-example` file to `.env` and replace with your details.\n2. Make sure `bin/test` is executable\n3. then run and watch for the pings in your slack room\n\n```bash\n$ bin/test\n```\n\n\nContributing\n------------\n\nIf there is any thing you'd like to contribute or fix, please:\n\n- Fork the repo\n- Add tests for any new functionality\n- Make your changes\n- Verify all new \u0026 existing tests pass\n- Make a pull request\n\n\nLicense\n-------\nThe slack-notifier gem is distributed under the MIT License.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-notifier%2Fslack-notifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslack-notifier%2Fslack-notifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-notifier%2Fslack-notifier/lists"}