module Slackbot::Rails::ClassMethods

Public Instance Methods

bot() click to toggle source
# File lib/slackbot/rails.rb, line 11
def bot
  @bot ||= Slack::Notifier.new slackbot_rails_options[:bot][:webhook], 
                               http_options: { open_timeout: 5 }  do 
    defaults channel: '#general',
             username: 'Untitled'
  end
end
notify_bot(options = {}) click to toggle source
# File lib/slackbot/rails.rb, line 29
def notify_bot(options = {})
  begin
  cattr_accessor :slackbot_rails_options
  self.slackbot_rails_options = options
  if Slackbot::Railtie.enable_notifications && slackbot_rails_options[:message][:create].present?
    after_commit :push_create_notification_to_bot, on: :create
  end
  if Slackbot::Railtie.enable_notifications && slackbot_rails_options[:message][:update].present?
    after_commit :push_update_notification_to_bot, on: :update
  end
  rescue Exception => e
    logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
    logger.fatal "[Slackbot::Rails] #{e}"
  end          
end
push_to_bot(message) click to toggle source
# File lib/slackbot/rails.rb, line 20
def push_to_bot(message)
  begin
    bot.ping(text: message, channel: slackbot_rails_options[:bot][:channel], username: slackbot_rails_options[:bot][:name], icon_emoji: slackbot_rails_options[:bot][:icon])
  rescue Exception => e
    logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
    logger.fatal "[Slackbot::Rails] #{e}"
  end
end