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
- Firstly you need to create a Slack app from https://api.slack.com/apps. Click on the Create New App button to create a new App:
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:
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:
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
And run:
bundle install
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
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)