seancdavis
12/7/2015 - 12:55 PM

Post incoming webhook to Slack using Ruby

Post incoming webhook to Slack using Ruby

# Assumes:
#   - curl is installed
#   - you have a slack channel with an incoming webhook configured

require 'json'

def notify_slack(webhook_url, channel, username, text, image)
  payload = {
    :channel  => channel,
    :username => username,
    :text     => text,
    :icon_url => image
  }.to_json
  cmd = "curl -X POST --data-urlencode 'payload=#{payload}' #{webhook_url}"
  system(cmd)
end