Low commit activity in last 3 years
No release in over a year
A simplified Slack API for integration into Rails applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 12.3, >= 12.3.3
~> 3.8, >= 3.8.0
~> 0.93, >= 0.93.1
~> 0.16, >= 0.16.1

Runtime

 Project Readme

SlackNotification

Gem Version Build Status

This is a simplified API for sending Slack messages from (e.g.) a Rails application.

Installation

Add this line to your application's Gemfile:

gem 'slack-notification'

And then execute:

bundle

Or install it yourself as:

gem install slack-notification

Usage

SlackNotification.new(
  channel: 'channel-name-here', type: :success, title: 'Something Happened',
  fallback: "Plain-text version of the message.",
  fields: [
    { title: 'Field one', value: value_one, short: true },
    { title: 'Field two', value: value_two, short: true },
    { title: 'Longer field that needs more space.', value: value_three, short: false }
  ]
).notify!

Options:

:type     # Notification type (see below)
:dryrun   # Do not actually submit the message
:title    # Title for the message
:fallback # Plain-text version for if fields won't work
:fields   # Regular data for the message
:channel  # The channel webhook to submit to

Available notification types:

%i[success info warning failure]

Fields can be formatted in several ways:

  • String: The fields value becomes the message title, and no fields are submitted.
  • Hash: Format: { title_1: :value_1, [...] }
  • Array: Array of hashes, each of format: { title: 'Field name', value: field_value, short: true }

Configuration

Channels can be made available by setting ENV variables beginning with SLACK_URL_.

If you are using Rails credentials, .slack will take priority over ENV variables, if present.

The title field will default to ENV['SLACK_DEFAULT_TITLE'], if present.

License

The gem is available as open source under the terms of the MIT License.