slack-ruby-bot-server 0.12.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +4 -9
  3. data/.travis.yml +0 -1
  4. data/CHANGELOG.md +4 -0
  5. data/DEBUGGING.md +0 -20
  6. data/README.md +29 -81
  7. data/UPGRADING.md +14 -0
  8. data/lib/slack-ruby-bot-server.rb +3 -3
  9. data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +7 -3
  10. data/lib/slack-ruby-bot-server/api/middleware.rb +4 -5
  11. data/lib/slack-ruby-bot-server/config.rb +8 -2
  12. data/lib/slack-ruby-bot-server/ext.rb +1 -1
  13. data/lib/slack-ruby-bot-server/loggable.rb +25 -0
  14. data/lib/slack-ruby-bot-server/rspec.rb +0 -1
  15. data/lib/slack-ruby-bot-server/service.rb +7 -33
  16. data/lib/slack-ruby-bot-server/version.rb +1 -1
  17. data/public/index.html.erb +1 -1
  18. data/slack-ruby-bot-server.gemspec +2 -2
  19. data/tasks/db.rake +0 -36
  20. metadata +11 -51
  21. data/images/slackbotserver.gif +0 -0
  22. data/images/slackbutton.gif +0 -0
  23. data/lib/slack-ruby-bot-server/ext/activerecord/slack-ruby-bot/commands/base.rb +0 -18
  24. data/lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb +0 -2
  25. data/lib/slack-ruby-bot-server/ext/slack-ruby-bot/client.rb +0 -12
  26. data/lib/slack-ruby-bot-server/server.rb +0 -31
  27. data/sample_apps/README.md +0 -11
  28. data/sample_apps/sample_app_activerecord/.rspec +0 -3
  29. data/sample_apps/sample_app_activerecord/.standalone_migrations +0 -3
  30. data/sample_apps/sample_app_activerecord/Gemfile +0 -24
  31. data/sample_apps/sample_app_activerecord/Procfile +0 -1
  32. data/sample_apps/sample_app_activerecord/README.md +0 -12
  33. data/sample_apps/sample_app_activerecord/Rakefile +0 -14
  34. data/sample_apps/sample_app_activerecord/commands.rb +0 -2
  35. data/sample_apps/sample_app_activerecord/commands/help.rb +0 -19
  36. data/sample_apps/sample_app_activerecord/commands/whoami.rb +0 -6
  37. data/sample_apps/sample_app_activerecord/config.ru +0 -22
  38. data/sample_apps/sample_app_activerecord/config/newrelic.yml +0 -217
  39. data/sample_apps/sample_app_activerecord/config/postgresql.yml +0 -17
  40. data/sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb +0 -12
  41. data/sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb +0 -7
  42. data/sample_apps/sample_app_activerecord/db/schema.rb +0 -29
  43. data/sample_apps/sample_app_activerecord/spec/api/root_spec.rb +0 -16
  44. data/sample_apps/sample_app_activerecord/spec/commands/help_spec.rb +0 -14
  45. data/sample_apps/sample_app_activerecord/spec/commands/whoami_spec.rb +0 -14
  46. data/sample_apps/sample_app_activerecord/spec/spec_helper.rb +0 -19
  47. data/sample_apps/sample_app_mongoid/.rspec +0 -3
  48. data/sample_apps/sample_app_mongoid/Gemfile +0 -20
  49. data/sample_apps/sample_app_mongoid/Procfile +0 -1
  50. data/sample_apps/sample_app_mongoid/README.md +0 -14
  51. data/sample_apps/sample_app_mongoid/Rakefile +0 -10
  52. data/sample_apps/sample_app_mongoid/commands.rb +0 -2
  53. data/sample_apps/sample_app_mongoid/commands/help.rb +0 -19
  54. data/sample_apps/sample_app_mongoid/commands/whoami.rb +0 -6
  55. data/sample_apps/sample_app_mongoid/config.ru +0 -14
  56. data/sample_apps/sample_app_mongoid/config/mongoid.yml +0 -27
  57. data/sample_apps/sample_app_mongoid/config/newrelic.yml +0 -217
  58. data/sample_apps/sample_app_mongoid/spec/api/root_spec.rb +0 -16
  59. data/sample_apps/sample_app_mongoid/spec/commands/help_spec.rb +0 -14
  60. data/sample_apps/sample_app_mongoid/spec/commands/whoami_spec.rb +0 -14
  61. data/sample_apps/sample_app_mongoid/spec/spec_helper.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f3d74ad11628ec28dafca1d0ea2ac2b9119eb2d44aa5d8a9e55bbd07aad4bfa
4
- data.tar.gz: d7cd58655aae8c5f75ca23d844cdf0820d4fcb874475aad221123473333eef25
3
+ metadata.gz: 3999b9e5a783666fcf1cebfe6d07d50e0228d7a1e3c17ca52217c7677705a1c2
4
+ data.tar.gz: 6294712aae7ca330fa3c13764e369084ed7f097772e22b54e5a8c1964ec2e130
5
5
  SHA512:
6
- metadata.gz: 7ec7123d4ab6f0d7a771e473fa7de24baf8ff8d273d136c08bb105ed7088377e650b1cf1bfed821f04cf023e5dcdc24951e33d954e7cdd95af61710cfe09b7fb
7
- data.tar.gz: ea6c899f378bc4f336fcd06be80a39983ba0795371260c5262501e13dcc1c322565fdcd737acea8e433eaab56509e327ee4147c80d8d1bdc3973cd7f1b6e5bf2
6
+ metadata.gz: 17c1e6474f1a45c964d67210d96669dc4bbb5910c3571d1720916f9a13b469741d08462e6feb57185a9745ffb373164f68c88f91bbf71691313215a23264a0a5
7
+ data.tar.gz: 43c5fde5d25f993be6da99758303026ff2870b26e50435cda7bc10218ae0fea1c7a9ab321d946f62485fc59f37da845ee425804327b1a5c7a4c2575d1f9ccfd3
@@ -1,20 +1,18 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-07-17 08:36:05 -0400 using RuboCop version 0.81.0.
3
+ # on 2020-11-15 11:38:22 -0500 using RuboCop version 0.81.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 1
10
10
  # Cop supports --auto-correct.
11
11
  # Configuration parameters: EnforcedStyle.
12
12
  # SupportedStyles: squiggly, active_support, powerpack, unindent
13
13
  Layout/HeredocIndentation:
14
14
  Exclude:
15
15
  - 'lib/slack-ruby-bot-server/info.rb'
16
- - 'sample_apps/sample_app_activerecord/commands/help.rb'
17
- - 'sample_apps/sample_app_mongoid/commands/help.rb'
18
16
 
19
17
  # Offense count: 1
20
18
  Lint/AmbiguousOperator:
@@ -27,22 +25,19 @@ Lint/NonDeterministicRequireOrder:
27
25
  Exclude:
28
26
  - 'spec/spec_helper.rb'
29
27
 
30
- # Offense count: 2
28
+ # Offense count: 1
31
29
  # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
32
30
  # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
33
31
  Naming/FileName:
34
32
  Exclude:
35
33
  - 'lib/slack-ruby-bot-server.rb'
36
- - 'lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb'
37
34
 
38
- # Offense count: 3
35
+ # Offense count: 1
39
36
  # Configuration parameters: ForbiddenDelimiters.
40
37
  # ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
41
38
  Naming/HeredocDelimiterNaming:
42
39
  Exclude:
43
40
  - 'lib/slack-ruby-bot-server/info.rb'
44
- - 'sample_apps/sample_app_activerecord/commands/help.rb'
45
- - 'sample_apps/sample_app_mongoid/commands/help.rb'
46
41
 
47
42
  # Offense count: 3
48
43
  # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
@@ -31,4 +31,3 @@ before_install:
31
31
 
32
32
  script:
33
33
  - bundle exec rake
34
- - BUNDLE_GEMFILE=Gemfile && cd sample_apps/sample_app_$DATABASE_ADAPTER && bundle && bundle exec rake
@@ -1,5 +1,9 @@
1
1
  ### Changelog
2
2
 
3
+ #### 1.0.0 (2020/11/15)
4
+
5
+ * [#129](https://github.com/slack-ruby/slack-ruby-bot-server/pull/129): Extracted RealTime components into [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm) - [@dblock](https://github.com/dblock).
6
+
3
7
  #### 0.12.3 (2020/11/14)
4
8
 
5
9
  * [#123](https://github.com/slack-ruby/slack-ruby-bot-server/pull/123): Reactivate a team that was disabled from Slack - [@dblock](https://github.com/dblock).
@@ -3,23 +3,3 @@
3
3
  ### Locally
4
4
 
5
5
  You can debug your instance of slack-ruby-bot-server with a built-in `script/console`.
6
-
7
- ### Silence Mongoid Logger
8
-
9
- If Mongoid logging is annoying you.
10
-
11
- ```ruby
12
- Mongoid.logger.level = Logger::INFO
13
- Mongo::Logger.logger.level = Logger::INFO
14
- ```
15
-
16
- ### Heroku
17
-
18
- ```
19
- heroku run script/console --app=...
20
-
21
- Running `script/console` attached to terminal... up, run.7593
22
-
23
- 2.2.1 > Team.count
24
- => 3
25
- ```
data/README.md CHANGED
@@ -7,54 +7,44 @@ Slack Ruby Bot Server
7
7
 
8
8
  Build a complete Slack bot service with Slack button integration, in Ruby.
9
9
 
10
- If you are not familiar with Slack bots or Slack API concepts, you might want to watch [this video](http://code.dblock.org/2016/03/11/your-first-slack-bot-service-video.html).
11
-
12
- A good [open-source demo](https://github.com/dblock/slack-strava) of a service built on top of this library is [Strava integration with Slack](https://slava.playplay.io).
13
-
14
10
  # Table of Contents
15
11
 
16
12
  - [What is this?](#what-is-this)
17
13
  - [Stable Release](#stable-release)
18
- - [Try Me](#try-me)
19
- - [Run Your Own](#run-your-own)
14
+ - [Make Your Own](#make-your-own)
15
+ - [Storage](#storage)
20
16
  - [MongoDB](#mongodb)
21
17
  - [ActiveRecord](#activerecord)
22
18
  - [Usage](#usage)
23
- - [OAuth Code Grant](#oauth-code-grant)
24
19
  - [API](#api)
25
20
  - [App](#app)
26
21
  - [Service Manager](#service-manager)
27
22
  - [Lifecycle Callbacks](#lifecycle-callbacks)
28
23
  - [Service Timers](#service-timers)
29
24
  - [Extensions](#extensions)
30
- - [Server Class](#server-class)
31
25
  - [Service Class](#service-class)
32
26
  - [HTML Templates](#html-templates)
33
27
  - [Access Tokens](#access-tokens)
34
- - [Example Bots Using Slack Ruby Bot Server](#example-bots-using-slack-ruby-bot-server)
28
+ - [Sample Bots Using Slack Ruby Bot Server](#sample-bots-using-slack-ruby-bot-server)
29
+ - [Slack Bots with Granular Permissions](#slack-bots-with-granular-permissions)
30
+ - [Legacy Slack Bots](#legacy-slack-bots)
35
31
  - [Copyright & License](#copyright--license)
36
32
 
37
33
  ### What is this?
38
34
 
39
- A library that contains a [Grape](http://github.com/ruby-grape/grape) API serving a [Slack Ruby Bot](https://github.com/slack-ruby/slack-ruby-bot) to multiple teams. This gem combines a web server, a RESTful API and multiple instances of [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot). It integrates with the [Slack Platform API](https://medium.com/slack-developer-blog/launch-platform-114754258b91#.od3y71dyo). Your customers can use a Slack button to install the bot.
35
+ A library that contains a web server and a RESTful [Grape](http://github.com/ruby-grape/grape) API serving a Slack bot to multiple teams. Use in conjunction with [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events) to build a complete Slack bot service, or [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm) to build a Class RealTime Slack bot. Your customers can use a Slack button to install the bot.
40
36
 
41
37
  ### Stable Release
42
38
 
43
- You're reading the documentation for the **stable** release of slack-ruby-bot-server, 0.12.3. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
44
-
45
- ### Try Me
46
-
47
- A demo version of the [sample app with mongoid](sample_apps/sample_app_mongoid) is running on Heroku at [slack-ruby-bot-server.herokuapp.com](https://slack-ruby-bot-server.herokuapp.com). Use the _Add to Slack_ button. The bot will join your team as _@slackbotserver_.
39
+ You're reading the documentation for the **stable** release of slack-ruby-bot-server, v1.0.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
48
40
 
49
- ![](images/slackbutton.gif)
41
+ ### Make Your Own
50
42
 
51
- Once a bot is registered, you can invite to a channel with `/invite @slackbotserver` interact with it. DM "hi" to it, or say "@slackbotserver hi".
43
+ We recommend you get started from a [slack-ruby-bot-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample) app to bootstrap your project.
52
44
 
53
- ![](images/slackbotserver.gif)
45
+ ### Storage
54
46
 
55
- ### Run Your Own
56
-
57
- You can use one of the [sample applications](sample_apps) to bootstrap your project and start adding slack command handlers on top of this code. A database is required to store teams.
47
+ A database is required to store teams.
58
48
 
59
49
  ### MongoDB
60
50
 
@@ -67,8 +57,6 @@ gem 'mongoid-scroll'
67
57
  gem 'slack-ruby-bot-server'
68
58
  ```
69
59
 
70
- See the [sample app using Mongoid](sample_apps/sample_app_mongoid) for more information.
71
-
72
60
  ### ActiveRecord
73
61
 
74
62
  Use ActiveRecord with, for example, PostgreSQL via [pg](https://github.com/ged/ruby-pg). Configure the database connection in `postgresql.yml`. Add the `activerecord`, `pg`, `otr-activerecord` and `cursor_pagination` gems to your Gemfile.
@@ -81,11 +69,9 @@ gem 'otr-activerecord'
81
69
  gem 'cursor_pagination'
82
70
  ```
83
71
 
84
- See the [sample app using ActiveRecord](sample_apps/sample_app_activerecord) for more information.
85
-
86
72
  ### Usage
87
73
 
88
- Start with one of the samples above, which contain a couple of custom commands, necessary dependencies and tests, then [create a new Slack App](https://api.slack.com/applications/new).
74
+ Start with the [slack-ruby-bot-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample) sample, which contain a couple of custom commands, necessary dependencies and tests, then [create a new Slack App](https://api.slack.com/applications/new).
89
75
 
90
76
  ![](images/create-app.png)
91
77
 
@@ -93,40 +79,21 @@ Follow Slack's instructions, note the app client ID and secret, give the bot a d
93
79
 
94
80
  Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
95
81
 
96
- Run `bundle install` and `foreman start` to boot the app. Navigate to [localhost:9292](http://localhost:9292). You should see an "Add to Slack" button. Use it to install the app into your own Slack team.
97
-
98
- ### OAuth Code Grant
99
-
100
- The "Add to Slack" button uses the standard OAuth code grant flow as described in the [Slack docs](https://api.slack.com/docs/oauth#flow).
101
-
102
- The button itself contains a link that looks like this:
103
-
104
- ```
105
- https://slack.com/oauth/authorize?scope=bot&client_id=<%= ENV['SLACK_CLIENT_ID'] %>
106
- ```
107
-
108
- Once clicked, the user is taken through the authorization process at Slack's site. Upon successful completion, a callback containing a temporary code is sent to the redirect URL you specified. The endpoint at that URL contains code that looks like this:
82
+ Configure your app's [OAuth scopes](https://api.slack.com/legacy/oauth-scopes) as needed by your application.
109
83
 
110
84
  ```ruby
111
- # Instantiate a web client
112
- client = Slack::Web::Client.new
113
-
114
- # Request a token using the temporary code
115
- rc = client.oauth_access(
116
- client_id: ENV['SLACK_CLIENT_ID'],
117
- client_secret: ENV['SLACK_CLIENT_SECRET'],
118
- code: params[:code]
119
- )
120
-
121
- # Pluck the token from the response
122
- token = rc['bot']['bot_access_token']
85
+ SlackRubyBotServer.configure do |config|
86
+ config.oauth_scope = ['channels:read', 'chat:write:user']
87
+ end
123
88
  ```
124
89
 
125
- The token is stored in persistent storage and used each time a Slack client is instantiated for the specific team.
90
+ The "Add to Slack" button uses the standard OAuth code grant flow as described in the [Slack docs](https://api.slack.com/docs/oauth#flow). Once clicked, the user is taken through the authorization process at Slack's site. Upon successful completion, a callback containing a temporary code is sent to the redirect URL you specified. The endpoint at that URL contains code that persists the bot token each time a Slack client is instantiated for the specific team.
91
+
92
+ Run `bundle install` and `foreman start` to boot the app. Navigate to [localhost:9292](http://localhost:9292). You should see an "Add to Slack" button. Use it to install the app into your own Slack team.
126
93
 
127
94
  ### API
128
95
 
129
- This library implements an app, [SlackRubyBotServer::App](lib/slack-ruby-bot-server/app.rb), a service manager, [SlackRubyBotServer::Service](lib/slack-ruby-bot-server/service.rb) that creates multiple instances of a bot server class, [SlackRubyBotServer::Server](lib/slack-ruby-bot-server/server.rb), one per team. It also provides [default HTML templates and JS scripts](public) for Slack integration.
96
+ This library implements an app, [SlackRubyBotServer::App](lib/slack-ruby-bot-server/app.rb) and a service manager, [SlackRubyBotServer::Service](lib/slack-ruby-bot-server/service.rb). It also provides [default HTML templates and JS scripts](public) for Slack integration.
130
97
 
131
98
  #### App
132
99
 
@@ -201,7 +168,7 @@ The [Add to Slack button](https://api.slack.com/docs/slack-button) also allows f
201
168
  auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data")
202
169
  ```
203
170
  ```html
204
- <a href="https://slack.com/oauth/authorize?scope=bot&client_id=<%= ENV['SLACK_CLIENT_ID'] %>&state=#{auth)"> ... </a>
171
+ <a href="https://slack.com/oauth/authorize?scope=<%= SlackRubyBotServer::Config.oauth_scope_s %>&client_id=<%= ENV['SLACK_CLIENT_ID'] %>&state=#{auth)"> ... </a>
205
172
  ```
206
173
  ```ruby
207
174
  instance = SlackRubyBotServer::Service.instance
@@ -248,26 +215,7 @@ A number of extensions use service manager callbacks and service timers to imple
248
215
  * [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events): Easily handle Slack slash commands, interactive buttons and events.
249
216
  * [slack-ruby-bot-server-mailchimp](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp): Subscribes new bot users to a Mailchimp mailing list.
250
217
  * [slack-ruby-bot-server-stripe](https://github.com/slack-ruby/slack-ruby-bot-server-stripe): Enables paid bots with trial periods and commerce through Stripe.
251
-
252
- #### Server Class
253
-
254
- You can override the server class to handle additional events, and configure the service to use it.
255
-
256
- ```ruby
257
- class MyServer < SlackRubyBotServer::Server
258
- on :hello do |client, data|
259
- # connected to Slack
260
- end
261
-
262
- on :channel_joined do |client, data|
263
- # the bot joined a channel in data.channel['id']
264
- end
265
- end
266
-
267
- SlackRubyBotServer.configure do |config|
268
- config.server_class = MyServer
269
- end
270
- ```
218
+ * [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm): Create RTM Slack bots.
271
219
 
272
220
  #### Service Class
273
221
 
@@ -302,15 +250,16 @@ end
302
250
 
303
251
  ### Access Tokens
304
252
 
305
- By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores a `bot_access_token` as `token` that grants a certain amount of privileges to the bot user as described in [Slack OAuth Docs](https://api.slack.com/docs/oauth) along with `activated_user_access_token` that represents the token of the installing user. You may not want a bot user at all, or may require different auth scopes, such as `users.profile:read` to access user profile information via `Slack::Web::Client#users_profile_get`. To change required scopes make the following changes.
253
+ By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores the value of the token with all the requested OAuth scopes in both `token` and `activated_user_access_token` (for backwards compatibility). If a legacy Slack bot integration `bot_access_token` is present, it is stored as `token`, and `activated_user_access_token`is the token that has all the requested OAuth scopes.
254
+
255
+ ### Sample Bots Using Slack Ruby Bot Server
306
256
 
307
- 1) Configure your app to require additional scopes in Slack API under _OAuth_, _Permissions_
308
- 2) Change the _Add to Slack_ buttons to require the additional scope, eg. `https://slack.com/oauth/authorize?scope=bot,users.profile:read&client_id=...`
309
- 3) The access token with the requested scopes will be stored as `activated_user_access_token`.
257
+ #### Slack Bots with Granular Permissions
310
258
 
311
- You can see a sample implementation in [slack-sup#3a497b](https://github.com/dblock/slack-sup/commit/3a497b436d25d3a7738562655cda64b180ae0096).
259
+ * [slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample), a generic sample
260
+ * [slack-rails-bot-starter](https://github.com/CrazyOptimist/slack-rails-bot-starter), an all-in-one Rails starter kit
312
261
 
313
- ### Example Bots Using Slack Ruby Bot Server
262
+ #### Legacy Slack Bots
314
263
 
315
264
  * [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample), a generic sample
316
265
  * [slack-sup](https://github.com/dblock/slack-sup), see [sup.playplay.io](https://sup.playplay.io)
@@ -320,7 +269,6 @@ You can see a sample implementation in [slack-sup#3a497b](https://github.com/dbl
320
269
  * [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), see [api-explorer.playplay.io](https://shell.playplay.io)
321
270
  * [slack-strava](https://github.com/dblock/slack-strava), see [slava.playplay.io](https://slava.playplay.io)
322
271
  * [slack-arena](https://github.com/dblock/slack-arena), see [arena.playplay.io](https://arena.playplay.io)
323
- * [slack-rails-bot-starter](https://github.com/CrazyOptimist/slack-rails-bot-starter), an all-in-one rails starter kit built on top of the slack-ruby-bot-server and the slack-ruby-bot-server-events
324
272
 
325
273
  ### Copyright & License
326
274
 
@@ -1,6 +1,20 @@
1
1
  Upgrading Slack-Ruby-Bot-Server
2
2
  ===============================
3
3
 
4
+ ### Upgrading to >= 1.0.0
5
+
6
+ #### Extracted RealTime (Legacy) Support
7
+
8
+ New slack apps may no longer access RTM. Classic Slack apps can no longer be submitted to the app directory as of December 4th, 2020. In preparation for these changes slack-ruby-bot-server no longer includes RTM components by default. These have been extracted to a new gem [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm).
9
+
10
+ To upgrade an existing classic Slack app that uses slack-ruby-bot-server do the following.
11
+
12
+ 1. Add `slack-ruby-bot-server-rtm` as an additional dependency.
13
+ 2. Replace any reference to `SlackRubyBotServer::Server` to `SlackRubyBotServer::RealTime::Server`.
14
+ 3. Replace any `require 'slack-ruby-bot-server/rspec'` with `require 'slack-ruby-bot-server-rtm/rspec'`.
15
+
16
+ Existing RTM Slack bots will continue working and be listed in the Slack App Directory. On December 4th, 2020 Slack will no longer accept resubmissions from apps that are not using granular permissions. On November 18, 2021 Slack will start delisting apps that have not migrated to use granular permissions. Use [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events) to create a Slack bot with granular permissions. See [migration](https://api.slack.com/authentication/migration) for more details.
17
+
4
18
  ### Upgrading to >= 0.11.0
5
19
 
6
20
  #### Removed Legacy Migrations
@@ -1,10 +1,10 @@
1
- require 'async/websocket'
1
+ require 'async'
2
2
 
3
+ require 'slack-ruby-client'
3
4
  require 'grape-swagger'
4
- require 'slack-ruby-bot'
5
5
 
6
+ require_relative 'slack-ruby-bot-server/loggable'
6
7
  require_relative 'slack-ruby-bot-server/service'
7
- require_relative 'slack-ruby-bot-server/server'
8
8
  require_relative 'slack-ruby-bot-server/config'
9
9
  require_relative 'slack-ruby-bot-server/ext'
10
10
  require_relative 'slack-ruby-bot-server/version'
@@ -46,10 +46,14 @@ module SlackRubyBotServer
46
46
  code: params[:code]
47
47
  )
48
48
 
49
- token = rc['bot']['bot_access_token']
50
- bot_user_id = rc['bot']['bot_user_id']
51
- user_id = rc['user_id']
52
49
  access_token = rc['access_token']
50
+ user_id = rc['user_id']
51
+
52
+ bot = rc['bot']
53
+
54
+ token = bot ? bot['bot_access_token'] : access_token
55
+ bot_user_id = bot['bot_user_id'] if bot
56
+
53
57
  team = Team.where(token: token).first
54
58
  team ||= Team.where(team_id: rc['team_id']).first
55
59
 
@@ -6,11 +6,10 @@ require 'otr-activerecord' if SlackRubyBotServer::Config.activerecord? && !defin
6
6
  module SlackRubyBotServer
7
7
  module Api
8
8
  class Middleware
9
- def self.logger
10
- @logger ||= begin
11
- STDOUT.sync = true
12
- Logger.new(STDOUT)
13
- end
9
+ include SlackRubyBotServer::Loggable
10
+
11
+ def self.reset!
12
+ @instance = nil
14
13
  end
15
14
 
16
15
  def self.instance
@@ -2,14 +2,16 @@ module SlackRubyBotServer
2
2
  module Config
3
3
  extend self
4
4
 
5
- attr_accessor :server_class
5
+ attr_accessor :logger
6
6
  attr_accessor :service_class
7
7
  attr_accessor :database_adapter
8
8
  attr_accessor :view_paths
9
+ attr_accessor :oauth_scope
9
10
 
10
11
  def reset!
11
- self.server_class = SlackRubyBotServer::Server
12
+ self.logger = nil
12
13
  self.service_class = SlackRubyBotServer::Service
14
+ self.oauth_scope = nil
13
15
 
14
16
  self.view_paths = [
15
17
  'views',
@@ -26,6 +28,10 @@ module SlackRubyBotServer
26
28
  end
27
29
  end
28
30
 
31
+ def oauth_scope_s
32
+ oauth_scope&.join('+')
33
+ end
34
+
29
35
  def activerecord?
30
36
  database_adapter == :activerecord
31
37
  end
@@ -1,3 +1,3 @@
1
- %w[bson/object_id grape/sort_extension slack-ruby-bot].each do |ext|
1
+ %w[bson/object_id grape/sort_extension].each do |ext|
2
2
  require_relative "ext/#{ext}"
3
3
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Loggable
5
+ def self.included(base)
6
+ base.send :include, InstanceMethods
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def logger
12
+ @logger ||= SlackRubyBotServer::Config.logger || begin
13
+ $stdout.sync = true
14
+ Logger.new($stdout)
15
+ end
16
+ end
17
+ end
18
+
19
+ module InstanceMethods
20
+ def logger
21
+ self.class.logger
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,3 @@
1
- require 'slack-ruby-bot/rspec'
2
1
  require 'slack-ruby-bot-server'
3
2
  require 'fabrication'
4
3
  require 'faker'
@@ -1,6 +1,6 @@
1
1
  module SlackRubyBotServer
2
2
  class Service
3
- include SlackRubyBot::Loggable
3
+ include SlackRubyBotServer::Loggable
4
4
 
5
5
  def self.start!
6
6
  Thread.new do
@@ -47,34 +47,30 @@ module SlackRubyBotServer
47
47
  end
48
48
 
49
49
  def start!(team)
50
- run_callbacks :starting, team
51
50
  logger.info "Starting team #{team}."
52
- options = { team: team }
53
- server = SlackRubyBotServer::Config.server_class.new(options)
54
- start_server! team, server
51
+ run_callbacks :starting, team
55
52
  run_callbacks :started, team
56
- server
57
53
  rescue StandardError => e
58
54
  run_callbacks :error, team, e
59
55
  logger.error e
60
56
  end
61
57
 
62
- def restart!(team, server, wait = 1)
58
+ def restart!(team)
59
+ logger.info "Restarting team #{team}."
63
60
  run_callbacks :restarting, team
64
- start_server! team, server, wait
65
61
  run_callbacks :restarted, team
62
+ rescue StandardError => e
63
+ run_callbacks :error, team, e
64
+ logger.error e
66
65
  end
67
66
 
68
67
  def stop!(team)
69
68
  logger.info "Stopping team #{team}."
70
69
  run_callbacks :stopping, team
71
- team.server&.stop!
72
70
  run_callbacks :stopped, team
73
71
  rescue StandardError => e
74
72
  run_callbacks :error, team, e
75
73
  logger.error e
76
- ensure
77
- team.server = nil
78
74
  end
79
75
 
80
76
  def start_from_database!
@@ -98,14 +94,9 @@ module SlackRubyBotServer
98
94
  run_callbacks :deactivating, team
99
95
  team.deactivate!
100
96
  run_callbacks :deactivated, team
101
- rescue Mongoid::Errors::Validations => e
102
- run_callbacks :error, team, e
103
- logger.error "#{team.name}: #{e.message}, error - #{e.document.class}, #{e.document.errors.to_hash}, ignored."
104
97
  rescue StandardError => e
105
98
  run_callbacks :error, team, e
106
99
  logger.error "#{team.name}: #{e.class}, #{e.message}, ignored."
107
- ensure
108
- team.server = nil
109
100
  end
110
101
 
111
102
  def self.reset!
@@ -127,23 +118,6 @@ module SlackRubyBotServer
127
118
  end
128
119
  end
129
120
 
130
- def start_server!(team, server, wait = 1)
131
- team.server = server
132
- server.start_async
133
- rescue StandardError => e
134
- run_callbacks :error, team, e
135
- case e.message
136
- when 'account_inactive', 'invalid_auth' then
137
- logger.error "#{team.name}: #{e.message}, team will be deactivated."
138
- deactivate!(team)
139
- else
140
- wait = e.retry_after if e.is_a?(Slack::Web::Api::Errors::TooManyRequestsError)
141
- logger.error "#{team.name}: #{e.message}, restarting in #{wait} second(s)."
142
- sleep(wait)
143
- start_server! team, server, [wait * 2, 60].min
144
- end
145
- end
146
-
147
121
  def run_callbacks(type, team = nil, error = nil, options = {})
148
122
  callbacks = @callbacks[type.to_s]
149
123
  return false unless callbacks