Skip to content

Instantly share code, notes, and snippets.

@ktopolski
Created September 19, 2017 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktopolski/e21c4a7ec0af5b93303d1e4d67e9db66 to your computer and use it in GitHub Desktop.
Save ktopolski/e21c4a7ec0af5b93303d1e4d67e9db66 to your computer and use it in GitHub Desktop.
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