slack-ruby-bot-server 0.12.0 → 1.1.0
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_todo.yml +7 -10
- data/.travis.yml +0 -1
- data/CHANGELOG.md +22 -0
- data/DEBUGGING.md +0 -20
- data/Dangerfile +1 -0
- data/Gemfile +1 -0
- data/README.md +69 -74
- data/UPGRADING.md +21 -0
- data/lib/slack-ruby-bot-server.rb +3 -3
- data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +35 -9
- data/lib/slack-ruby-bot-server/api/middleware.rb +4 -5
- data/lib/slack-ruby-bot-server/app.rb +2 -14
- data/lib/slack-ruby-bot-server/config.rb +32 -2
- data/lib/slack-ruby-bot-server/ext.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/loggable.rb +25 -0
- data/lib/slack-ruby-bot-server/models/team/activerecord.rb +8 -5
- data/lib/slack-ruby-bot-server/models/team/methods.rb +21 -1
- data/lib/slack-ruby-bot-server/models/team/mongoid.rb +8 -4
- data/lib/slack-ruby-bot-server/rspec.rb +0 -1
- data/lib/slack-ruby-bot-server/service.rb +7 -33
- data/lib/slack-ruby-bot-server/version.rb +1 -1
- data/public/index.html.erb +1 -1
- data/slack-ruby-bot-server.gemspec +2 -2
- data/tasks/db.rake +0 -36
- metadata +17 -56
- data/images/slackbotserver.gif +0 -0
- data/images/slackbutton.gif +0 -0
- data/lib/slack-ruby-bot-server/ext/activerecord/slack-ruby-bot/commands/base.rb +0 -18
- data/lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb +0 -2
- data/lib/slack-ruby-bot-server/ext/slack-ruby-bot/client.rb +0 -12
- data/lib/slack-ruby-bot-server/server.rb +0 -31
- data/sample_apps/README.md +0 -11
- data/sample_apps/sample_app_activerecord/.rspec +0 -3
- data/sample_apps/sample_app_activerecord/.standalone_migrations +0 -3
- data/sample_apps/sample_app_activerecord/Gemfile +0 -24
- data/sample_apps/sample_app_activerecord/Procfile +0 -1
- data/sample_apps/sample_app_activerecord/README.md +0 -12
- data/sample_apps/sample_app_activerecord/Rakefile +0 -14
- data/sample_apps/sample_app_activerecord/commands.rb +0 -2
- data/sample_apps/sample_app_activerecord/commands/help.rb +0 -19
- data/sample_apps/sample_app_activerecord/commands/whoami.rb +0 -6
- data/sample_apps/sample_app_activerecord/config.ru +0 -22
- data/sample_apps/sample_app_activerecord/config/newrelic.yml +0 -217
- data/sample_apps/sample_app_activerecord/config/postgresql.yml +0 -17
- data/sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb +0 -12
- data/sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb +0 -7
- data/sample_apps/sample_app_activerecord/db/schema.rb +0 -29
- data/sample_apps/sample_app_activerecord/spec/api/root_spec.rb +0 -16
- data/sample_apps/sample_app_activerecord/spec/commands/help_spec.rb +0 -14
- data/sample_apps/sample_app_activerecord/spec/commands/whoami_spec.rb +0 -14
- data/sample_apps/sample_app_activerecord/spec/spec_helper.rb +0 -19
- data/sample_apps/sample_app_mongoid/.rspec +0 -3
- data/sample_apps/sample_app_mongoid/Gemfile +0 -20
- data/sample_apps/sample_app_mongoid/Procfile +0 -1
- data/sample_apps/sample_app_mongoid/README.md +0 -14
- data/sample_apps/sample_app_mongoid/Rakefile +0 -10
- data/sample_apps/sample_app_mongoid/commands.rb +0 -2
- data/sample_apps/sample_app_mongoid/commands/help.rb +0 -19
- data/sample_apps/sample_app_mongoid/commands/whoami.rb +0 -6
- data/sample_apps/sample_app_mongoid/config.ru +0 -14
- data/sample_apps/sample_app_mongoid/config/mongoid.yml +0 -27
- data/sample_apps/sample_app_mongoid/config/newrelic.yml +0 -217
- data/sample_apps/sample_app_mongoid/spec/api/root_spec.rb +0 -16
- data/sample_apps/sample_app_mongoid/spec/commands/help_spec.rb +0 -14
- data/sample_apps/sample_app_mongoid/spec/commands/whoami_spec.rb +0 -14
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d96988aebe8c1dadd75c95e086ad63f5aaa81a8c93ecb1a92ae2f6a1908f6b6d
|
4
|
+
data.tar.gz: a1519cf75e0afadc610fc92b975613d7817c5a8cf243f849c6ecb9587e504df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52881e9b3faa4754a4c582eb9269a6b9eacf0f3f80f4dc20d7332e0d9304d2580b47185409ace983422f6e800bd2ae9bed00d3829eb457c4299eee5294630c3
|
7
|
+
data.tar.gz: 91a903e372af38353a914d61f04d1e7016e1e25edf3f9b41afeee523279c1b5c29fefb23ec8d1acc1bb6fdaaf8b6cd0ef4d1c6a2b2f1ac9707ac036a22f4881e
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [dblock]
|
data/.rubocop_todo.yml
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2020-
|
3
|
+
# on 2020-11-16 09:56:54 -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:
|
9
|
+
# Offense count: 1
|
10
10
|
# Cop supports --auto-correct.
|
11
11
|
# Configuration parameters: EnforcedStyle.
|
12
12
|
# SupportedStyles: squiggly, active_support, powerpack, unindent
|
13
13
|
Layout/HeredocIndentation:
|
14
14
|
Exclude:
|
15
15
|
- 'lib/slack-ruby-bot-server/info.rb'
|
16
|
-
- 'sample_apps/sample_app_activerecord/commands/help.rb'
|
17
|
-
- 'sample_apps/sample_app_mongoid/commands/help.rb'
|
18
16
|
|
19
17
|
# Offense count: 1
|
20
18
|
Lint/AmbiguousOperator:
|
@@ -27,28 +25,27 @@ Lint/NonDeterministicRequireOrder:
|
|
27
25
|
Exclude:
|
28
26
|
- 'spec/spec_helper.rb'
|
29
27
|
|
30
|
-
# Offense count:
|
28
|
+
# Offense count: 1
|
31
29
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
32
30
|
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
33
31
|
Naming/FileName:
|
34
32
|
Exclude:
|
35
33
|
- 'lib/slack-ruby-bot-server.rb'
|
36
|
-
- 'lib/slack-ruby-bot-server/ext/slack-ruby-bot.rb'
|
37
34
|
|
38
|
-
# Offense count:
|
35
|
+
# Offense count: 1
|
39
36
|
# Configuration parameters: ForbiddenDelimiters.
|
40
37
|
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
41
38
|
Naming/HeredocDelimiterNaming:
|
42
39
|
Exclude:
|
43
40
|
- 'lib/slack-ruby-bot-server/info.rb'
|
44
|
-
- 'sample_apps/sample_app_activerecord/commands/help.rb'
|
45
|
-
- 'sample_apps/sample_app_mongoid/commands/help.rb'
|
46
41
|
|
47
|
-
# Offense count:
|
42
|
+
# Offense count: 3
|
48
43
|
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
49
44
|
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
|
50
45
|
Naming/MethodParameterName:
|
51
46
|
Exclude:
|
47
|
+
- 'lib/slack-ruby-bot-server/models/team/activerecord.rb'
|
48
|
+
- 'lib/slack-ruby-bot-server/models/team/mongoid.rb'
|
52
49
|
- 'lib/slack-ruby-bot-server/service.rb'
|
53
50
|
|
54
51
|
# Offense count: 1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
### Changelog
|
2
2
|
|
3
|
+
#### 1.1.0 (2020/11/17)
|
4
|
+
|
5
|
+
* [#132](https://github.com/slack-ruby/slack-ruby-bot-server/pull/132): Add support for OAuth v2 - [@dblock](https://github.com/dblock).
|
6
|
+
|
7
|
+
#### 1.0.0 (2020/11/15)
|
8
|
+
|
9
|
+
* [#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).
|
10
|
+
|
11
|
+
#### 0.12.3 (2020/11/14)
|
12
|
+
|
13
|
+
* [#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).
|
14
|
+
* [#127](https://github.com/slack-ruby/slack-ruby-bot-server/pull/127): Added a Rails bot example link - [@CrazyOptimist](https://github.com/CrazyOptimist).
|
15
|
+
|
16
|
+
#### 0.12.2 (2020/7/26)
|
17
|
+
|
18
|
+
* [#120](https://github.com/slack-ruby/slack-ruby-bot-server/pull/120): Removed GIFs - [@dblock](https://github.com/dblock).
|
19
|
+
* [#121](https://github.com/slack-ruby/slack-ruby-bot-server/pull/121): Added TOC - [@dblock](https://github.com/dblock).
|
20
|
+
|
21
|
+
#### 0.12.1 (2020/5/16)
|
22
|
+
|
23
|
+
* [#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).
|
24
|
+
|
3
25
|
#### 0.12.0 (2020/4/26)
|
4
26
|
|
5
27
|
* [#113](https://github.com/slack-ruby/slack-ruby-bot-server/pull/113): Added support for intervals with `.every` - [@dblock](https://github.com/dblock).
|
data/DEBUGGING.md
CHANGED
@@ -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
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,33 +7,50 @@ Slack Ruby Bot Server
|
|
7
7
|
|
8
8
|
Build a complete Slack bot service with Slack button integration, in Ruby.
|
9
9
|
|
10
|
-
|
10
|
+
## Table of Contents
|
11
11
|
|
12
|
-
|
12
|
+
- [What is this?](#what-is-this)
|
13
|
+
- [Stable Release](#stable-release)
|
14
|
+
- [Make Your Own](#make-your-own)
|
15
|
+
- [Usage](#usage)
|
16
|
+
- [Storage](#storage)
|
17
|
+
- [MongoDB](#mongodb)
|
18
|
+
- [ActiveRecord](#activerecord)
|
19
|
+
- [OAuth Version and Scopes](#oauth-version-and-scopes)
|
20
|
+
- [Slack App](#slack-app)
|
21
|
+
- [API](#api)
|
22
|
+
- [App](#app)
|
23
|
+
- [Service Manager](#service-manager)
|
24
|
+
- [Lifecycle Callbacks](#lifecycle-callbacks)
|
25
|
+
- [Service Timers](#service-timers)
|
26
|
+
- [Extensions](#extensions)
|
27
|
+
- [Service Class](#service-class)
|
28
|
+
- [HTML Templates](#html-templates)
|
29
|
+
- [Access Tokens](#access-tokens)
|
30
|
+
- [Sample Bots Using Slack Ruby Bot Server](#sample-bots-using-slack-ruby-bot-server)
|
31
|
+
- [Slack Bots with Granular Permissions](#slack-bots-with-granular-permissions)
|
32
|
+
- [Legacy Slack Bots](#legacy-slack-bots)
|
33
|
+
- [Copyright & License](#copyright--license)
|
13
34
|
|
14
|
-
|
35
|
+
## What is this?
|
15
36
|
|
16
|
-
A library that contains a [Grape](http://github.com/ruby-grape/grape) API serving a
|
37
|
+
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
38
|
|
18
|
-
|
39
|
+
## Stable Release
|
19
40
|
|
20
|
-
You're reading the documentation for the **stable** release of slack-ruby-bot-server
|
41
|
+
You're reading the documentation for the **stable** release of slack-ruby-bot-server. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
21
42
|
|
22
|
-
|
43
|
+
## Make Your Own
|
23
44
|
|
24
|
-
|
45
|
+
This library alone will only register a new bot, but will not include any bot functionality. To make something useful, 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.
|
25
46
|
|
26
|
-
|
47
|
+
## Usage
|
27
48
|
|
28
|
-
|
49
|
+
### Storage
|
29
50
|
|
30
|
-
|
51
|
+
A database is required to store teams.
|
31
52
|
|
32
|
-
|
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.
|
35
|
-
|
36
|
-
### MongoDB
|
53
|
+
#### MongoDB
|
37
54
|
|
38
55
|
Use MongoDB with [Mongoid](https://github.com/mongodb/mongoid) as ODM. Configure the database connection in `mongoid.yml`. Add the `mongoid` gem in your Gemfile.
|
39
56
|
|
@@ -44,9 +61,7 @@ gem 'mongoid-scroll'
|
|
44
61
|
gem 'slack-ruby-bot-server'
|
45
62
|
```
|
46
63
|
|
47
|
-
|
48
|
-
|
49
|
-
### ActiveRecord
|
64
|
+
#### ActiveRecord
|
50
65
|
|
51
66
|
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.
|
52
67
|
|
@@ -58,52 +73,49 @@ gem 'otr-activerecord'
|
|
58
73
|
gem 'cursor_pagination'
|
59
74
|
```
|
60
75
|
|
61
|
-
|
76
|
+
### OAuth Version and Scopes
|
62
77
|
|
63
|
-
|
78
|
+
Configure your app's [OAuth version](https://api.slack.com/authentication/oauth-v2) and [scopes](https://api.slack.com/legacy/oauth-scopes) as needed by your application.
|
64
79
|
|
65
|
-
|
80
|
+
```ruby
|
81
|
+
SlackRubyBotServer.configure do |config|
|
82
|
+
config.oauth_version = :v2
|
83
|
+
config.oauth_scope = ['channels:read', 'chat:write']
|
84
|
+
end
|
85
|
+
```
|
66
86
|
|
67
|
-
|
87
|
+
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.
|
68
88
|
|
69
|
-
|
89
|
+
### Slack App
|
70
90
|
|
71
|
-
|
91
|
+
Create a new Slack App [here](https://api.slack.com/applications/new).
|
72
92
|
|
73
|
-
|
93
|
+
![](images/create-app.png)
|
74
94
|
|
75
|
-
|
95
|
+
Follow Slack's instructions, note the app client ID and secret, give the bot a default name, etc.
|
76
96
|
|
77
|
-
|
97
|
+
Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
|
78
98
|
|
79
|
-
|
99
|
+
Run `bundle install` and `foreman start` to boot the app.
|
80
100
|
|
81
101
|
```
|
82
|
-
|
102
|
+
$ foreman start
|
103
|
+
07:44:47 web.1 | started with pid 59258
|
104
|
+
07:44:50 web.1 | * Listening on tcp://0.0.0.0:5000
|
83
105
|
```
|
84
106
|
|
85
|
-
|
107
|
+
Set the redirect URL in "OAuth & Permissions" be the location of your app. Since you cannot receive notifications on localhost from Slack use a public tunneling service such as [ngrok](https://ngrok.com/) to expose local port 9292 for testing.
|
86
108
|
|
87
|
-
```
|
88
|
-
|
89
|
-
|
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']
|
109
|
+
```
|
110
|
+
$ ngrok http 5000
|
111
|
+
Forwarding https://ddfd97f80615.ngrok.io -> http://localhost:5000
|
100
112
|
```
|
101
113
|
|
102
|
-
|
114
|
+
Navigate to either [localhost:9292](http://localhost:9292) or the ngrok URL above. You should see an "Add to Slack" button. Use it to install the app into your own Slack team.
|
103
115
|
|
104
116
|
### API
|
105
117
|
|
106
|
-
This library implements an app, [SlackRubyBotServer::App](lib/slack-ruby-bot-server/app.rb)
|
118
|
+
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.
|
107
119
|
|
108
120
|
#### App
|
109
121
|
|
@@ -178,7 +190,7 @@ The [Add to Slack button](https://api.slack.com/docs/slack-button) also allows f
|
|
178
190
|
auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data")
|
179
191
|
```
|
180
192
|
```html
|
181
|
-
<a href="
|
193
|
+
<a href="<%= SlackRubyBotServer::Config.oauth_authorize_url %>?scope=<%= SlackRubyBotServer::Config.oauth_scope_s %>&client_id=<%= ENV['SLACK_CLIENT_ID'] %>&state=#{auth)"> ... </a>
|
182
194
|
```
|
183
195
|
```ruby
|
184
196
|
instance = SlackRubyBotServer::Service.instance
|
@@ -222,28 +234,10 @@ end
|
|
222
234
|
|
223
235
|
A number of extensions use service manager callbacks and service timers to implement useful functionality.
|
224
236
|
|
237
|
+
* [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events): Easily handle Slack slash commands, interactive buttons and events.
|
225
238
|
* [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
239
|
* [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
|
-
|
228
|
-
#### Server Class
|
229
|
-
|
230
|
-
You can override the server class to handle additional events, and configure the service to use it.
|
231
|
-
|
232
|
-
```ruby
|
233
|
-
class MyServer < SlackRubyBotServer::Server
|
234
|
-
on :hello do |client, data|
|
235
|
-
# connected to Slack
|
236
|
-
end
|
237
|
-
|
238
|
-
on :channel_joined do |client, data|
|
239
|
-
# the bot joined a channel in data.channel['id']
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
SlackRubyBotServer.configure do |config|
|
244
|
-
config.server_class = MyServer
|
245
|
-
end
|
246
|
-
```
|
240
|
+
* [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm): Create RTM Slack bots.
|
247
241
|
|
248
242
|
#### Service Class
|
249
243
|
|
@@ -278,15 +272,16 @@ end
|
|
278
272
|
|
279
273
|
### Access Tokens
|
280
274
|
|
281
|
-
By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores
|
275
|
+
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.
|
276
|
+
|
277
|
+
## Sample Bots Using Slack Ruby Bot Server
|
282
278
|
|
283
|
-
|
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`.
|
279
|
+
### Slack Bots with Granular Permissions
|
286
280
|
|
287
|
-
|
281
|
+
* [slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample), a generic sample
|
282
|
+
* [slack-rails-bot-starter](https://github.com/CrazyOptimist/slack-rails-bot-starter), an all-in-one Rails starter kit
|
288
283
|
|
289
|
-
###
|
284
|
+
### Legacy Slack Bots
|
290
285
|
|
291
286
|
* [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample), a generic sample
|
292
287
|
* [slack-sup](https://github.com/dblock/slack-sup), see [sup.playplay.io](https://sup.playplay.io)
|
@@ -297,7 +292,7 @@ You can see a sample implementation in [slack-sup#3a497b](https://github.com/dbl
|
|
297
292
|
* [slack-strava](https://github.com/dblock/slack-strava), see [slava.playplay.io](https://slava.playplay.io)
|
298
293
|
* [slack-arena](https://github.com/dblock/slack-arena), see [arena.playplay.io](https://arena.playplay.io)
|
299
294
|
|
300
|
-
|
295
|
+
## Copyright & License
|
301
296
|
|
302
297
|
Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2015-2020
|
303
298
|
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
Upgrading Slack-Ruby-Bot-Server
|
2
2
|
===============================
|
3
3
|
|
4
|
+
### Upgrading to >= 1.1.0
|
5
|
+
|
6
|
+
#### Extracted RealTime (Legacy) Support
|
7
|
+
|
8
|
+
New slack apps may no longer access RTM. Classic Slack apps can no longer be submitted to the app directory as of December 4th, 2020. In preparation for these changes slack-ruby-bot-server no longer includes RTM components by default. These have been extracted to a new gem [slack-ruby-bot-server-rtm](https://github.com/slack-ruby/slack-ruby-bot-server-rtm).
|
9
|
+
|
10
|
+
To upgrade an existing classic Slack app that uses slack-ruby-bot-server do the following.
|
11
|
+
|
12
|
+
1. Add `slack-ruby-bot-server-rtm` as an additional dependency.
|
13
|
+
2. Replace any reference to `SlackRubyBotServer::Server` to `SlackRubyBotServer::RealTime::Server`.
|
14
|
+
3. Replace any `require 'slack-ruby-bot-server/rspec'` with `require 'slack-ruby-bot-server-rtm/rspec'`.
|
15
|
+
4. Use Slack OAuth 1.0 and configure scopes.
|
16
|
+
```ruby
|
17
|
+
SlackRubyBotServer.configure do |config|
|
18
|
+
config.oauth_version = :v1
|
19
|
+
config.oauth_scope = ['bot']
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Existing RTM Slack bots will continue working and be listed in the Slack App Directory. On December 4th, 2020 Slack will no longer accept resubmissions from apps that are not using granular permissions. On November 18, 2021 Slack will start delisting apps that have not migrated to use granular permissions. Use [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events) to create a Slack bot with granular permissions. See [migration](https://api.slack.com/authentication/migration) for more details.
|
24
|
+
|
4
25
|
### Upgrading to >= 0.11.0
|
5
26
|
|
6
27
|
#### Removed Legacy Migrations
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'async
|
1
|
+
require 'async'
|
2
2
|
|
3
|
+
require 'slack-ruby-client'
|
3
4
|
require 'grape-swagger'
|
4
|
-
require 'slack-ruby-bot'
|
5
5
|
|
6
|
+
require_relative 'slack-ruby-bot-server/loggable'
|
6
7
|
require_relative 'slack-ruby-bot-server/service'
|
7
|
-
require_relative 'slack-ruby-bot-server/server'
|
8
8
|
require_relative 'slack-ruby-bot-server/config'
|
9
9
|
require_relative 'slack-ruby-bot-server/ext'
|
10
10
|
require_relative 'slack-ruby-bot-server/version'
|
@@ -40,33 +40,59 @@ module SlackRubyBotServer
|
|
40
40
|
|
41
41
|
raise 'Missing SLACK_CLIENT_ID or SLACK_CLIENT_SECRET.' unless ENV.key?('SLACK_CLIENT_ID') && ENV.key?('SLACK_CLIENT_SECRET')
|
42
42
|
|
43
|
-
|
43
|
+
options = {
|
44
44
|
client_id: ENV['SLACK_CLIENT_ID'],
|
45
45
|
client_secret: ENV['SLACK_CLIENT_SECRET'],
|
46
46
|
code: params[:code]
|
47
|
-
|
47
|
+
}
|
48
|
+
|
49
|
+
rc = client.send(SlackRubyBotServer.config.oauth_access_method, options)
|
50
|
+
|
51
|
+
token = nil
|
52
|
+
access_token = nil
|
53
|
+
user_id = nil
|
54
|
+
bot_user_id = nil
|
55
|
+
team_id = nil
|
56
|
+
team_name = nil
|
57
|
+
|
58
|
+
case SlackRubyBotServer::Config.oauth_version
|
59
|
+
when :v2
|
60
|
+
access_token = rc.access_token
|
61
|
+
token = rc.access_token
|
62
|
+
user_id = rc.authed_user&.id
|
63
|
+
bot_user_id = rc.bot_user_id
|
64
|
+
team_id = rc.team&.id
|
65
|
+
team_name = rc.team&.name
|
66
|
+
when :v1
|
67
|
+
access_token = rc.access_token
|
68
|
+
bot = rc.bot if rc.key?(:bot)
|
69
|
+
token = bot ? bot.bot_access_token : access_token
|
70
|
+
user_id = rc.user_id
|
71
|
+
bot_user_id = bot ? bot.bot_user_id : nil
|
72
|
+
team_id = rc.team_id
|
73
|
+
team_name = rc.team_name
|
74
|
+
end
|
48
75
|
|
49
|
-
token = rc['bot']['bot_access_token']
|
50
|
-
bot_user_id = rc['bot']['bot_user_id']
|
51
|
-
user_id = rc['user_id']
|
52
|
-
access_token = rc['access_token']
|
53
76
|
team = Team.where(token: token).first
|
54
|
-
team ||= Team.where(team_id:
|
77
|
+
team ||= Team.where(team_id: team_id).first
|
55
78
|
|
56
79
|
if team
|
80
|
+
team.ping_if_active!
|
81
|
+
|
57
82
|
team.update_attributes!(
|
58
83
|
activated_user_id: user_id,
|
59
84
|
activated_user_access_token: access_token,
|
60
85
|
bot_user_id: bot_user_id
|
61
86
|
)
|
87
|
+
|
62
88
|
raise "Team #{team.name} is already registered." if team.active?
|
63
89
|
|
64
90
|
team.activate!(token)
|
65
91
|
else
|
66
92
|
team = Team.create!(
|
67
93
|
token: token,
|
68
|
-
team_id:
|
69
|
-
name:
|
94
|
+
team_id: team_id,
|
95
|
+
name: team_name,
|
70
96
|
activated_user_id: user_id,
|
71
97
|
activated_user_access_token: access_token,
|
72
98
|
bot_user_id: bot_user_id
|