Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarioRuiz opened this issue Apr 17, 2024 · 7 comments
Open
Labels

Comments

@MarioRuiz
Copy link

MarioRuiz commented Apr 17, 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?

@dblock
Copy link
Collaborator

dblock commented Apr 17, 2024

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 dblock/slack-sup2@c7c761e.

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
Copy link
Collaborator

dblock commented Apr 17, 2024

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

@MarioRuiz
Copy link
Author

MarioRuiz commented Apr 18, 2024

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?

@dblock
Copy link
Collaborator

dblock commented Apr 18, 2024

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

@MarioRuiz
Copy link
Author

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

@dblock
Copy link
Collaborator

dblock commented Dec 18, 2024

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!

@MarioRuiz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants