Last active
July 3, 2017 16:25
-
-
Save mcritchlow/d419acbdeb6f96d3d7a9a1752b49b55c to your computer and use it in GitHub Desktop.
Slack Ruby Bot - Server Hooks
This file contains 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
$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 |
This file contains 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
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 |
This file contains 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 'slack-ruby-bot' | |
require 'slack-library-bot/commands/ping' | |
require 'slack-library-bot/server' | |
require 'slack-library-bot/bot' |
This file contains 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
. | |
├── 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