0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
This gem make more comfortable working with slack
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16.a
~> 13.0
~> 3.0

Runtime

 Project Readme

SlackMailer

SlackMailer gem helps separate business logic from logic of message delivery. It structures code just like ActionMailer.

Installation

Add this line to your application's Gemfile:

gem 'slack_mailer'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install slack_mailer

Dependencies

Before using gem you need install sidekiq in to your project.

Configuring

Add queue for sidekiq to config/sidekiq.yml

- [slack_messages, 1]

Create configuration file config/initializers/slack_mailer.rb

Slack::Mailer::Configuration.configure do |config|
  config.templates_path = "#{Rails.root}/app/views/slack_templates/"
  config.templates_type = 'text'
  config.erb_in_templates = true
  config.slack_hook_urls = ['https://hooks.slack.com/services/...........',
                            'https://hooks.slack.com/services/...........']
end

Gem balances messages by hooks. It helps not to reach a message limit through 1 hook per 1 second.

Usage

app/slack_mailers/user_mailer.rb

class UserMailer < Slack::Mailer

  def created(user)
    @user = user
    mail(to: 'channel_name', template: 'created')
  end

end

If you want to send a message via Mailer without sidekiq

class UserMailer < Slack::Mailer

  def created(user)
    @user = user
    mail(to: 'channel_name', template: 'created', use_sidekiq: false)
  end

end

Mailer will be using template app/views/slack_templates/user_mailer/created.text.erb

Name: <%= @user.name %>
Full name: <%= @user.full_name %>
Phone: <%= @user.phone %>

Sending messages

UserMailer.created(user)

Sending small messages(one line message)

Slack::Mailer.send_message('#channel', 'name', 'message')

Sending message by passing sidekiq

Slack::Mailer.send_direct_message('#channel', 'name', 'message')

Also you can do this by using slack-notifier