Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created October 28, 2016 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/770dacc2048107e794c167fff4471605 to your computer and use it in GitHub Desktop.
Save shoyan/770dacc2048107e794c167fff4471605 to your computer and use it in GitHub Desktop.
chat.postMessage sample for Slack
require "faraday"
username = 'your name'
channel = 'your channel'
slack_token = 'your slack token'
icon_url = 'your icon url'
body = {
username: username,
channel: channel,
icon_url: icon_url,
text: "Hello world"
}
Faraday.new('https://slack.com') do |c|
c.request :url_encoded
c.adapter Faraday.default_adapter
end.post("/api/chat.postMessage?token=#{slack_token}", body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment