slack-ruby-client icon indicating copy to clipboard operation
slack-ruby-client copied to clipboard

classic Apps and legacy custom bots deprecated after 4th June 2024

Open MarioRuiz opened this issue 1 year ago • 8 comments

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?

MarioRuiz avatar Apr 17 '24 14:04 MarioRuiz

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.

dblock avatar Apr 17 '24 22:04 dblock

@MarioRuiz it would be nice if someone (you?) could contribute updates to this project code / README about what's being removed/deprecated.

dblock avatar Apr 17 '24 22:04 dblock

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?

MarioRuiz avatar Apr 18 '24 10:04 MarioRuiz

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).

dblock avatar Apr 18 '24 14:04 dblock

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

MarioRuiz avatar Dec 18 '24 12:12 MarioRuiz

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!

dblock avatar Dec 18 '24 14:12 dblock

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

MarioRuiz avatar Dec 20 '24 13:12 MarioRuiz

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.

hartator avatar Apr 09 '25 01:04 hartator