Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimalistic slack bot notifier approach for rails apps - useful for capistrano deploy scripts
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../config/boot'
require_relative '../config/environment'
require 'slack'
Slack.configure do |config|
config.token = Rails.application.secrets.slack_bot[:token]
end
slack_channel = Rails.application.secrets.slack_bot[:channel]
slack_bot = Slack::Web::Client.new
slack_bot.chat_postMessage(
channel: slack_channel,
text: 'deployed successfully',
as_user: true
)
# secrets.yml
=begin
:slack_bot:
:token: 'sample_token'
:channel: '#notifications'
=end
=begin
STEPS
1. add gem 'slack-ruby-client' to Gemfile and bundle install
2. copy this to bin/slack_notifier.rb
3. chmod +x bin/slack_notifier.rb
4. set up secrets
5. bin/slack_notifier.rb
6. see your message on the slack
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.