Created
May 16, 2014 01:53
-
-
Save nifuramu/d949445da35ab1d77794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'uri' | |
require 'net/https' | |
class Slack | |
def initialize(settings) | |
@host = settings["host"] | |
@endpoint = settings["endpoint"] | |
@token = settings["token"] | |
end | |
def send_message(message, username="kussan-bot", icon_emoji=":kussan:", channel="#develop") | |
data = { | |
type: "message", | |
subtype: "bot_message", | |
text: message, | |
username: username, | |
icon_emoji: icon_emoji, | |
channel: channel, | |
} | |
https = Net::HTTP.new(@host, 443) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
https.start do |https| | |
https.post(sprintf("%s%s", @endpoint, @token), "payload=#{data.to_json}") | |
end | |
end | |
end | |
# yaml sample | |
# slack: | |
# token: "TOKEN" | |
# host: "YOUR.slack.com" | |
# endpoint: "/services/hooks/incoming-webhook?token=" | |
settings = YAML.load_file('config/settings.yml') | |
slack = Slack.new(settings["slack"]) | |
slack.send_message('チンチンチンチンチンチンチンチンチンチンチンチンチンチンチンチン', 'おじさんbot', ':ojisan:', '#general') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment