Skip to content

Instantly share code, notes, and snippets.

@therod
Last active August 29, 2015 14:24
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 therod/23ce3fa058c3b60c565e to your computer and use it in GitHub Desktop.
Save therod/23ce3fa058c3b60c565e to your computer and use it in GitHub Desktop.
require 'slack'
require 'curb'
Slack.configure do |config|
config.token = ENV['SLACK_TOKEN']
end
auth = Slack.auth_test
client = Slack.realtime
client.on :hello do
# Slack successfull connected ...
puts 'Successfully connected.'
end
client.on :message do |data|
welcome_text = Curl.get(ENV['TEXT_URL']).body_str
case data['text']
when 'makersbot welcome text'
private_chat = Slack.im_open user: data['user'], as_user: true
Slack.chat_postMessage channel: private_chat["channel"]["id"], text: welcome_text, as_user: true
end
end
client.on :team_join do |data|
welcome_text = Curl.get(ENV['TEXT_URL']).body_str
new_member = data["user"]["id"]
private_channel = Slack.im_open(user: new_member, as_user: true)["channel"]
Slack.chat_postMessage channel: private_channel["id"], text: welcome_text, as_user: true
end
client.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment