Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Post a message to 'alert' channel in Slack
gem 'json'
gem 'faye-websocket'
gem 'eventmachine'
gem 'slack-ruby-client'
class SlackModule
before_action :get_slack_client
require 'slack-ruby-client'
require 'json'
def post_to_alert_channel
index = 'Index'
description = 'Description'
json = JSON.generate([
color: '#ac3d54',
pretext: '',
title: 'Title',
text: '----------------------------',
fields: [
title: 'Description',
value: description,
short: false
title: 'Index',
value: index,
short: false
channel: '#alert', # To 'alert' channel
text: '@channel Alert', # the notification type is '@channel'
as_user: false,
attachments: json,
username: 'Alert Bot chan',
icon_emoji: ':warning:',
link_names: '1'
) if Rails.env.production? || Rails.env.staging?
def get_slack_client
Slack.configure do |config|
config.token = '**********'
@client =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment