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