Skip to content

Instantly share code, notes, and snippets.

@kidach1
Last active August 29, 2015 14:04
Show Gist options
  • Save kidach1/1be27171c51283065aba to your computer and use it in GitHub Desktop.
Save kidach1/1be27171c51283065aba to your computer and use it in GitHub Desktop.
[お手軽ChatOps] サーバサイドで起きた諸々の事象をSlackbotに通知してもらう ref: http://qiita.com/kidachi_/items/7f1053acb9dffc5c684d
https://slack.com/api/chat.postMessage?channel=<channel_name>&text=<text>&token=<your_token>&username=<bot_name>
require 'addressable/uri'
require 'net/http'
endpoint = 'https://slack.com/api/chat.postMessage'
token='hogehoge'
channel='#slack_bot_test'
text='hello,slackbot!'
username='slackbot'
uri = Addressable::URI.parse(endpoint)
query = {token: token, channel: channel, text: text, username: username}
uri.query_values ||= {}
uri.query_values = uri.query_values.merge(query)
Net::HTTP.get(URI.parse(uri))
=> "{\"ok\":true,\"channel\":\"C02EZTYKS\",\"ts\":\"1407134492.000010\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment