Skip to content

Instantly share code, notes, and snippets.

@polamjag
Last active November 27, 2015 20:24
Show Gist options
  • Save polamjag/66783675ca14623e98ca to your computer and use it in GitHub Desktop.
Save polamjag/66783675ca14623e98ca to your computer and use it in GitHub Desktop.
Slack Incoming Webhook in Ruby
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
# param `data` will be like this (only `text` is mandatory)
# {
# channel: '#general',
# username: 'somebot',
# text: 'hello world!'
# }
def webhook(hook_url, data={})
uri = URI.parse(hook_url)
Net::HTTP.post_form(
uri,
{ payload: data.to_json }
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment