classic Apps and legacy custom bots deprecated after 4th June 2024
I just got an email from Slack informing that we won't be able to create new classic Slack apps or legacy custom bots, so I guess we will not be able to use RTM, am I correct? And if I understand correctly slack-ruby-client using events is not covering everything we can do with RTM, is there any expected way to solve this?
That's correct, RTM for new bots is DOA. If you're writing a new bot today you should use events (e.g. https://github.com/slack-ruby/slack-ruby-bot-server-events and https://github.com/slack-ruby/slack-ruby-bot-server-events-app-mentions), and use this library for Web API (send messages, etc.). I wrote this about one migration and have more recently migrated https://github.com/dblock/slack-sup2 from https://github.com/dblock/slack-sup, the interesting change is https://github.com/dblock/slack-sup2/commit/c7c761e34d1864c0685f9e45aeb3c244b992b17e.
It's a ton of work for otherwise perfectly working applications. I have half a dozen, so I hate having to rework them. I am not happy Slack is removing support for RTM.
@MarioRuiz it would be nice if someone (you?) could contribute updates to this project code / README about what's being removed/deprecated.
Thanks for the response @dblock Is it possible when using events that the bot is listening to any message that is written on a channel so can response messages without using Slash (/) commands?
Is it possible when using events that the bot is listening to any message that is written on a channel so can response messages without using Slash (/) commands?
Yes, this is a basic message event (https://api.slack.com/events/message).
It seems like I cannot use Events since my bot is an internal development so it is not opened to internet. They recommend to use Sockets for that https://api.slack.com/apis/connections/socket Do you know any library that support Slack sockets functionality in ruby? @dblock
Do you know any library that support Slack sockets functionality in ruby? @dblock
I do not. If someone/you wants to contribute support here that'd be great!
I created a code that is working fine with Sockets, not much time to contribute though, I post it here if anyone want to use it
require "async"
require "async/io/stream"
require "async/http/endpoint"
require "async/websocket/client"
require "json"
require "nice_hash"
require "nice_http"
module SlackSocket
class Client
AdquisitionError = Class.new(StandardError)
ConnectionError = Class.new(StandardError)
AcknowledgeError = Class.new(StandardError)
def initialize
@token = ENV["SLACK_SOCKETS_TOKEN"]
end
def connect
http = NiceHttp.new("https://slack.com")
request = {
headers: {
Authorization: "Bearer #{@token}",
},
path: "/api/apps.connections.open",
}
connection_info = http.post(request)
http.close
result = connection_info.data.json
raise(AdquisitionError) unless result.ok
websocket = Async::HTTP::Endpoint.parse(result.url)
Async do |_i|
Async::WebSocket::Client.connect(websocket) do |connection|
payload = connection.read
raise(ConnectionError) unless connection_status(payload)
puts "Listening..."
treat(payload, connection) while (payload = connection.read)
end
end
end
private
def connection_status(payload)
payload.buffer.json.type == "hello"
end
def treat(payload, connection)
event = payload.buffer.json.payload.event
#send a post request with the envelope_id
envelope_id = payload.buffer.json.envelope_id
resp = connection.write(JSON.dump(envelope_id: envelope_id))
raise AcknowledgeError unless resp.finished
# call the bot supplying the event
#
#
end
end
end
client = SlackSocket::Client.new
client.connect
It's a ton of work for otherwise perfectly working applications. I have half a dozen, so I hate having to rework them. I am not happy Slack is removing support for RTM.
Same here. I am not happy with that change either.