Sha256: d9016bc24dee1e3c2155943c547f28016b7bab74b5da38efd8b815f2673f5af3

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# SlackNotification

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

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'slack-notification'
```

And then execute:

```sh
bundle
```

Or install it yourself as:

```sh
gem install slack-notification
```

## Usage

```ruby
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:

```ruby
: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:

```ruby
%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, the `: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](https://opensource.org/licenses/MIT).

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slack-notification-0.1.4 README.md
slack-notification-0.1.2 README.md