Hook classes are now handled differently, namely they are explicitly registered into SlackRubyBot::Server
via a configuration option (hook_handlers
) or by passing a similar hash later on through the add_hook_handlers
method. Including Hook classes directly into the server class is no longer needed.
A hook is actioned via a call
message onto the handler object (this can be anything that responds to that), so you'll need to rename your method.
Finally, you can now register multiple hooks for the same event, so if you had any code to remove default hooks, you'll need to change it so you pass a configuration hash into Server
The regular expression parser for commands will now include a nil
value for expression
when an expression is not present. You can therefore no longer rely on checking match.names.include?('expression')
, instead check match['expression']
.
SlackRubyBot 0.6.x versions invoked a method called auth!
, which caused a pre-flight authentication via Slack Web API auth_test
method and collected a number of properties, such as client and team ID or name. This method has been removed in favor of using data available in the Slack::RealTime::Client
local store introduced in slack-ruby-client#54. Remove any explicit calls to this method.
While entirely compatible with the 0.5.x series, a number of methods have been deprecated and will be removed in the next release.
Prefer command
, operator
or match
with a block instead of implementing a self.call
method.
Before:
require 'slack-ruby-bot'
class Bot < SlackRubyBot::Bot
command 'ping'
def self.call(client, data, match)
...
end
end
After:
require 'slack-ruby-bot'
class Bot < SlackRubyBot::Bot
command 'ping' do |client, data, match|
...
end
end
Use client.say
instead of send_message
, send_message_with_gif
and send_gif
in commands.
Before:
class Bot < SlackRubyBot::Bot
command 'one' do |client, data, match|
send_message client, data.channel, 'Text.'
end
command 'two' do |client, data, match|
send_message_with_gif client, data.channel, "Text.", 'keyword'
end
command 'three' do |client, data, match|
send_gif client, data.channel, 'keyword'
end
end
After:
class Bot < SlackRubyBot::Bot
command 'one' do |client, data, match|
client.say(channel: data.channel, text: 'Text.')
end
command 'two' do |client, data, match|
client.say(channel: data.channel, text: 'Text.', gif: 'keyword')
end
command 'three' do |client, data, match|
client.say(channel: data.channel, gif: 'keyword')
end
end
Before:
module PongBot
class App < SlackRubyBot::App
end
class Ping < SlackRubyBot::Commands::Base
command 'ping' do |client, data, _match|
client.message(text: 'pong', channel: data.channel)
end
end
end
PongBot::App.instance.run
After:
class Bot < SlackRubyBot::Bot
command 'ping' do |client, data, _match|
client.say(text: 'pong', channel: data.channel)
end
end
Bot.run
This version uses slack-ruby-client instead of slack-ruby-gem.
The command interface now takes a client
parameter, which is the RealTime Messaging API instance. Add the new parameter to all call
calls in classes that inherit from SlackRubyBot::Commands::Base
.
Before:
def self.call(data, match)
...
end
After:
def self.call(client, data, match)
...
end
This also applies to command
, operator
and match
blocks.
Before:
command 'ping' do |data, match|
...
end
After:
command 'ping' do |client, data, match|
...
end
You can now send messages directly via the RealTime Messaging API.
client.message text: 'text', channel: 'channel'
Otherwise you must now pass the client
parameter to send_message
and send_message_with_gif
.
def self.call(client, data, match)
send_message client, data.channel, 'hello'
end
def self.call(client, data, match)
send_message_with_gif client, data.channel, 'hello', 'hi'
end