Skip to content

Instantly share code, notes, and snippets.

@mcritchlow
Last active July 3, 2017 16:25
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 mcritchlow/d419acbdeb6f96d3d7a9a1752b49b55c to your computer and use it in GitHub Desktop.
Save mcritchlow/d419acbdeb6f96d3d7a9a1752b49b55c to your computer and use it in GitHub Desktop.
Slack Ruby Bot - Server Hooks
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'dotenv'
Dotenv.load
require 'slack_library_bot'
require 'web'
Thread.abort_on_exception = true
Thread.new do
begin
SlackLibraryBot::Server.new
SlackLibraryBot::Bot.run
rescue StandardError => e
STDERR.puts "ERROR: #{e}"
STDERR.puts e.backtrace
raise e
end
end
run SlackLibraryBot::Web
module SlackLibraryBot
class Server < SlackRubyBot::Server
on 'channel_created' do |client, data|
# general_channel = 'C04RMMCGX' general channel
general_channel = 'C62EZ1LLC' # bot-testing channel
new_channel_info = <<~CHANNEL_INFO
"Hi! <@#{data['channel']['creator']}> just created a new :slack: channel
Check it out :point_right: <##{data['channel']['id']}>"
CHANNEL_INFO
# TODO: this isn't populated. why?
if data['channel']['purpose']
new_channel_info << "\n Purpose: #{data['channel']['purpose']}"
end
client.say(channel: general_channel, text: new_channel_info)
end
end
end
require 'slack-ruby-bot'
require 'slack-library-bot/commands/ping'
require 'slack-library-bot/server'
require 'slack-library-bot/bot'
.
├── config.ru
├── Gemfile
├── Gemfile.lock
├── License
├── README.md
├── slack-library-bot
│   ├── bot.rb
│   ├── commands
│   │   └── ping.rb
│   └── server.rb
├── slack_library_bot.rb
├── spec
│   ├── slack-library-bot
│   │   ├── bot_spec.rb
│   │   └── commands
│   │   └── ping_spec.rb
│   └── spec_helper.rb
└── web.rb
5 directories, 13 files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment