#!/usr/bin/env ruby require 'sm' URL = ENV['SLACK_WEBHOOK_URL'] channel = ARGV.shift content = ARGV.empty? ? ARGF.read : StringIO.new(ARGV.join("\n")).read exit 0 if content.empty? username = ENV['SLACKBOT_USERNAME'] || 'slackbot' icon_emoji = ENV['SLACK_MSG_ICON_EMOJI'] || ':ghost:' begin Sm.psm(channel, content, username, icon_emoji, URL) rescue Sm::Error => e puts "Error posting to slack #{e.message}:\n#{e.backtrace.join("\n")}" end