Class: SlackSocketModeBot::Transport::SocketModeClient
- Inherits:
-
Object
- Object
- SlackSocketModeBot::Transport::SocketModeClient
- Defined in:
- lib/transport/socket_mode_client.rb
Overview
Client responsible for instantiating a WebSocket, as well as providing a connection URL and a callback method
Instance Method Summary collapse
- #callback(*args) ⇒ Object
-
#initialize(app_token:, callback:, logger: nil) ⇒ SocketModeClient
constructor
A new instance of SocketModeClient.
- #new_socket_url ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(app_token:, callback:, logger: nil) ⇒ SocketModeClient
Returns a new instance of SocketModeClient.
8 9 10 11 12 13 14 |
# File 'lib/transport/socket_mode_client.rb', line 8 def initialize(app_token:, callback:, logger: nil) @app_token = app_token @callback = callback @logger = logger || Logger.new($stdout) @socket = WebSocket.new(client: self, logger: @logger) end |
Instance Method Details
#callback(*args) ⇒ Object
32 33 34 |
# File 'lib/transport/socket_mode_client.rb', line 32 def callback(*args) @callback.call(*args) end |
#new_socket_url ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/transport/socket_mode_client.rb', line 20 def new_socket_url response = slack_web_client.apps_connections_open raise response unless response[:ok] if ENV.fetch("ENVIRONMENT", "production").casecmp?("development") "#{response[:url]}&debug_reconnects=true" else response[:url] end end |
#run! ⇒ Object
16 17 18 |
# File 'lib/transport/socket_mode_client.rb', line 16 def run! @socket.connect! end |