Slackbot::Rails
An activerecord hook to send notifications to slack on updations and creation of resources.
Installation
Add this line to your application's Gemfile:
gem 'slackbot-rails', :git => 'git://github.com/bitsapien/slackbot-rails.git'
And then execute:
$ bundle
Usage
Just put the notify_bot
method in your model
class Model < ActiveRecord::Base
notify_bot bot: {
webhook: '<WEBHOOK URL>',
name: '<BOT NAME>',
channel: '#channel-name'
},
message: {
create: 'A new resource in *{class.model_name.human}* was created. '}
end
This would send a notification on Slack:
Attributes inside '{}' will be evaluated on the present object of the model, for example :
It is {valid?} that the present object passed validations
would output ->
It is true that the present object passed validations
Setting Defaults
You may enable/disable notifications using a flag, for example in application.rb
config.slackbot_rails_enable = Rails.env.production?
TODO
- Specs!
- Background job option.
- Add I18n support.
- Add fallbacks for configurations.
- Add more support for emojis.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request