DEV Community

Ahmad Raza
Ahmad Raza

Posted on

Slack Notifications in Rails 7

Wondering how to send a slack notification with your Rails App? You have come to the right place!

With the ability to send notifications to Slack, your Rails App can become even more dynamic and effective.

There are many common use cases for Slack notifications, including:

  • Keeping track of new user sign-ups
  • Monitoring system errors and exception notifications
  • Reporting real-time progress of background jobs
  • Notifying stakeholders of key events, such as a successful deployment
  • Sharing updates and changes in your project
  • Keeping the team informed of important deadlines or tasks

And many more.....

Setup the Slack App

Image description

  • Select From Scratch option in the modal/popup.

  • Type a name for your app such as: “My First App”, and select your workspace.

  • Activate Incoming Webhooks for your slack app. By clicking the following option, you'll see a page where you can activate it:

Image description

  • Click "Add New Webhook to Workspace" button at the end of the page. And select a channel where messages will be posted.

  • Copy the webhook url:

Image description

Setup Integration in Ruby on Rails

To send slack notifications, we are going to use a gem called slack-notifier.

So just add it in your Gemfile:



gem 'slack-notifier', '~> 2.4' # Change it with the latest version


Enter fullscreen mode Exit fullscreen mode

And run:



bundle install


Enter fullscreen mode Exit fullscreen mode

Now run rails c in your terminal and type:



notifier = Slack::Notifier.new "WEBHOOK_URL",
           channel: "#random",
           username: "notifier"

notifier.ping "Hello random"
# => will ping the "#random" channel


Enter fullscreen mode Exit fullscreen mode

To get more information about the gem, you can visit this url.

So go ahead and give it a try! And if you get stuck, don't hesitate to reach out.

Top comments (0)