0.0
No commit activity in last 3 years
No release in over 3 years
Easy sending of Slack notifications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 0.13
~> 10.0
~> 3.0
 Project Readme

SlackMessenger

Gem Version

SlackMessenger is an easy-to-use gem to build and send messages via Slack's Incoming Webhooks API.

Installation

Add this line to your application's Gemfile:

gem 'slack_messenger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install slack_messenger

Usage

Basic Usage

First, setup a default API endpoint. You can create an Incoming Webhook integration on your Slack account. Use the Webhook URL provided by the integration.

SlackMessenger.configure do |config|
  config.default_api = SlackMessenger::Api.new ENV['SLACK_ENDPOINT']
  config.attachment_color = '#eeeeee' # Color of sidebar on attachments. Set to a hex value.
end

Sending a message is easy once you have an endpoint:

message = SlackMessenger::Message.new "Message Text"
message.send! # Your message is sent!

If you need further customization, you can add attachments and attachment fields to provide more information.

# Attachment Field
field = SlackMessenger::AttachmentField.new title: "New Field", value: "Field Text", short: false

# Message Attachment
attachment = SlackMessenger::Attachment.new text: "Attachment text", color: '#000000', fields: field

# Create and sent message
message = SlackMessenger::Message.new text: "Message Text", attachments: attachment
message.send!

Attachments and fields can be passed as an array or as single objects.

Multiple Endpoints

At this stage, SlackMessenger only supports one default endpoint. Optionally, when sending message, you may create and pass another Api object when sending a message. This will override the default.

message = SlackMessenger::Message.new text: "Message Text"
second_api = SlackMessenger::Api.new ENV['SECOND_ENDPOINT']

message.send! second_api # Overrides the configured default_api

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jt-platterz/slack_messenger.

License

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