slack-ruby-bot-server 0.11.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +1 -1
  4. data/.rubocop_todo.yml +45 -13
  5. data/.travis.yml +7 -6
  6. data/CHANGELOG.md +49 -22
  7. data/DEBUGGING.md +0 -20
  8. data/Dangerfile +1 -0
  9. data/Gemfile +3 -2
  10. data/LICENSE +1 -1
  11. data/README.md +106 -52
  12. data/UPGRADING.md +14 -0
  13. data/images/create-app.png +0 -0
  14. data/lib/slack-ruby-bot-server.rb +11 -13
  15. data/lib/slack-ruby-bot-server/api.rb +4 -4
  16. data/lib/slack-ruby-bot-server/api/endpoints.rb +3 -3
  17. data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +11 -3
  18. data/lib/slack-ruby-bot-server/api/helpers.rb +4 -4
  19. data/lib/slack-ruby-bot-server/api/helpers/cursor_helpers.rb +2 -0
  20. data/lib/slack-ruby-bot-server/api/helpers/sort_helpers.rb +1 -0
  21. data/lib/slack-ruby-bot-server/api/middleware.rb +5 -10
  22. data/lib/slack-ruby-bot-server/api/presenters.rb +5 -5
  23. data/lib/slack-ruby-bot-server/api/presenters/status_presenter.rb +1 -0
  24. data/lib/slack-ruby-bot-server/config.rb +16 -2
  25. data/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb +2 -2
  26. data/lib/slack-ruby-bot-server/config/database_adapters/mongoid.rb +4 -2
  27. data/lib/slack-ruby-bot-server/ext.rb +1 -1
  28. data/lib/slack-ruby-bot-server/ext/mongoid/slack-ruby-bot/commands/base.rb +2 -2
  29. data/lib/slack-ruby-bot-server/loggable.rb +25 -0
  30. data/lib/slack-ruby-bot-server/models/team/activerecord.rb +8 -5
  31. data/lib/slack-ruby-bot-server/models/team/methods.rb +12 -0
  32. data/lib/slack-ruby-bot-server/models/team/mongoid.rb +8 -4
  33. data/lib/slack-ruby-bot-server/rspec.rb +0 -1
  34. data/lib/slack-ruby-bot-server/service.rb +48 -32
  35. data/lib/slack-ruby-bot-server/version.rb +1 -1
  36. data/public/index.html.erb +2 -1
  37. data/public/scripts/messages.js +33 -0
  38. data/public/scripts/register.js +0 -31
  39. data/slack-ruby-bot-server.gemspec +3 -3
  40. data/tasks/db.rake +0 -36
  41. metadata +19 -57
  42. data/images/new.png +0 -0
  43. data/images/slackbotserver.gif +0 -0
  44. data/images/slackbutton.gif +0 -0
  45. data/lib/slack-ruby-bot-server/ext/activerecord/slack-ruby-bot/commands/base.rb +0 -18
  46. data/lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb +0 -2
  47. data/lib/slack-ruby-bot-server/ext/slack-ruby-bot/client.rb +0 -12
  48. data/lib/slack-ruby-bot-server/server.rb +0 -30
  49. data/sample_apps/README.md +0 -11
  50. data/sample_apps/sample_app_activerecord/.rspec +0 -3
  51. data/sample_apps/sample_app_activerecord/.standalone_migrations +0 -3
  52. data/sample_apps/sample_app_activerecord/Gemfile +0 -24
  53. data/sample_apps/sample_app_activerecord/Procfile +0 -1
  54. data/sample_apps/sample_app_activerecord/README.md +0 -11
  55. data/sample_apps/sample_app_activerecord/Rakefile +0 -14
  56. data/sample_apps/sample_app_activerecord/commands.rb +0 -2
  57. data/sample_apps/sample_app_activerecord/commands/help.rb +0 -19
  58. data/sample_apps/sample_app_activerecord/commands/whoami.rb +0 -6
  59. data/sample_apps/sample_app_activerecord/config.ru +0 -22
  60. data/sample_apps/sample_app_activerecord/config/newrelic.yml +0 -217
  61. data/sample_apps/sample_app_activerecord/config/postgresql.yml +0 -17
  62. data/sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb +0 -12
  63. data/sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb +0 -7
  64. data/sample_apps/sample_app_activerecord/db/schema.rb +0 -29
  65. data/sample_apps/sample_app_activerecord/spec/api/root_spec.rb +0 -16
  66. data/sample_apps/sample_app_activerecord/spec/commands/help_spec.rb +0 -14
  67. data/sample_apps/sample_app_activerecord/spec/commands/whoami_spec.rb +0 -14
  68. data/sample_apps/sample_app_activerecord/spec/spec_helper.rb +0 -19
  69. data/sample_apps/sample_app_mongoid/.rspec +0 -3
  70. data/sample_apps/sample_app_mongoid/Gemfile +0 -20
  71. data/sample_apps/sample_app_mongoid/Procfile +0 -1
  72. data/sample_apps/sample_app_mongoid/README.md +0 -14
  73. data/sample_apps/sample_app_mongoid/Rakefile +0 -10
  74. data/sample_apps/sample_app_mongoid/commands.rb +0 -2
  75. data/sample_apps/sample_app_mongoid/commands/help.rb +0 -19
  76. data/sample_apps/sample_app_mongoid/commands/whoami.rb +0 -6
  77. data/sample_apps/sample_app_mongoid/config.ru +0 -14
  78. data/sample_apps/sample_app_mongoid/config/mongoid.yml +0 -27
  79. data/sample_apps/sample_app_mongoid/config/newrelic.yml +0 -217
  80. data/sample_apps/sample_app_mongoid/spec/api/root_spec.rb +0 -16
  81. data/sample_apps/sample_app_mongoid/spec/commands/help_spec.rb +0 -14
  82. data/sample_apps/sample_app_mongoid/spec/commands/whoami_spec.rb +0 -14
  83. 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: 34d650b165e330149dfc1e8a0045660f9e2dbb3440d504c188496d90f5c25ac6
4
- data.tar.gz: b29fdf9948bdccddc4bd5a08a0b0cbb701fb0aab40f03ed836d9fd438a67e9fc
3
+ metadata.gz: 3999b9e5a783666fcf1cebfe6d07d50e0228d7a1e3c17ca52217c7677705a1c2
4
+ data.tar.gz: 6294712aae7ca330fa3c13764e369084ed7f097772e22b54e5a8c1964ec2e130
5
5
  SHA512:
6
- metadata.gz: a45158dd0b039e8d4fa70b565303c989f171594d021b60d8e00eb174ecc9c3073c535ba01f7a707e5b763a40db8e14b0cb4bc2adf397b7bdcc1fee25a72d7741
7
- data.tar.gz: 3c6eeca00c91392fc41168688593052f51ad1b342427f13ab250f6b56f8fcb9924d751c11c1ed38571033479cbe975e371563e960cdb7d603eed6011d8cc4314
6
+ metadata.gz: 17c1e6474f1a45c964d67210d96669dc4bbb5910c3571d1720916f9a13b469741d08462e6feb57185a9745ffb373164f68c88f91bbf71691313215a23264a0a5
7
+ data.tar.gz: 43c5fde5d25f993be6da99758303026ff2870b26e50435cda7bc10218ae0fea1c7a9ab321d946f62485fc59f37da845ee425804327b1a5c7a4c2575d1f9ccfd3
@@ -0,0 +1 @@
1
+ github: [dblock]
@@ -1,7 +1,7 @@
1
1
  Metrics:
2
2
  Enabled: false
3
3
 
4
- Metrics/LineLength:
4
+ Layout/LineLength:
5
5
  Max: 500
6
6
  Enabled: false
7
7
 
@@ -1,34 +1,66 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-03-23 14:16:02 -0400 using RuboCop version 0.58.2.
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
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
- Layout/IndentHeredoc:
12
+ # SupportedStyles: squiggly, active_support, powerpack, unindent
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
- # Offense count: 3
20
- # Configuration parameters: Blacklist.
21
- # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
17
+ # Offense count: 1
18
+ Lint/AmbiguousOperator:
19
+ Exclude:
20
+ - 'spec/slack-ruby-bot-server/service_spec.rb'
21
+
22
+ # Offense count: 2
23
+ # Cop supports --auto-correct.
24
+ Lint/NonDeterministicRequireOrder:
25
+ Exclude:
26
+ - 'spec/spec_helper.rb'
27
+
28
+ # Offense count: 1
29
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
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
31
+ Naming/FileName:
32
+ Exclude:
33
+ - 'lib/slack-ruby-bot-server.rb'
34
+
35
+ # Offense count: 1
36
+ # Configuration parameters: ForbiddenDelimiters.
37
+ # ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
22
38
  Naming/HeredocDelimiterNaming:
23
39
  Exclude:
24
40
  - 'lib/slack-ruby-bot-server/info.rb'
25
- - 'sample_apps/sample_app_activerecord/commands/help.rb'
26
- - 'sample_apps/sample_app_mongoid/commands/help.rb'
41
+
42
+ # Offense count: 3
43
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
44
+ # AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
45
+ Naming/MethodParameterName:
46
+ Exclude:
47
+ - 'lib/slack-ruby-bot-server/models/team/activerecord.rb'
48
+ - 'lib/slack-ruby-bot-server/models/team/mongoid.rb'
49
+ - 'lib/slack-ruby-bot-server/service.rb'
27
50
 
28
51
  # Offense count: 1
29
52
  # Cop supports --auto-correct.
30
- # Configuration parameters: EnforcedStyle.
31
- # SupportedStyles: module_function, extend_self
53
+ # Configuration parameters: EnforcedStyle, Autocorrect.
54
+ # SupportedStyles: module_function, extend_self, forbidden
32
55
  Style/ModuleFunction:
33
56
  Exclude:
34
57
  - 'lib/slack-ruby-bot-server/config.rb'
58
+
59
+ # Offense count: 1
60
+ # Cop supports --auto-correct.
61
+ # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
62
+ # SupportedStyles: predicate, comparison
63
+ Style/NumericPredicate:
64
+ Exclude:
65
+ - 'spec/**/*'
66
+ - 'lib/slack-ruby-bot-server/service.rb'
@@ -4,24 +4,26 @@ cache: bundler
4
4
 
5
5
  matrix:
6
6
  include:
7
- - rvm: 2.3.1
7
+ - rvm: 2.6.2
8
8
  script:
9
9
  - bundle exec danger
10
- - rvm: 2.3.1
10
+ services:
11
+ - xvfb
12
+ - rvm: 2.6.2
11
13
  env: DATABASE_ADAPTER=activerecord
12
14
  services:
15
+ - xvfb
13
16
  - postgresql
14
- - rvm: 2.3.1
17
+ - rvm: 2.6.2
15
18
  env: DATABASE_ADAPTER=mongoid
16
19
  services:
20
+ - xvfb
17
21
  - mongodb
18
22
 
19
23
  addons:
20
24
  firefox: 54.0
21
25
 
22
26
  before_install:
23
- - export DISPLAY=:99.0
24
- - sh -e /etc/init.d/xvfb start
25
27
  - wget https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz
26
28
  - mkdir geckodriver
27
29
  - tar -xzf geckodriver-v0.18.0-linux64.tar.gz -C geckodriver
@@ -29,4 +31,3 @@ before_install:
29
31
 
30
32
  script:
31
33
  - bundle exec rake
32
- - BUNDLE_GEMFILE=Gemfile && cd sample_apps/sample_app_$DATABASE_ADAPTER && bundle && bundle exec rake
@@ -1,20 +1,47 @@
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
+
7
+ #### 0.12.3 (2020/11/14)
8
+
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).
10
+ * [#127](https://github.com/slack-ruby/slack-ruby-bot-server/pull/127): Added a Rails bot example link - [@CrazyOptimist](https://github.com/CrazyOptimist).
11
+
12
+ #### 0.12.2 (2020/7/26)
13
+
14
+ * [#120](https://github.com/slack-ruby/slack-ruby-bot-server/pull/120): Removed GIFs - [@dblock](https://github.com/dblock).
15
+ * [#121](https://github.com/slack-ruby/slack-ruby-bot-server/pull/121): Added TOC - [@dblock](https://github.com/dblock).
16
+
17
+ #### 0.12.1 (2020/5/16)
18
+
19
+ * [#118](https://github.com/slack-ruby/slack-ruby-bot-server/pull/118): Do not fail to start on errors in `Team#purge!` - [@dblock](https://github.com/dblock).
20
+
21
+ #### 0.12.0 (2020/4/26)
22
+
23
+ * [#113](https://github.com/slack-ruby/slack-ruby-bot-server/pull/113): Added support for intervals with `.every` - [@dblock](https://github.com/dblock).
24
+ * [#112](https://github.com/slack-ruby/slack-ruby-bot-server/pull/112): Added support for multiple `.on` events as an argument - [@dblock](https://github.com/dblock).
25
+ * [#111](https://github.com/slack-ruby/slack-ruby-bot-server/pull/111): Removed dependency on Virtus - [@dblock](https://github.com/dblock).
26
+ * [#110](https://github.com/slack-ruby/slack-ruby-bot-server/pull/110): Fixed ActiveRecord sample app - [@CeeBeeUK](https://github.com/CeeBeeUK).
27
+ * [#114](https://github.com/slack-ruby/slack-ruby-bot-server/pull/114): Used `require_relative` to prevent local collisions - [@dblock](https://github.com/dblock).
28
+ * [#115](https://github.com/slack-ruby/slack-ruby-bot-server/pull/115): Added `Config#view_paths` to be used by Rack middleware - [@dblock](https://github.com/dblock).
29
+
3
30
  #### 0.11.1 (2019/5/17)
4
31
 
5
- * [#104](https://github.com/slack-ruby/slack-ruby-bot-server/pull/104): Lock async-websocket at a compatible 0.8.0 version - [@dblock](https://github.com/dblock).
32
+ * [#104](https://github.com/slack-ruby/slack-ruby-bot-server/pull/104): Locked async-websocket at a compatible 0.8.0 version - [@dblock](https://github.com/dblock).
6
33
 
7
34
  #### 0.11.0 (2019/4/12)
8
35
 
9
36
  * [#101](https://github.com/slack-ruby/slack-ruby-bot-server/pull/101): Removed legacy migrations, including `SLACK_API_TOKEN`, team `name`, `team_id` and `active` - [@dblock](https://github.com/dblock).
10
37
  * [#98](https://github.com/slack-ruby/slack-ruby-bot-server/pull/98): Removed `unicorn` from gem dependencies - [@dblock](https://github.com/dblock).
11
- * [#90](https://github.com/slack-ruby/slack-ruby-bot-server/pull/90): Update ActiveRecord sample app to support ENV variables in `postgresql.yml` - [@ashkan18](https://github.com/ashkan18).
38
+ * [#90](https://github.com/slack-ruby/slack-ruby-bot-server/pull/90): Updated ActiveRecord sample app to support ENV variables in `postgresql.yml` - [@ashkan18](https://github.com/ashkan18).
12
39
 
13
40
  #### 0.10.0 (2019/3/23)
14
41
 
15
42
  * [#97](https://github.com/slack-ruby/slack-ruby-bot-server/pull/97): Added `Config#service_class` to override the `SlackRubyBotServer::Service.instance` singleton - [@dblock](https://github.com/dblock).
16
43
  * [#96](https://github.com/slack-ruby/slack-ruby-bot-server/pull/96): Added `Team#bot_user_id`, `activated_user_id` and `activated_user_access_token` - [@dblock](https://github.com/dblock).
17
- * [#95](https://github.com/slack-ruby/slack-ruby-bot-server/pull/95): Expose the optional `state` parameter that is returned from the Add to Slack button - [@aok-solutions](https://github.com/aok-solutions).
44
+ * [#95](https://github.com/slack-ruby/slack-ruby-bot-server/pull/95): Exposed the optional `state` parameter that is returned from the Add to Slack button - [@aok-solutions](https://github.com/aok-solutions).
18
45
 
19
46
  #### 0.9.0 (2019/2/25)
20
47
 
@@ -22,31 +49,31 @@
22
49
 
23
50
  #### 0.8.3 (2019/1/17)
24
51
 
25
- * [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88): Fix: compatibility with Grape 1.2.x - [@dblock](https://github.com/dblock).
52
+ * [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88): Fixed compatibility with Grape 1.2.x - [@dblock](https://github.com/dblock).
26
53
 
27
54
  #### 0.8.2 (2018/10/11)
28
55
 
29
- * [#80](https://github.com/slack-ruby/slack-ruby-bot-server/pull/80): Fix: closed stream when closing connection in ping worker - [@dblock](https://github.com/dblock).
56
+ * [#80](https://github.com/slack-ruby/slack-ruby-bot-server/pull/80): Fixed closed stream when closing connection in ping worker - [@dblock](https://github.com/dblock).
30
57
 
31
58
  #### 0.8.1 (2018/9/20)
32
59
 
33
- * [#79](https://github.com/slack-ruby/slack-ruby-bot-server/pull/79): Fix: ping worker terminates on a failed restart - [@dblock](https://github.com/dblock).
60
+ * [#79](https://github.com/slack-ruby/slack-ruby-bot-server/pull/79): Fixed ping worker terminates on a failed restart - [@dblock](https://github.com/dblock).
34
61
 
35
62
  #### 0.8.0 (2018/9/8)
36
63
 
37
- * [#75](https://github.com/slack-ruby/slack-ruby-bot-server/pull/75): Default to `async-websocket` instead of `celluloid-io` - [@dblock](https://github.com/dblock).
38
- * [#76](https://github.com/slack-ruby/slack-ruby-bot-server/pull/76): Adjust wait time on restart on Slack::Web::Api::Errors::TooManyRequestsError - [@dblock](https://github.com/dblock).
64
+ * [#75](https://github.com/slack-ruby/slack-ruby-bot-server/pull/75): Defaulted to `async-websocket` instead of `celluloid-io` - [@dblock](https://github.com/dblock).
65
+ * [#76](https://github.com/slack-ruby/slack-ruby-bot-server/pull/76): Adjusted wait time on restart on Slack::Web::Api::Errors::TooManyRequestsError - [@dblock](https://github.com/dblock).
39
66
 
40
67
  #### 0.7.0 (2018/8/22)
41
68
 
42
- * [#60](https://github.com/slack-ruby/slack-ruby-bot-server/pull/60): Log caught Standard::Error backtrace at debug-level - [@alexagranov](https://github.com/alexagranov).
69
+ * [#60](https://github.com/slack-ruby/slack-ruby-bot-server/pull/60): Logged caught Standard::Error backtrace at debug-level - [@alexagranov](https://github.com/alexagranov).
43
70
  * [#65](https://github.com/slack-ruby/slack-ruby-bot-server/pull/65): Updated Capybara and selenium-webdriver - [@dblock](https://github.com/dblock).
44
71
  * [#67](https://github.com/slack-ruby/slack-ruby-bot-server/pull/67): Only load the OTR::ActiveRecord::ConnectionManagement middleware when the OTR module is included. This module isn't needed when using Rails - [@darbyfrey](https://github.com/darbyfrey).
45
72
  * [#74](https://github.com/slack-ruby/slack-ruby-bot-server/pull/74): Added ping worker, will restart offline bots - [@dblock](https://github.com/dblock).
46
73
 
47
74
  #### 0.6.1 (2017/3/29)
48
75
 
49
- * [#54](https://github.com/slack-ruby/slack-ruby-bot-server/pull/54): Removing one more Mongoid dependency when rescuing from _invoke - [@alexagranov](https://github.com/alexagranov).
76
+ * [#54](https://github.com/slack-ruby/slack-ruby-bot-server/pull/54): Removed one more Mongoid dependency when rescuing from _invoke - [@alexagranov](https://github.com/alexagranov).
50
77
  * [#53](https://github.com/slack-ruby/slack-ruby-bot-server/pull/53): No need for `otr-activerecord` if using activerecord under Rails - [@alexagranov](https://github.com/alexagranov).
51
78
 
52
79
  #### 0.6.0 (2017/3/12)
@@ -57,17 +84,17 @@
57
84
 
58
85
  #### 0.5.0 (2017/2/9)
59
86
 
60
- * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fix: `cannot load kaminari/grape` - [@dblock](https://github.com/dblock).
61
- * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fix: `undefined method '[]' for nil:NilClass` in APIs - [@dblock](https://github.com/dblock).
62
- * [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28): Use slack-ruby-danger gem - [@dblock](https://github.com/dblock).
63
- * [#31](https://github.com/slack-ruby/slack-ruby-bot-server/pull/31): Adds MONGODB_URI as environment variable for MongoDB - [@corprew](https://github.com/corprew).
87
+ * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fixed `cannot load kaminari/grape` - [@dblock](https://github.com/dblock).
88
+ * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fixed `undefined method '[]' for nil:NilClass` in APIs - [@dblock](https://github.com/dblock).
89
+ * [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28): Used `slack-ruby-danger` gem - [@dblock](https://github.com/dblock).
90
+ * [#31](https://github.com/slack-ruby/slack-ruby-bot-server/pull/31): Added `MONGODB_URI` as environment variable for MongoDB - [@corprew](https://github.com/corprew).
64
91
 
65
92
  #### 0.4.0 (2016/8/29)
66
93
 
67
94
  * [#25](https://github.com/slack-ruby/slack-ruby-bot-server/pull/25): Added [danger](http://danger.systems), PR linting - [@dblock](https://github.com/dblock).
68
95
  * The `reset` and `resetting` callbacks have been removed - [@dblock](https://github.com/dblock).
69
96
  * Callbacks receive `team` and `error`, but no longer `server` - [@dblock](https://github.com/dblock).
70
- * [#23](https://github.com/slack-ruby/slack-ruby-bot-server/issues/23): Fix: server-side removal of bot doesn't deactivate it - [@dblock](https://github.com/dblock).
97
+ * [#23](https://github.com/slack-ruby/slack-ruby-bot-server/issues/23): Fixed server-side removal of bot doesn't deactivate it - [@dblock](https://github.com/dblock).
71
98
 
72
99
  #### 0.3.1 (2016/7/10)
73
100
 
@@ -91,13 +118,13 @@
91
118
 
92
119
  * Initial public release - [@dblock](https://github.com/dblock).
93
120
  * Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
94
- * [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turn project into gem - [@tmsrjs](https://github.com/tmsrjs).
95
- * Use `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
121
+ * [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turned project into gem - [@tmsrjs](https://github.com/tmsrjs).
122
+ * Used `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
96
123
  * Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
97
- * Use Grape 0.15.x - [@dblock](https://github.com/dblock).
124
+ * Used Grape 0.15.x - [@dblock](https://github.com/dblock).
98
125
  * Removed OOB GC - [@dblock](https://github.com/dblock).
99
- * Use Unicorn instead of Puma - [@dblock](https://github.com/dblock).
100
- * Fix: wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
101
- * Use an OOB GC - [@dblock](https://github.com/dblock).
102
- * Defer start, much faster - [@dblock](https://github.com/dblock).
126
+ * Used Unicorn instead of Puma - [@dblock](https://github.com/dblock).
127
+ * Fixed wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
128
+ * Used an OOB GC - [@dblock](https://github.com/dblock).
129
+ * Deferred start, much faster - [@dblock](https://github.com/dblock).
103
130
  * Backported changes from slack-metabot and slack-shellbot - [@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/Dangerfile CHANGED
@@ -1 +1,2 @@
1
1
  danger.import_dangerfile(gem: 'slack-ruby-danger')
2
+ toc.check!
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ when 'activerecord' then
11
11
  gem 'otr-activerecord', '~> 1.2.1'
12
12
  gem 'cursor_pagination' # rubocop:disable Bundler/OrderedGems
13
13
  gem 'pg'
14
- when nil then
14
+ when nil
15
15
  warn "Missing ENV['DATABASE_ADAPTER']."
16
16
  else
17
17
  warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}."
@@ -31,12 +31,13 @@ group :development, :test do
31
31
  gem 'rack-test'
32
32
  gem 'rake'
33
33
  gem 'rspec'
34
- gem 'rubocop', '0.58.2'
34
+ gem 'rubocop', '0.81.0'
35
35
  gem 'selenium-webdriver', '~> 3.4.4'
36
36
  gem 'vcr'
37
37
  gem 'webmock'
38
38
  end
39
39
 
40
40
  group :test do
41
+ gem 'danger-toc', '~> 0.2.0', require: false
41
42
  gem 'slack-ruby-danger', '~> 0.1.0', require: false
42
43
  end
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 Daniel Doubrovkine & Contributors
3
+ Copyright (c) 2015-2020 Daniel Doubrovkine & Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -7,31 +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).
10
+ # Table of Contents
11
+
12
+ - [What is this?](#what-is-this)
13
+ - [Stable Release](#stable-release)
14
+ - [Make Your Own](#make-your-own)
15
+ - [Storage](#storage)
16
+ - [MongoDB](#mongodb)
17
+ - [ActiveRecord](#activerecord)
18
+ - [Usage](#usage)
19
+ - [API](#api)
20
+ - [App](#app)
21
+ - [Service Manager](#service-manager)
22
+ - [Lifecycle Callbacks](#lifecycle-callbacks)
23
+ - [Service Timers](#service-timers)
24
+ - [Extensions](#extensions)
25
+ - [Service Class](#service-class)
26
+ - [HTML Templates](#html-templates)
27
+ - [Access Tokens](#access-tokens)
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)
31
+ - [Copyright & License](#copyright--license)
13
32
 
14
33
  ### What is this?
15
34
 
16
- 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.
17
36
 
18
37
  ### Stable Release
19
38
 
20
- You're reading the documentation for the **stable** release of slack-ruby-bot-server, 0.11.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
21
-
22
- ### Try Me
23
-
24
- 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.
25
40
 
26
- ![](images/slackbutton.gif)
41
+ ### Make Your Own
27
42
 
28
- 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.
29
44
 
30
- ![](images/slackbotserver.gif)
45
+ ### Storage
31
46
 
32
- ### Run Your Own
33
-
34
- 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.
35
48
 
36
49
  ### MongoDB
37
50
 
@@ -44,8 +57,6 @@ gem 'mongoid-scroll'
44
57
  gem 'slack-ruby-bot-server'
45
58
  ```
46
59
 
47
- See the [sample app using Mongoid](sample_apps/sample_app_mongoid) for more information.
48
-
49
60
  ### ActiveRecord
50
61
 
51
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.
@@ -58,23 +69,31 @@ gem 'otr-activerecord'
58
69
  gem 'cursor_pagination'
59
70
  ```
60
71
 
61
- See the [sample app using ActiveRecord](sample_apps/sample_app_activerecord) for more information.
62
-
63
72
  ### Usage
64
73
 
65
- Start with one of the samples above, which contain a couple of custom commands, necessary dependencies and tests, then [create a new application](https://api.slack.com/applications/new) on Slack.
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).
66
75
 
67
- ![](images/new.png)
76
+ ![](images/create-app.png)
68
77
 
69
- Follow Slack's instructions, note the app client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app, for local testing purposes use `http://localhost:9292`.
78
+ Follow Slack's instructions, note the app client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app. For local testing purposes use a public tunneling service such as [ngrok](https://ngrok.com/) to expose local port 9292.
70
79
 
71
80
  Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
72
81
 
82
+ Configure your app's [OAuth scopes](https://api.slack.com/legacy/oauth-scopes) as needed by your application.
83
+
84
+ ```ruby
85
+ SlackRubyBotServer.configure do |config|
86
+ config.oauth_scope = ['channels:read', 'chat:write:user']
87
+ end
88
+ ```
89
+
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
+
73
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.
74
93
 
75
94
  ### API
76
95
 
77
- 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.
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.
78
97
 
79
98
  #### App
80
99
 
@@ -104,11 +123,17 @@ MyApp.instance.prepare!
104
123
 
105
124
  #### Service Manager
106
125
 
126
+ ##### Lifecycle Callbacks
127
+
107
128
  You can introduce custom behavior into the service lifecycle via callbacks. This can be useful when new team has been registered via the API or a team has been deactivated from Slack.
108
129
 
109
130
  ```ruby
110
131
  instance = SlackRubyBotServer::Service.instance
111
132
 
133
+ instance.on :started, :stopped do |team|
134
+ # team has been started or stopped
135
+ end
136
+
112
137
  instance.on :created do |team, error, options|
113
138
  # a new team has been registered
114
139
  end
@@ -138,13 +163,12 @@ The following callbacks are supported. All callbacks receive a `team`, except `e
138
163
  | deactivating | a team is being deactivated |
139
164
  | deactivated | a team has been deactivated |
140
165
 
141
-
142
166
  The [Add to Slack button](https://api.slack.com/docs/slack-button) also allows for an optional `state` parameter that will be returned on completion of the request. The `creating` and `created` callbacks include an options hash where this value can be accessed (to check for forgery attacks for instance).
143
167
  ```ruby
144
168
  auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data")
145
169
  ```
146
170
  ```html
147
- <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>
148
172
  ```
149
173
  ```ruby
150
174
  instance = SlackRubyBotServer::Service.instance
@@ -153,30 +177,46 @@ instance.on :creating do |team, error, options|
153
177
  end
154
178
  ```
155
179
 
156
- A number of extensions use service manager callbacks to implement useful functionality.
180
+ ##### Service Timers
157
181
 
158
- * [slack-ruby-bot-server-mailchimp](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp): Subscribes new bot users to a Mailchimp mailing list.
182
+ You can introduce custom behavior into the service lifecycle on a timer. For example, check whether a team's trial has expired, or periodically cleanup data.
159
183
 
160
- #### Server Class
161
-
162
- You can override the server class to handle additional events, and configure the service to use it.
184
+ Note that unlike callbacks, timers are global for the entire service.
163
185
 
164
186
  ```ruby
165
- class MyServer < SlackRubyBotServer::Server
166
- on :hello do |client, data|
167
- # connected to Slack
168
- end
187
+ instance = SlackRubyBotServer::Service.instance
169
188
 
170
- on :channel_joined do |client, data|
171
- # the bot joined a channel in data.channel['id']
189
+ instance.every :hour do
190
+ Team.each do |team|
191
+ begin
192
+ # do something with every team once an hour
193
+ rescue StandardError
194
+ end
172
195
  end
173
196
  end
174
197
 
175
- SlackRubyBotServer.configure do |config|
176
- config.server_class = MyServer
198
+ instance.every :minute do
199
+ # called every minute
200
+ end
201
+
202
+ instance.every :second do
203
+ # called every second
204
+ end
205
+
206
+ instance.every 30 do
207
+ # called every 30 seconds
177
208
  end
178
209
  ```
179
210
 
211
+ ##### Extensions
212
+
213
+ A number of extensions use service manager callbacks and service timers to implement useful functionality.
214
+
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.
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.
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.
218
+ * [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm): Create RTM Slack bots.
219
+
180
220
  #### Service Class
181
221
 
182
222
  You can override the service class to handle additional methods.
@@ -196,28 +236,42 @@ SlackRubyBotServer::Service.instance # MyService
196
236
  SlackRubyBotServer::Service.instance.url # https://www.example.com
197
237
  ```
198
238
 
239
+ ### HTML Templates
240
+
241
+ This library provides a [default HTML template and JS scripts](public) that implement the "Add to Slack" button workflow. Customize your pages by adding a `public` directory in your application and starting with a [index.html.erb](public/index.html.erb) template. The application's `views` and `public` folders are [loaded by default](lib/slack-ruby-bot-server/api/middleware.rb#L32).
242
+
243
+ You can add to or override template paths as follows.
244
+
245
+ ```ruby
246
+ SlackRubyBotServer.configure do |config|
247
+ config.view_paths << File.expand_path(File.join(__dir__, 'public'))
248
+ end
249
+ ```
250
+
199
251
  ### Access Tokens
200
252
 
201
- 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
202
256
 
203
- 1) Configure your app to require additional scopes in Slack API under _OAuth_, _Permissions_
204
- 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=...`
205
- 3) The access token with the requested scopes will be stored as `activated_user_access_token`.
257
+ #### Slack Bots with Granular Permissions
206
258
 
207
- 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
208
261
 
209
- ### Examples Using Slack Ruby Bot Server
262
+ #### Legacy Slack Bots
210
263
 
211
- * [slack-sup](https://github.com/dblock/slack-sup), free service at [sup.playplay.io](https://sup.playplay.io)
212
- * [slack-gamebot](https://github.com/dblock/slack-gamebot), free service at [www.playplay.io](https://www.playplay.io)
213
- * [slack-market](https://github.com/dblock/slack-market), free service at [market.playplay.io](https://market.playplay.io)
214
- * [slack-shellbot](https://github.com/slack-ruby/slack-shellbot), free service at [shell.playplay.io](https://shell.playplay.io)
215
- * [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), free service at [api-explorer.playplay.io](https://shell.playplay.io)
216
- * [slack-strava](https://github.com/dblock/slack-strava), free service at [slava.playplay.io](https://slava.playplay.io)
217
- * [slack-arena](https://github.com/dblock/slack-arena), free service at [arena.playplay.io](https://arena.playplay.io)
264
+ * [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample), a generic sample
265
+ * [slack-sup](https://github.com/dblock/slack-sup), see [sup.playplay.io](https://sup.playplay.io)
266
+ * [slack-gamebot](https://github.com/dblock/slack-gamebot), see [www.playplay.io](https://www.playplay.io)
267
+ * [slack-market](https://github.com/dblock/slack-market), see [market.playplay.io](https://market.playplay.io)
268
+ * [slack-shellbot](https://github.com/slack-ruby/slack-shellbot), see [shell.playplay.io](https://shell.playplay.io)
269
+ * [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), see [api-explorer.playplay.io](https://shell.playplay.io)
270
+ * [slack-strava](https://github.com/dblock/slack-strava), see [slava.playplay.io](https://slava.playplay.io)
271
+ * [slack-arena](https://github.com/dblock/slack-arena), see [arena.playplay.io](https://arena.playplay.io)
218
272
 
219
273
  ### Copyright & License
220
274
 
221
- Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2019
275
+ Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2020
222
276
 
223
277
  [MIT License](LICENSE)