slack-ruby-bot-server 0.10.0 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +44 -7
- data/.travis.yml +7 -5
- data/CHANGELOG.md +48 -20
- data/Dangerfile +1 -0
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +129 -18
- data/UPGRADING.md +14 -0
- data/images/create-app.png +0 -0
- data/lib/slack-ruby-bot-server.rb +9 -11
- data/lib/slack-ruby-bot-server/api.rb +4 -4
- data/lib/slack-ruby-bot-server/api/endpoints.rb +3 -3
- data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +1 -0
- data/lib/slack-ruby-bot-server/api/helpers.rb +4 -4
- data/lib/slack-ruby-bot-server/api/helpers/cursor_helpers.rb +2 -0
- data/lib/slack-ruby-bot-server/api/helpers/sort_helpers.rb +1 -0
- data/lib/slack-ruby-bot-server/api/middleware.rb +1 -5
- data/lib/slack-ruby-bot-server/api/presenters.rb +5 -5
- data/lib/slack-ruby-bot-server/api/presenters/status_presenter.rb +1 -0
- data/lib/slack-ruby-bot-server/app.rb +0 -27
- data/lib/slack-ruby-bot-server/config.rb +8 -0
- data/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb +2 -2
- data/lib/slack-ruby-bot-server/config/database_adapters/mongoid.rb +4 -2
- data/lib/slack-ruby-bot-server/ext/activerecord/slack-ruby-bot/commands/base.rb +1 -1
- data/lib/slack-ruby-bot-server/ext/mongoid/slack-ruby-bot/commands/base.rb +2 -2
- data/lib/slack-ruby-bot-server/models/team/activerecord.rb +8 -5
- data/lib/slack-ruby-bot-server/models/team/methods.rb +0 -13
- data/lib/slack-ruby-bot-server/models/team/mongoid.rb +8 -4
- data/lib/slack-ruby-bot-server/server.rb +1 -0
- data/lib/slack-ruby-bot-server/service.rb +45 -3
- data/lib/slack-ruby-bot-server/version.rb +1 -1
- data/public/index.html.erb +1 -0
- data/public/scripts/messages.js +33 -0
- data/public/scripts/register.js +0 -31
- data/sample_apps/sample_app_activerecord/Gemfile +1 -0
- data/sample_apps/sample_app_activerecord/README.md +1 -0
- data/sample_apps/sample_app_activerecord/commands/help.rb +1 -1
- data/sample_apps/sample_app_activerecord/config.ru +8 -1
- data/sample_apps/sample_app_activerecord/config/postgresql.yml +1 -1
- data/sample_apps/sample_app_activerecord/spec/commands/help_spec.rb +1 -1
- data/sample_apps/sample_app_mongoid/Gemfile +1 -0
- data/sample_apps/sample_app_mongoid/commands/help.rb +1 -1
- data/sample_apps/sample_app_mongoid/spec/commands/help_spec.rb +1 -1
- data/slack-ruby-bot-server.gemspec +2 -3
- metadata +14 -28
- data/app.json +0 -9
- data/images/new.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ba269cbf5d52a1ec63e186d89860b2d5fd3d2375126e93b0efcfb0db77233d2
|
4
|
+
data.tar.gz: f79f39c72303c00dcd90adc2229d95b98a8caff43a0cd1cfb2d40fd328e17214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 619d8952361de54d239f127891f690460cc3a3e0d85ac69298a0a384d4caa52eb68bbf643e03f035c33723f8c1d3207e9ef7b17af76f0d47e0e0656b5d50fa79
|
7
|
+
data.tar.gz: 06a7f1c37a6c9ebd2b17aa6733790383c57ffdff9b0ca4b5344cc9701493fcbeb80d532bc134fbea52f69088e4007e0f7ee76a9cb3d2ab7ec1af082cc87024f3
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [dblock]
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
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:
|
13
|
-
Layout/
|
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:
|
21
|
-
#
|
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'
|
data/.travis.yml
CHANGED
@@ -4,24 +4,26 @@ cache: bundler
|
|
4
4
|
|
5
5
|
matrix:
|
6
6
|
include:
|
7
|
-
- rvm: 2.
|
7
|
+
- rvm: 2.6.2
|
8
8
|
script:
|
9
9
|
- bundle exec danger
|
10
|
-
|
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.
|
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
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,38 @@
|
|
1
1
|
### Changelog
|
2
2
|
|
3
|
+
#### 0.12.2 (2020/7/26)
|
4
|
+
|
5
|
+
* [#120](https://github.com/slack-ruby/slack-ruby-bot-server/pull/120): Removed GIFs - [@dblock](https://github.com/dblock).
|
6
|
+
* [#121](https://github.com/slack-ruby/slack-ruby-bot-server/pull/121): Added TOC - [@dblock](https://github.com/dblock).
|
7
|
+
|
8
|
+
#### 0.12.1 (2020/5/16)
|
9
|
+
|
10
|
+
* [#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).
|
11
|
+
|
12
|
+
#### 0.12.0 (2020/4/26)
|
13
|
+
|
14
|
+
* [#113](https://github.com/slack-ruby/slack-ruby-bot-server/pull/113): Added support for intervals with `.every` - [@dblock](https://github.com/dblock).
|
15
|
+
* [#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).
|
16
|
+
* [#111](https://github.com/slack-ruby/slack-ruby-bot-server/pull/111): Removed dependency on Virtus - [@dblock](https://github.com/dblock).
|
17
|
+
* [#110](https://github.com/slack-ruby/slack-ruby-bot-server/pull/110): Fixed ActiveRecord sample app - [@CeeBeeUK](https://github.com/CeeBeeUK).
|
18
|
+
* [#114](https://github.com/slack-ruby/slack-ruby-bot-server/pull/114): Used `require_relative` to prevent local collisions - [@dblock](https://github.com/dblock).
|
19
|
+
* [#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).
|
20
|
+
|
21
|
+
#### 0.11.1 (2019/5/17)
|
22
|
+
|
23
|
+
* [#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).
|
24
|
+
|
25
|
+
#### 0.11.0 (2019/4/12)
|
26
|
+
|
27
|
+
* [#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).
|
28
|
+
* [#98](https://github.com/slack-ruby/slack-ruby-bot-server/pull/98): Removed `unicorn` from gem dependencies - [@dblock](https://github.com/dblock).
|
29
|
+
* [#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).
|
30
|
+
|
3
31
|
#### 0.10.0 (2019/3/23)
|
4
32
|
|
5
33
|
* [#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).
|
6
34
|
* [#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).
|
7
|
-
* [#95](https://github.com/slack-ruby/slack-ruby-bot-server/pull/95):
|
35
|
+
* [#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).
|
8
36
|
|
9
37
|
#### 0.9.0 (2019/2/25)
|
10
38
|
|
@@ -12,31 +40,31 @@
|
|
12
40
|
|
13
41
|
#### 0.8.3 (2019/1/17)
|
14
42
|
|
15
|
-
* [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88):
|
43
|
+
* [#88](https://github.com/slack-ruby/slack-ruby-bot-server/issues/88): Fixed compatibility with Grape 1.2.x - [@dblock](https://github.com/dblock).
|
16
44
|
|
17
45
|
#### 0.8.2 (2018/10/11)
|
18
46
|
|
19
|
-
* [#80](https://github.com/slack-ruby/slack-ruby-bot-server/pull/80):
|
47
|
+
* [#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).
|
20
48
|
|
21
49
|
#### 0.8.1 (2018/9/20)
|
22
50
|
|
23
|
-
* [#79](https://github.com/slack-ruby/slack-ruby-bot-server/pull/79):
|
51
|
+
* [#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).
|
24
52
|
|
25
53
|
#### 0.8.0 (2018/9/8)
|
26
54
|
|
27
|
-
* [#75](https://github.com/slack-ruby/slack-ruby-bot-server/pull/75):
|
28
|
-
* [#76](https://github.com/slack-ruby/slack-ruby-bot-server/pull/76):
|
55
|
+
* [#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).
|
56
|
+
* [#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).
|
29
57
|
|
30
58
|
#### 0.7.0 (2018/8/22)
|
31
59
|
|
32
|
-
* [#60](https://github.com/slack-ruby/slack-ruby-bot-server/pull/60):
|
60
|
+
* [#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).
|
33
61
|
* [#65](https://github.com/slack-ruby/slack-ruby-bot-server/pull/65): Updated Capybara and selenium-webdriver - [@dblock](https://github.com/dblock).
|
34
62
|
* [#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).
|
35
63
|
* [#74](https://github.com/slack-ruby/slack-ruby-bot-server/pull/74): Added ping worker, will restart offline bots - [@dblock](https://github.com/dblock).
|
36
64
|
|
37
65
|
#### 0.6.1 (2017/3/29)
|
38
66
|
|
39
|
-
* [#54](https://github.com/slack-ruby/slack-ruby-bot-server/pull/54):
|
67
|
+
* [#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).
|
40
68
|
* [#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).
|
41
69
|
|
42
70
|
#### 0.6.0 (2017/3/12)
|
@@ -47,17 +75,17 @@
|
|
47
75
|
|
48
76
|
#### 0.5.0 (2017/2/9)
|
49
77
|
|
50
|
-
* [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43):
|
51
|
-
* [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43):
|
52
|
-
* [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28):
|
53
|
-
* [#31](https://github.com/slack-ruby/slack-ruby-bot-server/pull/31):
|
78
|
+
* [#43](https://github.com/slack-ruby/slack-ruby-bot-server/pull/43): Fixed `cannot load kaminari/grape` - [@dblock](https://github.com/dblock).
|
79
|
+
* [#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).
|
80
|
+
* [#28](https://github.com/slack-ruby/slack-ruby-bot-server/pull/28): Used `slack-ruby-danger` gem - [@dblock](https://github.com/dblock).
|
81
|
+
* [#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).
|
54
82
|
|
55
83
|
#### 0.4.0 (2016/8/29)
|
56
84
|
|
57
85
|
* [#25](https://github.com/slack-ruby/slack-ruby-bot-server/pull/25): Added [danger](http://danger.systems), PR linting - [@dblock](https://github.com/dblock).
|
58
86
|
* The `reset` and `resetting` callbacks have been removed - [@dblock](https://github.com/dblock).
|
59
87
|
* Callbacks receive `team` and `error`, but no longer `server` - [@dblock](https://github.com/dblock).
|
60
|
-
* [#23](https://github.com/slack-ruby/slack-ruby-bot-server/issues/23):
|
88
|
+
* [#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).
|
61
89
|
|
62
90
|
#### 0.3.1 (2016/7/10)
|
63
91
|
|
@@ -81,13 +109,13 @@
|
|
81
109
|
|
82
110
|
* Initial public release - [@dblock](https://github.com/dblock).
|
83
111
|
* Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
|
84
|
-
* [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11):
|
85
|
-
*
|
112
|
+
* [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turned project into gem - [@tmsrjs](https://github.com/tmsrjs).
|
113
|
+
* Used `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
|
86
114
|
* Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
|
87
|
-
*
|
115
|
+
* Used Grape 0.15.x - [@dblock](https://github.com/dblock).
|
88
116
|
* Removed OOB GC - [@dblock](https://github.com/dblock).
|
89
|
-
*
|
90
|
-
*
|
91
|
-
*
|
92
|
-
*
|
117
|
+
* Used Unicorn instead of Puma - [@dblock](https://github.com/dblock).
|
118
|
+
* Fixed wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
|
119
|
+
* Used an OOB GC - [@dblock](https://github.com/dblock).
|
120
|
+
* Deferred start, much faster - [@dblock](https://github.com/dblock).
|
93
121
|
* Backported changes from slack-metabot and slack-shellbot - [@dblock](https://github.com/dblock).
|
data/Dangerfile
CHANGED
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
|
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.
|
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-
|
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,34 @@ 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
|
-
|
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).
|
13
|
+
|
14
|
+
# Table of Contents
|
15
|
+
|
16
|
+
- [What is this?](#what-is-this)
|
17
|
+
- [Stable Release](#stable-release)
|
18
|
+
- [Try Me](#try-me)
|
19
|
+
- [Run Your Own](#run-your-own)
|
20
|
+
- [MongoDB](#mongodb)
|
21
|
+
- [ActiveRecord](#activerecord)
|
22
|
+
- [Usage](#usage)
|
23
|
+
- [OAuth Code Grant](#oauth-code-grant)
|
24
|
+
- [API](#api)
|
25
|
+
- [App](#app)
|
26
|
+
- [Service Manager](#service-manager)
|
27
|
+
- [Lifecycle Callbacks](#lifecycle-callbacks)
|
28
|
+
- [Service Timers](#service-timers)
|
29
|
+
- [Extensions](#extensions)
|
30
|
+
- [Server Class](#server-class)
|
31
|
+
- [Service Class](#service-class)
|
32
|
+
- [HTML Templates](#html-templates)
|
33
|
+
- [Access Tokens](#access-tokens)
|
34
|
+
- [Example Bots Using Slack Ruby Bot Server](#example-bots-using-slack-ruby-bot-server)
|
35
|
+
- [Copyright & License](#copyright--license)
|
9
36
|
|
10
37
|
### What is this?
|
11
38
|
|
@@ -13,7 +40,7 @@ A library that contains a [Grape](http://github.com/ruby-grape/grape) API servin
|
|
13
40
|
|
14
41
|
### Stable Release
|
15
42
|
|
16
|
-
You're reading the documentation for the **stable** release of slack-ruby-bot-server, v0.
|
43
|
+
You're reading the documentation for the **stable** release of slack-ruby-bot-server, v0.12.2. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
17
44
|
|
18
45
|
### Try Me
|
19
46
|
|
@@ -58,17 +85,48 @@ See the [sample app using ActiveRecord](sample_apps/sample_app_activerecord) for
|
|
58
85
|
|
59
86
|
### Usage
|
60
87
|
|
61
|
-
[
|
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).
|
62
89
|
|
63
|
-
![](images/
|
90
|
+
![](images/create-app.png)
|
64
91
|
|
65
|
-
Follow
|
92
|
+
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.
|
66
93
|
|
67
|
-
|
94
|
+
Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
|
95
|
+
|
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:
|
109
|
+
|
110
|
+
```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']
|
123
|
+
```
|
124
|
+
|
125
|
+
The token is stored in persistent storage and used each time a Slack client is instantiated for the specific team.
|
68
126
|
|
69
127
|
### API
|
70
128
|
|
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.
|
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.
|
72
130
|
|
73
131
|
#### App
|
74
132
|
|
@@ -98,11 +156,17 @@ MyApp.instance.prepare!
|
|
98
156
|
|
99
157
|
#### Service Manager
|
100
158
|
|
159
|
+
##### Lifecycle Callbacks
|
160
|
+
|
101
161
|
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
162
|
|
103
163
|
```ruby
|
104
164
|
instance = SlackRubyBotServer::Service.instance
|
105
165
|
|
166
|
+
instance.on :started, :stopped do |team|
|
167
|
+
# team has been started or stopped
|
168
|
+
end
|
169
|
+
|
106
170
|
instance.on :created do |team, error, options|
|
107
171
|
# a new team has been registered
|
108
172
|
end
|
@@ -132,7 +196,6 @@ The following callbacks are supported. All callbacks receive a `team`, except `e
|
|
132
196
|
| deactivating | a team is being deactivated |
|
133
197
|
| deactivated | a team has been deactivated |
|
134
198
|
|
135
|
-
|
136
199
|
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).
|
137
200
|
```ruby
|
138
201
|
auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data")
|
@@ -147,9 +210,44 @@ instance.on :creating do |team, error, options|
|
|
147
210
|
end
|
148
211
|
```
|
149
212
|
|
150
|
-
|
213
|
+
##### Service Timers
|
214
|
+
|
215
|
+
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.
|
216
|
+
|
217
|
+
Note that unlike callbacks, timers are global for the entire service.
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
instance = SlackRubyBotServer::Service.instance
|
221
|
+
|
222
|
+
instance.every :hour do
|
223
|
+
Team.each do |team|
|
224
|
+
begin
|
225
|
+
# do something with every team once an hour
|
226
|
+
rescue StandardError
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
instance.every :minute do
|
232
|
+
# called every minute
|
233
|
+
end
|
234
|
+
|
235
|
+
instance.every :second do
|
236
|
+
# called every second
|
237
|
+
end
|
238
|
+
|
239
|
+
instance.every 30 do
|
240
|
+
# called every 30 seconds
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
244
|
+
##### Extensions
|
245
|
+
|
246
|
+
A number of extensions use service manager callbacks and service timers to implement useful functionality.
|
151
247
|
|
248
|
+
* [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events): Easily handle Slack slash commands, interactive buttons and events.
|
152
249
|
* [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
|
+
* [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.
|
153
251
|
|
154
252
|
#### Server Class
|
155
253
|
|
@@ -190,6 +288,18 @@ SlackRubyBotServer::Service.instance # MyService
|
|
190
288
|
SlackRubyBotServer::Service.instance.url # https://www.example.com
|
191
289
|
```
|
192
290
|
|
291
|
+
### HTML Templates
|
292
|
+
|
293
|
+
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).
|
294
|
+
|
295
|
+
You can add to or override template paths as follows.
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
SlackRubyBotServer.configure do |config|
|
299
|
+
config.view_paths << File.expand_path(File.join(__dir__, 'public'))
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
193
303
|
### Access Tokens
|
194
304
|
|
195
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.
|
@@ -200,18 +310,19 @@ By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) s
|
|
200
310
|
|
201
311
|
You can see a sample implementation in [slack-sup#3a497b](https://github.com/dblock/slack-sup/commit/3a497b436d25d3a7738562655cda64b180ae0096).
|
202
312
|
|
203
|
-
###
|
313
|
+
### Example Bots Using Slack Ruby Bot Server
|
204
314
|
|
205
|
-
* [slack-
|
206
|
-
* [slack-
|
207
|
-
* [slack-
|
208
|
-
* [slack-
|
209
|
-
* [slack-
|
210
|
-
* [slack-
|
211
|
-
* [slack-
|
315
|
+
* [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample), a generic sample
|
316
|
+
* [slack-sup](https://github.com/dblock/slack-sup), see [sup.playplay.io](https://sup.playplay.io)
|
317
|
+
* [slack-gamebot](https://github.com/dblock/slack-gamebot), see [www.playplay.io](https://www.playplay.io)
|
318
|
+
* [slack-market](https://github.com/dblock/slack-market), see [market.playplay.io](https://market.playplay.io)
|
319
|
+
* [slack-shellbot](https://github.com/slack-ruby/slack-shellbot), see [shell.playplay.io](https://shell.playplay.io)
|
320
|
+
* [slack-api-explorer](https://github.com/slack-ruby/slack-api-explorer), see [api-explorer.playplay.io](https://shell.playplay.io)
|
321
|
+
* [slack-strava](https://github.com/dblock/slack-strava), see [slava.playplay.io](https://slava.playplay.io)
|
322
|
+
* [slack-arena](https://github.com/dblock/slack-arena), see [arena.playplay.io](https://arena.playplay.io)
|
212
323
|
|
213
324
|
### Copyright & License
|
214
325
|
|
215
|
-
Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-
|
326
|
+
Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2020
|
216
327
|
|
217
328
|
[MIT License](LICENSE)
|