slack-ruby-bot-server 0.9.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.rubocop_todo.yml +44 -7
  4. data/.travis.yml +7 -5
  5. data/CHANGELOG.md +48 -19
  6. data/Gemfile +3 -3
  7. data/LICENSE +1 -1
  8. data/README.md +147 -23
  9. data/UPGRADING.md +42 -2
  10. data/images/create-app.png +0 -0
  11. data/lib/slack-ruby-bot-server.rb +9 -11
  12. data/lib/slack-ruby-bot-server/api.rb +4 -4
  13. data/lib/slack-ruby-bot-server/api/endpoints.rb +3 -3
  14. data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +20 -5
  15. data/lib/slack-ruby-bot-server/api/helpers.rb +4 -4
  16. data/lib/slack-ruby-bot-server/api/helpers/cursor_helpers.rb +2 -0
  17. data/lib/slack-ruby-bot-server/api/helpers/sort_helpers.rb +1 -0
  18. data/lib/slack-ruby-bot-server/api/middleware.rb +1 -5
  19. data/lib/slack-ruby-bot-server/api/presenters.rb +5 -5
  20. data/lib/slack-ruby-bot-server/api/presenters/status_presenter.rb +1 -0
  21. data/lib/slack-ruby-bot-server/app.rb +0 -27
  22. data/lib/slack-ruby-bot-server/config.rb +10 -0
  23. data/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb +6 -2
  24. data/lib/slack-ruby-bot-server/config/database_adapters/mongoid.rb +4 -2
  25. data/lib/slack-ruby-bot-server/models/team/activerecord.rb +8 -5
  26. data/lib/slack-ruby-bot-server/models/team/methods.rb +0 -13
  27. data/lib/slack-ruby-bot-server/models/team/mongoid.rb +11 -4
  28. data/lib/slack-ruby-bot-server/server.rb +1 -0
  29. data/lib/slack-ruby-bot-server/service.rb +51 -9
  30. data/lib/slack-ruby-bot-server/version.rb +1 -1
  31. data/public/index.html.erb +1 -0
  32. data/public/scripts/messages.js +33 -0
  33. data/public/scripts/register.js +3 -32
  34. data/sample_apps/sample_app_activerecord/Gemfile +1 -0
  35. data/sample_apps/sample_app_activerecord/README.md +1 -0
  36. data/sample_apps/sample_app_activerecord/config.ru +8 -1
  37. data/sample_apps/sample_app_activerecord/config/postgresql.yml +1 -1
  38. data/sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb +0 -1
  39. data/sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb +7 -0
  40. data/sample_apps/sample_app_activerecord/db/schema.rb +6 -3
  41. data/sample_apps/sample_app_mongoid/Gemfile +1 -0
  42. data/slack-ruby-bot-server.gemspec +2 -3
  43. metadata +10 -25
  44. data/app.json +0 -9
  45. data/images/new.png +0 -0
  46. data/lib/slack-ruby-bot-server/models.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02acf8078e1ec2fb418d45f9fac6823d7af6b473ad00c8992f59ff4a64311609
4
- data.tar.gz: d1da43dc7201cd30a5e49eb6193eb476820edd936b804e714e8952aafaf4d566
3
+ metadata.gz: bd95fc2a7806d66e49468401dec6f7598ba538d690f79c39a80723b0abd4afc8
4
+ data.tar.gz: 57d542b3799078c57e29914395d20c92735c9f70025471f7ccb3e422a965c437
5
5
  SHA512:
6
- metadata.gz: bc2b495018d4d24f36c75eada4e9eb218205611bc2ab94d77b89326e4c23ac0e254302747a6d3bee758dc20fb46f44a4722da93fcac69a262754eb106aca80a6
7
- data.tar.gz: 4e503d3c5f70d464a4c07f429cd81b1aa6bdc3414e95fa9b3e668ad6649f644e6df83a8401bf491147c9e5821a3b865052c3a74532cb4ca0e711a495047d5753
6
+ metadata.gz: 7725ccdcda4bc790c8f4a28de21797ee8aaefe698e937be0fb2bc665a487e28f3174960db32d772b75ea0137677a1049dc2ef05b8ea49f192dcd40d1b58502f0
7
+ data.tar.gz: a661c32f29d0685428510700dfed5f3a76614adf924d972cad8bae14570422ab2d131f7db41a28ad378f0c5a0e8c283943ab674e4c70df6d80ed826e12bd126f
@@ -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,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-02-25 14:24:34 -0500 using RuboCop version 0.58.2.
3
+ # on 2020-06-16 16:54:39 -0400 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
@@ -9,26 +9,63 @@
9
9
  # Offense count: 3
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
16
  - 'sample_apps/sample_app_activerecord/commands/help.rb'
17
17
  - 'sample_apps/sample_app_mongoid/commands/help.rb'
18
18
 
19
+ # Offense count: 1
20
+ Lint/AmbiguousOperator:
21
+ Exclude:
22
+ - 'spec/slack-ruby-bot-server/service_spec.rb'
23
+
24
+ # Offense count: 2
25
+ # Cop supports --auto-correct.
26
+ Lint/NonDeterministicRequireOrder:
27
+ Exclude:
28
+ - 'spec/spec_helper.rb'
29
+
30
+ # Offense count: 2
31
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
32
+ # 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
+ Naming/FileName:
34
+ Exclude:
35
+ - 'lib/slack-ruby-bot-server.rb'
36
+ - 'lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb'
37
+
19
38
  # Offense count: 3
20
- # Configuration parameters: Blacklist.
21
- # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
39
+ # Configuration parameters: ForbiddenDelimiters.
40
+ # ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
22
41
  Naming/HeredocDelimiterNaming:
23
42
  Exclude:
24
43
  - 'lib/slack-ruby-bot-server/info.rb'
25
44
  - 'sample_apps/sample_app_activerecord/commands/help.rb'
26
45
  - 'sample_apps/sample_app_mongoid/commands/help.rb'
27
46
 
47
+ # Offense count: 3
48
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
49
+ # AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
50
+ Naming/MethodParameterName:
51
+ Exclude:
52
+ - 'lib/slack-ruby-bot-server/models/team/activerecord.rb'
53
+ - 'lib/slack-ruby-bot-server/models/team/mongoid.rb'
54
+ - 'lib/slack-ruby-bot-server/service.rb'
55
+
28
56
  # Offense count: 1
29
57
  # Cop supports --auto-correct.
30
- # Configuration parameters: EnforcedStyle.
31
- # SupportedStyles: module_function, extend_self
58
+ # Configuration parameters: EnforcedStyle, Autocorrect.
59
+ # SupportedStyles: module_function, extend_self, forbidden
32
60
  Style/ModuleFunction:
33
61
  Exclude:
34
62
  - 'lib/slack-ruby-bot-server/config.rb'
63
+
64
+ # Offense count: 1
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
67
+ # SupportedStyles: predicate, comparison
68
+ Style/NumericPredicate:
69
+ Exclude:
70
+ - 'spec/**/*'
71
+ - '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
@@ -1,36 +1,65 @@
1
1
  ### Changelog
2
2
 
3
+ #### 0.12.1 (2020/5/16)
4
+
5
+ * [#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).
6
+
7
+ #### 0.12.0 (2020/4/26)
8
+
9
+ * [#113](https://github.com/slack-ruby/slack-ruby-bot-server/pull/113): Added support for intervals with `.every` - [@dblock](https://github.com/dblock).
10
+ * [#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).
11
+ * [#111](https://github.com/slack-ruby/slack-ruby-bot-server/pull/111): Removed dependency on Virtus - [@dblock](https://github.com/dblock).
12
+ * [#110](https://github.com/slack-ruby/slack-ruby-bot-server/pull/110): Fixed ActiveRecord sample app - [@CeeBeeUK](https://github.com/CeeBeeUK).
13
+ * [#114](https://github.com/slack-ruby/slack-ruby-bot-server/pull/114): Used `require_relative` to prevent local collisions - [@dblock](https://github.com/dblock).
14
+ * [#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).
15
+
16
+ #### 0.11.1 (2019/5/17)
17
+
18
+ * [#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).
19
+
20
+ #### 0.11.0 (2019/4/12)
21
+
22
+ * [#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).
23
+ * [#98](https://github.com/slack-ruby/slack-ruby-bot-server/pull/98): Removed `unicorn` from gem dependencies - [@dblock](https://github.com/dblock).
24
+ * [#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).
25
+
26
+ #### 0.10.0 (2019/3/23)
27
+
28
+ * [#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).
29
+ * [#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).
30
+ * [#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).
31
+
3
32
  #### 0.9.0 (2019/2/25)
4
33
 
5
34
  * [#93](https://github.com/slack-ruby/slack-ruby-bot-server/pull/93): Removed ping worker in favor of slack-ruby-client lower level ping - [@dblock](https://github.com/dblock).
6
35
 
7
36
  #### 0.8.3 (2019/1/17)
8
37
 
9
- * [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88): Fix: compatibility with Grape 1.2.x - [@dblock](https://github.com/dblock).
38
+ * [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88): Fixed compatibility with Grape 1.2.x - [@dblock](https://github.com/dblock).
10
39
 
11
40
  #### 0.8.2 (2018/10/11)
12
41
 
13
- * [#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).
42
+ * [#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).
14
43
 
15
44
  #### 0.8.1 (2018/9/20)
16
45
 
17
- * [#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).
46
+ * [#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).
18
47
 
19
48
  #### 0.8.0 (2018/9/8)
20
49
 
21
- * [#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).
22
- * [#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).
50
+ * [#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).
51
+ * [#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).
23
52
 
24
53
  #### 0.7.0 (2018/8/22)
25
54
 
26
- * [#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).
55
+ * [#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).
27
56
  * [#65](https://github.com/slack-ruby/slack-ruby-bot-server/pull/65): Updated Capybara and selenium-webdriver - [@dblock](https://github.com/dblock).
28
57
  * [#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).
29
58
  * [#74](https://github.com/slack-ruby/slack-ruby-bot-server/pull/74): Added ping worker, will restart offline bots - [@dblock](https://github.com/dblock).
30
59
 
31
60
  #### 0.6.1 (2017/3/29)
32
61
 
33
- * [#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).
62
+ * [#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).
34
63
  * [#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).
35
64
 
36
65
  #### 0.6.0 (2017/3/12)
@@ -41,17 +70,17 @@
41
70
 
42
71
  #### 0.5.0 (2017/2/9)
43
72
 
44
- * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fix: `cannot load kaminari/grape` - [@dblock](https://github.com/dblock).
45
- * [#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).
46
- * [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28): Use slack-ruby-danger gem - [@dblock](https://github.com/dblock).
47
- * [#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).
73
+ * [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fixed `cannot load kaminari/grape` - [@dblock](https://github.com/dblock).
74
+ * [#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).
75
+ * [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28): Used `slack-ruby-danger` gem - [@dblock](https://github.com/dblock).
76
+ * [#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).
48
77
 
49
78
  #### 0.4.0 (2016/8/29)
50
79
 
51
80
  * [#25](https://github.com/slack-ruby/slack-ruby-bot-server/pull/25): Added [danger](http://danger.systems), PR linting - [@dblock](https://github.com/dblock).
52
81
  * The `reset` and `resetting` callbacks have been removed - [@dblock](https://github.com/dblock).
53
82
  * Callbacks receive `team` and `error`, but no longer `server` - [@dblock](https://github.com/dblock).
54
- * [#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).
83
+ * [#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).
55
84
 
56
85
  #### 0.3.1 (2016/7/10)
57
86
 
@@ -75,13 +104,13 @@
75
104
 
76
105
  * Initial public release - [@dblock](https://github.com/dblock).
77
106
  * Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
78
- * [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turn project into gem - [@tmsrjs](https://github.com/tmsrjs).
79
- * Use `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
107
+ * [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turned project into gem - [@tmsrjs](https://github.com/tmsrjs).
108
+ * Used `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
80
109
  * Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
81
- * Use Grape 0.15.x - [@dblock](https://github.com/dblock).
110
+ * Used Grape 0.15.x - [@dblock](https://github.com/dblock).
82
111
  * Removed OOB GC - [@dblock](https://github.com/dblock).
83
- * Use Unicorn instead of Puma - [@dblock](https://github.com/dblock).
84
- * Fix: wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
85
- * Use an OOB GC - [@dblock](https://github.com/dblock).
86
- * Defer start, much faster - [@dblock](https://github.com/dblock).
112
+ * Used Unicorn instead of Puma - [@dblock](https://github.com/dblock).
113
+ * Fixed wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
114
+ * Used an OOB GC - [@dblock](https://github.com/dblock).
115
+ * Deferred start, much faster - [@dblock](https://github.com/dblock).
87
116
  * Backported changes from slack-metabot and slack-shellbot - [@dblock](https://github.com/dblock).
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ when 'mongoid' then
5
5
  gem 'kaminari-mongoid'
6
6
  gem 'mongoid'
7
7
  gem 'mongoid-scroll'
8
+ gem 'mongoid-shell'
8
9
  when 'activerecord' then
9
10
  gem 'activerecord', '~> 5.0.0'
10
11
  gem 'otr-activerecord', '~> 1.2.1'
11
12
  gem 'cursor_pagination' # rubocop:disable Bundler/OrderedGems
12
13
  gem 'pg'
13
- when nil then
14
+ when nil
14
15
  warn "Missing ENV['DATABASE_ADAPTER']."
15
16
  else
16
17
  warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}."
@@ -26,12 +27,11 @@ group :development, :test do
26
27
  gem 'fabrication'
27
28
  gem 'faker'
28
29
  gem 'hyperclient'
29
- gem 'mongoid-shell'
30
30
  gem 'rack-server-pages'
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'
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2018 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
@@ -5,7 +5,11 @@ Slack Ruby Bot Server
5
5
  [![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-bot-server.svg?branch=master)](https://travis-ci.org/slack-ruby/slack-ruby-bot-server)
6
6
  [![Code Climate](https://codeclimate.com/github/slack-ruby/slack-ruby-bot-server.svg)](https://codeclimate.com/github/slack-ruby/slack-ruby-bot-server)
7
7
 
8
- A library that enables you to write a complete Slack bot service with Slack button integration, in Ruby. 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). A good demo of a service built on top of this is [missingkidsbot.org](http://missingkidsbot.org).
8
+ Build a complete Slack bot service with Slack button integration, in Ruby.
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).
9
13
 
10
14
  ### What is this?
11
15
 
@@ -13,7 +17,7 @@ A library that contains a [Grape](http://github.com/ruby-grape/grape) API servin
13
17
 
14
18
  ### Stable Release
15
19
 
16
- You're reading the documentation for the **stable** release of slack-ruby-bot-server, v0.9.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
20
+ You're reading the documentation for the **next** release of slack-ruby-bot-server. Please see the documentation for the [last stable release, v0.12.0](https://github.com/slack-ruby/slack-ruby-bot-server/blob/v0.12.0/README.md) unless you're integrating with HEAD. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
17
21
 
18
22
  ### Try Me
19
23
 
@@ -58,17 +62,48 @@ See the [sample app using ActiveRecord](sample_apps/sample_app_activerecord) for
58
62
 
59
63
  ### Usage
60
64
 
61
- [Create a New Application](https://api.slack.com/applications/new) on Slack.
65
+ 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).
66
+
67
+ ![](images/create-app.png)
68
+
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 a public tunneling service such as [ngrok](https://ngrok.com/) to expose local port 9292.
70
+
71
+ Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
72
+
73
+ 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
+
75
+ ### OAuth Code Grant
76
+
77
+ 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).
62
78
 
63
- ![](images/new.png)
79
+ The button itself contains a link that looks like this:
64
80
 
65
- Follow the instructions, note the app's client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app, for testing purposes use `http://localhost:9292`. Edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it. Run `bundle install` and `foreman start`. Navigate to [localhost:9292](http://localhost:9292). Register using the Slack button.
81
+ ```
82
+ https://slack.com/oauth/authorize?scope=bot&client_id=<%= ENV['SLACK_CLIENT_ID'] %>
83
+ ```
84
+
85
+ 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:
86
+
87
+ ```ruby
88
+ # Instantiate a web client
89
+ client = Slack::Web::Client.new
90
+
91
+ # Request a token using the temporary code
92
+ rc = client.oauth_access(
93
+ client_id: ENV['SLACK_CLIENT_ID'],
94
+ client_secret: ENV['SLACK_CLIENT_SECRET'],
95
+ code: params[:code]
96
+ )
97
+
98
+ # Pluck the token from the response
99
+ token = rc['bot']['bot_access_token']
100
+ ```
66
101
 
67
- If you deploy to Heroku set `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` via `heroku config:add SLACK_CLIENT_ID=... SLACK_CLIENT_SECRET=...`.
102
+ The token is stored in persistent storage and used each time a Slack client is instantiated for the specific team.
68
103
 
69
104
  ### API
70
105
 
71
- 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.
106
+ 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.
72
107
 
73
108
  #### App
74
109
 
@@ -98,20 +133,26 @@ MyApp.instance.prepare!
98
133
 
99
134
  #### Service Manager
100
135
 
136
+ ##### Lifecycle Callbacks
137
+
101
138
  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.
102
139
 
103
140
  ```ruby
104
141
  instance = SlackRubyBotServer::Service.instance
105
142
 
106
- instance.on :created do |team, error|
143
+ instance.on :started, :stopped do |team|
144
+ # team has been started or stopped
145
+ end
146
+
147
+ instance.on :created do |team, error, options|
107
148
  # a new team has been registered
108
149
  end
109
150
 
110
- instance.on :deactivated do |team, error|
151
+ instance.on :deactivated do |team, error, options|
111
152
  # an existing team has been deactivated in Slack
112
153
  end
113
154
 
114
- instance.on :error do |team, error|
155
+ instance.on :error do |team, error, options|
115
156
  # an error has occurred
116
157
  end
117
158
  ```
@@ -132,6 +173,58 @@ The following callbacks are supported. All callbacks receive a `team`, except `e
132
173
  | deactivating | a team is being deactivated |
133
174
  | deactivated | a team has been deactivated |
134
175
 
176
+ 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).
177
+ ```ruby
178
+ auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data")
179
+ ```
180
+ ```html
181
+ <a href="https://slack.com/oauth/authorize?scope=bot&client_id=<%= ENV['SLACK_CLIENT_ID'] %>&state=#{auth)"> ... </a>
182
+ ```
183
+ ```ruby
184
+ instance = SlackRubyBotServer::Service.instance
185
+ instance.on :creating do |team, error, options|
186
+ raise "Unauthorized response" unless options[:state] == auth
187
+ end
188
+ ```
189
+
190
+ ##### Service Timers
191
+
192
+ 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.
193
+
194
+ Note that unlike callbacks, timers are global for the entire service.
195
+
196
+ ```ruby
197
+ instance = SlackRubyBotServer::Service.instance
198
+
199
+ instance.every :hour do
200
+ Team.each do |team|
201
+ begin
202
+ # do something with every team once an hour
203
+ rescue StandardError
204
+ end
205
+ end
206
+ end
207
+
208
+ instance.every :minute do
209
+ # called every minute
210
+ end
211
+
212
+ instance.every :second do
213
+ # called every second
214
+ end
215
+
216
+ instance.every 30 do
217
+ # called every 30 seconds
218
+ end
219
+ ```
220
+
221
+ ##### Extensions
222
+
223
+ A number of extensions use service manager callbacks and service timers to implement useful functionality.
224
+
225
+ * [slack-ruby-bot-server-mailchimp](https://github.com/slack-ruby/slack-ruby-bot-server-mailchimp): Subscribes new bot users to a Mailchimp mailing list.
226
+ * [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.
227
+
135
228
  #### Server Class
136
229
 
137
230
  You can override the server class to handle additional events, and configure the service to use it.
@@ -152,29 +245,60 @@ SlackRubyBotServer.configure do |config|
152
245
  end
153
246
  ```
154
247
 
248
+ #### Service Class
249
+
250
+ You can override the service class to handle additional methods.
251
+
252
+ ```ruby
253
+ class MyService < SlackRubyBotServer::Service
254
+ def url
255
+ 'https://www.example.com'
256
+ end
257
+ end
258
+
259
+ SlackRubyBotServer.configure do |config|
260
+ config.service_class = MyService
261
+ end
262
+
263
+ SlackRubyBotServer::Service.instance # MyService
264
+ SlackRubyBotServer::Service.instance.url # https://www.example.com
265
+ ```
266
+
267
+ ### HTML Templates
268
+
269
+ 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).
270
+
271
+ You can add to or override template paths as follows.
272
+
273
+ ```ruby
274
+ SlackRubyBotServer.configure do |config|
275
+ config.view_paths << File.expand_path(File.join(__dir__, 'public'))
276
+ end
277
+ ```
278
+
155
279
  ### Access Tokens
156
280
 
157
- By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores a `bot_access_token` that grants a certain amount of privileges to the bot user as described in [Slack OAuth Docs](https://api.slack.com/docs/oauth). 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 obtain the non-bot access token make the following changes.
281
+ 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.
158
282
 
159
283
  1) Configure your app to require additional scopes in Slack API under _OAuth_, _Permissions_
160
- 2) Add `access_token` and, optionally, `scope` to your `Team` model
161
- 3) Change the _Add to Slack_ buttons to require the additional scope, eg. `https://slack.com/oauth/authorize?scope=bot,users.profile:read&client_id=...`
162
- 4) Store the access token returned from `Slack::Web::Client#oauth_access` and scope when creating a team in your `Teams` API endpoint.
284
+ 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=...`
285
+ 3) The access token with the requested scopes will be stored as `activated_user_access_token`.
163
286
 
164
287
  You can see a sample implementation in [slack-sup#3a497b](https://github.com/dblock/slack-sup/commit/3a497b436d25d3a7738562655cda64b180ae0096).
165
288
 
166
- ### Examples Using Slack Ruby Bot Server
289
+ ### Example Bots Using Slack Ruby Bot Server
167
290
 
168
- * [slack-sup](https://github.com/dblock/slack-sup), free service at [sup.playplay.io](https://sup.playplay.io)
169
- * [slack-gamebot](https://github.com/dblock/slack-gamebot), free service at [www.playplay.io](https://www.playplay.io)
170
- * [slack-market](https://github.com/dblock/slack-market), free service at [market.playplay.io](https://market.playplay.io)
171
- * [slack-shellbot](https://github.com/slack-ruby/slack-shellbot), free service at [shell.playplay.io](https://shell.playplay.io)
172
- * [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), free service at [api-explorer.playplay.io](https://shell.playplay.io)
173
- * [slack-strava](https://github.com/dblock/slack-strava), free service at [slava.playplay.io](https://slava.playplay.io)
174
- * [slack-arena](https://github.com/dblock/slack-arena), free service at [arena.playplay.io](https://arena.playplay.io)
291
+ * [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample), a generic sample
292
+ * [slack-sup](https://github.com/dblock/slack-sup), see [sup.playplay.io](https://sup.playplay.io)
293
+ * [slack-gamebot](https://github.com/dblock/slack-gamebot), see [www.playplay.io](https://www.playplay.io)
294
+ * [slack-market](https://github.com/dblock/slack-market), see [market.playplay.io](https://market.playplay.io)
295
+ * [slack-shellbot](https://github.com/slack-ruby/slack-shellbot), see [shell.playplay.io](https://shell.playplay.io)
296
+ * [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), see [api-explorer.playplay.io](https://shell.playplay.io)
297
+ * [slack-strava](https://github.com/dblock/slack-strava), see [slava.playplay.io](https://slava.playplay.io)
298
+ * [slack-arena](https://github.com/dblock/slack-arena), see [arena.playplay.io](https://arena.playplay.io)
175
299
 
176
300
  ### Copyright & License
177
301
 
178
- Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2018
302
+ Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2020
179
303
 
180
304
  [MIT License](LICENSE)