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

Remove rtm.start and start_method configuration #419

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Style/Documentation:
Style/ModuleFunction:
Enabled: false

Style/NumericLiterals:
Exclude:
- 'spec/**/*'
Comment on lines +38 to +40
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the best way to disable this just for Unix timestamps so I just disabled it entirely for specs


RSpec/InstanceVariable:
Enabled: false

Expand Down
22 changes: 8 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-05-04 06:11:49 UTC using RuboCop version 1.26.1.
# on 2022-10-02 05:05:29 UTC using RuboCop version 1.26.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -93,19 +93,13 @@ RSpec/ContextMethod:
- 'spec/slack/messages/formatting_spec.rb'
- 'spec/slack/web/api/mixins/users_spec.rb'

# Offense count: 77
# Offense count: 74
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 127
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowConsecutiveOneLiners.
RSpec/EmptyLineAfterExample:
Enabled: false

# Offense count: 64
# Offense count: 63
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 18
Expand All @@ -116,13 +110,13 @@ RSpec/ExampleLength:
RSpec/FilePath:
Enabled: false

# Offense count: 65
# Offense count: 63
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 96
# Offense count: 92
RSpec/MultipleExpectations:
Max: 5

Expand All @@ -137,11 +131,11 @@ RSpec/NamedSubject:
Exclude:
- 'spec/slack/web/api/mixins/conversations_list_spec.rb'

# Offense count: 50
# Offense count: 44
RSpec/NestedGroups:
Max: 6

# Offense count: 6
# Offense count: 5
RSpec/StubbedMock:
Exclude:
- 'spec/slack/real_time/client_spec.rb'
Expand All @@ -162,7 +156,7 @@ RSpec/SubjectStub:
RSpec/VerifiedDoubleReference:
EnforcedStyle: string

# Offense count: 12
# Offense count: 10
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [#416](https://github.com/slack-ruby/slack-ruby-client/pull/416): Removes default values for Faraday's SSL settings `ca_file` and `ca_path` - [@irphilli](https://github.com/irphilli).
* [#417](https://github.com/slack-ruby/slack-ruby-client/pull/417): Raise rescuable errors - [@zachahn](https://github.com/zachahn).
* [#419](https://github.com/slack-ruby/slack-ruby-client/pull/419): Use `rtm.connect` instead of `rtm.start` - [@kstole](https://github.com/kstole).
* Your contribution here.

### 1.1.0 (2022/06/05)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ We definitely appreciate pull requests that highlight or reproduce a problem, ev

Implement your feature or bug fix.

Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ignored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.

Make sure that `bundle exec rake` completes without errors.

Expand Down
40 changes: 5 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin
- [Configuring Slack::RealTime::Client](#configuring-slackrealtimeclient)
- [Caveats](#caveats)
- [websocket_ping](#websocket_ping)
- [Connection Methods](#connection-methods)
- [Combining RealTime and Web Clients](#combining-realtime-and-web-clients)
- [Large Team Considerations](#large-team-considerations)
- [Concurrency](#concurrency)
- [Async](#async)
- [Events API](#events-api)
Expand Down Expand Up @@ -374,7 +372,7 @@ You can send a ping with `ping`.
client.ping
```

By default, the RealTime client exposes and maintains a local store with the properties of [rtm.start](https://api.slack.com/methods/rtm.start) upon a successful connection.
By default, the RealTime client exposes and maintains a local store upon a successful connection.

property | description
---------|-------------------------------------------------------------------------------------------------
Expand All @@ -393,11 +391,11 @@ Tracking with a local store can be disabled with `Slack::RealTime::Client.new(st

#### Slack::RealTime::Stores::Store

The default store that tracks all changes. By default the client will be connected using `rtm_start`.
The default store that tracks all changes.

#### Slack::RealTime::Stores::Starter

A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots. By default the client will be connected using `rtm_connect`.
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots.

### Configuring Slack::RealTime::Client

Expand All @@ -421,11 +419,10 @@ token | Slack API token.
websocket_ping | How long the socket can be idle before sending a ping message to confirm it's still connected, default is 30.
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
start_method | Optional start method, either `:rtm_start` or `:rtm_connect`.
start_options | Options to pass into `rtm.start` or `rtm.connect`, default is `{ request: { timeout: 180 } }`.
start_options | Options to pass to `rtm.connect`, default is `{ request: { timeout: 180 } }`.
logger | Optional `Logger` instance that logs RealTime requests and socket data.

Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.connect](https://api.slack.com/methods/rtm.connect). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.

See a fully working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).

Expand All @@ -442,16 +439,6 @@ Note that the ping may take between `websocket_ping` and `websocket_ping * 3/2`

To disable this feature set `websocket_ping` to 0.

### Connection Methods

The RealTime client uses either [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect) to open a connection. The former retrieves a lot of team information while the latter only serves connection purposes and is preferred. You should let the library choose the right method for you based on the `store_class` used and override this behavior with `start_method` when necessary.

```ruby
Slack::RealTime::Client.configure do |config|
config.start_method = :rtm_start
end
```

### Combining RealTime and Web Clients

Since the Web client is used to obtain the RealTime client's WebSocket URL, you can continue using the Web client in combination with the RealTime client.
Expand All @@ -475,23 +462,6 @@ See a fully working example in [examples/hi_real_time_and_web](examples/hi_real_

![](examples/hi_real_time_and_web/hi.gif)

### Large Team Considerations

The `rtm.start` call downloads a large amount of data. For large teams, consider reducing the amount of unnecessary data downloaded with `start_options`. You may also want to increase the default timeout of 180 seconds.

```ruby
Slack::RealTime::Client.configure do |config|
# Return timestamp only for latest message object of each channel.
config.start_options[:simple_latest] = true
# Skip unread counts for each channel.
config.start_options[:no_unreads] = true
# Increase request timeout to 6 minutes.
config.start_options[:request][:timeout] = 360
end
```

See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a discussion on this topic.

#### Concurrency

`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async).
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ or
client = Slack::Web::Client.new(ca_file: OpenSSL::X509::DEFAULT_CERT_FILE, ca_path: OpenSSL::X509::DEFAULT_CERT_DIR)
```

Slack has deprecated the `rtm.start` method and replaced its response with that of `rtm.connect`, so it has been removed from the library along with the `start_method` configuration.

### Upgrading to >= 1.0.0

#### Deprecated Methods
Expand Down
15 changes: 0 additions & 15 deletions bin/commands/rtm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,4 @@
puts JSON.dump($client.rtm_connect(options))
end
end

g.desc 'Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead.'
g.long_desc %( Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead. )
g.command 'start' do |c|
c.flag 'batch_presence_aware', desc: 'Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. See batch presence.'
c.flag 'include_locale', desc: 'Set this to true to receive the locale for users and channels. Defaults to false.'
c.flag 'mpim_aware', desc: 'Returns MPIMs to the client in the API response.'
c.flag 'no_latest', desc: 'Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1.'
c.flag 'no_unreads', desc: 'Skip unread counts for each channel (improves performance).'
c.flag 'presence_sub', desc: 'Only deliver presence events when requested by subscription. See presence subscriptions.'
c.flag 'simple_latest', desc: 'Return timestamp only for latest message object of each channel (improves performance).'
c.action do |_global_options, options, _args|
puts JSON.dump($client.rtm_start(options))
end
end
end
14 changes: 2 additions & 12 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def to_s
def restart_async
logger.debug("#{self}##{__method__}")
@socket.close
start = web_client.send(rtm_start_method, start_options)
start = web_client.rtm_connect(start_options)
data = Slack::Messages::Message.new(start)
@url = data.url
@store = @store_class.new(data) if @store_class
Expand All @@ -173,23 +173,13 @@ def restart_async
def build_socket
raise ClientAlreadyStartedError if started?

start = web_client.send(rtm_start_method, start_options)
start = web_client.rtm_connect(start_options)
data = Slack::Messages::Message.new(start)
@url = data.url
@store = @store_class.new(data) if @store_class
@socket = socket_class.new(@url, socket_options)
end

def rtm_start_method
if start_method
start_method
elsif @store_class && @store_class <= Slack::RealTime::Stores::Store
:rtm_start
else
:rtm_connect
end
end

def socket_options
socket_options = {}
socket_options[:ping] = websocket_ping if websocket_ping
Expand Down
23 changes: 0 additions & 23 deletions lib/slack/web/api/endpoints/rtm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ module Rtm
def rtm_connect(options = {})
post('rtm.connect', options)
end

#
# Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead.
#
# @option options [boolean] :batch_presence_aware
# Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. See batch presence.
# @option options [boolean] :include_locale
# Set this to true to receive the locale for users and channels. Defaults to false.
# @option options [boolean] :mpim_aware
# Returns MPIMs to the client in the API response.
# @option options [boolean] :no_latest
# Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1.
# @option options [boolean] :no_unreads
# Skip unread counts for each channel (improves performance).
# @option options [boolean] :presence_sub
# Only deliver presence events when requested by subscription. See presence subscriptions.
# @option options [boolean] :simple_latest
# Return timestamp only for latest message object of each channel (improves performance).
# @see https://api.slack.com/methods/rtm.start
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/rtm/rtm.start.json
def rtm_start(options = {})
post('rtm.start', options)
end
end
end
end
Expand Down
86 changes: 85 additions & 1 deletion spec/fixtures/slack/web/rtm_connect.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading