support/ruby/collins-notify/lib/collins_notify/adapter/slack.rb
def notify! message_obj = OpenStruct.new, to = nil
      slack_hash = Hash.new
      channel = get_channel config.adapters[:slack], to
      slack_hash['channel'] = channel
      optional_parameters = [:username, :icon_url, :icon_emoji]
      optional_parameters.each do |op|
        if config.adapters[:slack][op]
          slack_hash[op] = config.adapters[:slack][op]
        end
      end

      slack_hash['text'] = get_message_body(binding)

      @logger.debug "slack parameters: #{slack_hash.inspect}"
        
      if config.test? then
        @logger.info "Not sending message in test mode"
        return true
      end

      begin
        @logger.debug "Posting to slack webhook: #{@webhook_url}"
        reply = HTTParty.post(@webhook_url, :body => JSON.dump(slack_hash))
        reply.response.value # this raises an error if the response said it was unsuccessful
        true
      rescue CollinsNotify::CollinsNotifyException => e
        @logger.error "error sending slack notification - #{e}"
        raise e
      rescue Exception => e
        @logger.error "#{e.class.to_s} - error sending slack notification - #{e}"
        raise CollinsNotify::CollinsNotifyException.new e
      end
    end
# Available in template binding:
# message_obj - Depends on call
# channel - channel sending to
Available in template binding:
message_obj - Depends on call
channel - channel sending to
Available in template binding : message_obj - Depends on call channel - channel sending to
def notify! message_obj = OpenStruct.new, to = nil
      slack_hash = Hash.new
      channel = get_channel config.adapters[:slack], to
      slack_hash['channel'] = channel
      optional_parameters = [:username, :icon_url, :icon_emoji]
      optional_parameters.each do |op|
        if config.adapters[:slack][op]
          slack_hash[op] = config.adapters[:slack][op]
        end
      end
      slack_hash['text'] = get_message_body(binding)
      @logger.debug "slack parameters: #{slack_hash.inspect}"
      if config.test? then
        @logger.info "Not sending message in test mode"
        return true
      end
      begin
        @logger.debug "Posting to slack webhook: #{@webhook_url}"
        reply = HTTParty.post(@webhook_url, :body => JSON.dump(slack_hash))
        reply.response.value 
        true
      rescue CollinsNotify::CollinsNotifyException => e
        @logger.error "error sending slack notification - #{e}"
        raise e
      rescue Exception => e
        @logger.error "#{e.class.to_s} - error sending slack notification - #{e}"
        raise CollinsNotify::CollinsNotifyException.new e
      end
    end
def notify! message_obj = OpenStruct . new , to = nil slack_hash = Hash . new channel = get_channel config . adapters [ :slack ] , to slack_hash [ 'channel' ] = channel optional_parameters = [ :username , :icon_url , :icon_emoji ] optional_parameters . each do | op | if config . adapters [ :slack ] [ op ] slack_hash [ op ] = config . adapters [ :slack ] [ op ] end end slack_hash [ 'text' ] = get_message_body ( binding ) @logger . debug "slack parameters: #{slack_hash.inspect}" if config . test? then @logger . info "Not sending message in test mode" return true end begin @logger . debug "Posting to slack webhook: #{@webhook_url}" reply = HTTParty . post ( @webhook_url , :body => JSON . dump ( slack_hash ) ) reply . response . value true rescue CollinsNotify :: CollinsNotifyException => e @logger . error "error sending slack notification - #{e}" raise e rescue Exception => e @logger . error "#{e.class.to_s} - error sending slack notification - #{e}" raise CollinsNotify :: CollinsNotifyException . new e end end
Available in template binding:
message_obj - Depends on call
channel - channel sending to
Available in template binding : message_obj - Depends on call channel - channel sending to
# this raises an error if the response said it was unsuccessful
message_obj
new
to