slack-ruby-bot-server-events 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/danger-comment.yml +16 -0
- data/.github/workflows/danger.yml +11 -20
- data/.github/workflows/lint.yml +29 -0
- data/.github/workflows/release.yml +28 -0
- data/.github/workflows/test.yml +84 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +91 -5
- data/.rubocop_todo.yml +15 -21
- data/.spellcheck.txt +43 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +16 -20
- data/Dangerfile +4 -1
- data/Gemfile +23 -4
- data/README.md +102 -28
- data/RELEASING.md +20 -42
- data/Rakefile +22 -3
- data/lib/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint.rb +44 -2
- data/lib/slack-ruby-bot-server-events/config.rb +25 -8
- data/lib/slack-ruby-bot-server-events/version.rb +1 -1
- data/script/release.rb +15 -0
- data/slack-ruby-bot-server-events.gemspec +1 -3
- metadata +13 -7
- data/.github/workflows/rubocop.yml +0 -16
- data/.github/workflows/test-mongodb.yml +0 -32
- data/.github/workflows/test-postgresql.yml +0 -39
- data/Gemfile.danger +0 -6
data/README.md
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
Slack Ruby Bot Server Events Extension
|
|
2
|
-
======================================
|
|
1
|
+
# Slack Ruby Bot Server Events Extension
|
|
3
2
|
|
|
4
|
-
[](https://badge.fury.io/rb/slack-ruby-bot-server-events)
|
|
5
|
-
[](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/rubocop.yml)
|
|
6
|
-
[](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-mongodb.yml)
|
|
7
|
-
[](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-postgresql.yml)
|
|
3
|
+
[](https://badge.fury.io/rb/slack-ruby-bot-server-events) [](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/lint.yml) [](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test.yml)
|
|
8
4
|
|
|
9
5
|
An extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that makes it easy to handle Slack slash commands, interactive buttons and events.
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
## Table of Contents
|
|
12
8
|
|
|
13
9
|
- [Sample](#sample)
|
|
14
10
|
- [Usage](#usage)
|
|
@@ -20,15 +16,16 @@ An extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby
|
|
|
20
16
|
- [Events](#events-1)
|
|
21
17
|
- [Actions](#actions)
|
|
22
18
|
- [Commands](#commands)
|
|
19
|
+
- [Testing](#testing)
|
|
23
20
|
- [Copyright & License](#copyright--license)
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
## Sample
|
|
26
23
|
|
|
27
24
|
See [slack-ruby/slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample) for a working sample.
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
## Usage
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
### Gemfile
|
|
32
29
|
|
|
33
30
|
Add 'slack-ruby-bot-server-events' to Gemfile.
|
|
34
31
|
|
|
@@ -36,9 +33,9 @@ Add 'slack-ruby-bot-server-events' to Gemfile.
|
|
|
36
33
|
gem 'slack-ruby-bot-server-events'
|
|
37
34
|
```
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
### Configure
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
#### OAuth
|
|
42
39
|
|
|
43
40
|
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.
|
|
44
41
|
|
|
@@ -49,7 +46,7 @@ SlackRubyBotServer.configure do |config|
|
|
|
49
46
|
end
|
|
50
47
|
```
|
|
51
48
|
|
|
52
|
-
|
|
49
|
+
#### Events
|
|
53
50
|
|
|
54
51
|
Configure events-specific settings.
|
|
55
52
|
|
|
@@ -61,18 +58,18 @@ end
|
|
|
61
58
|
|
|
62
59
|
The following settings are supported.
|
|
63
60
|
|
|
64
|
-
setting
|
|
65
|
-
|
|
66
|
-
signing_secret
|
|
67
|
-
signature_expires_in
|
|
61
|
+
setting | description
|
|
62
|
+
---------------------- | ------------------------------------------------------------------
|
|
63
|
+
signing_secret | Slack signing secret, default is `ENV['SLACK_SIGNING_SECRET']`.
|
|
64
|
+
signature_expires_in | Signature expiration window in seconds, default is `300`.
|
|
68
65
|
|
|
69
66
|
Get the signing secret from [your app's](https://api.slack.com/apps) _Basic Information_ settings.
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
### Implement Callbacks
|
|
72
69
|
|
|
73
|
-
This library supports events, actions and commands. When implementing multiple callbacks for each type, the response from the first callback to return a non `nil` value will be used and no further callbacks will be invoked. Callbacks receive subclasses of [SlackRubyBotServer::Events::Requests::Request](lib/slack-ruby-bot-server-events/requests/request.rb).
|
|
70
|
+
This library supports events, actions and commands. When implementing multiple callbacks for each type, the response from the first callback to return a non `nil` value will be used and no further callbacks will be invoked. Callbacks receive subclasses of [SlackRubyBotServer::Events::Requests::Request](lib/slack-ruby-bot-server-events/requests/request.rb). When a callback raises an error, the error is logged with the callback's key, such as `event/event_callback/team_join`, and the file and line where the callback was defined, then raised again.
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
### Events
|
|
76
73
|
|
|
77
74
|
Respond to [Slack Events](https://api.slack.com/events-api) by implementing `SlackRubyBotServer::Events::Config#on :event`.
|
|
78
75
|
|
|
@@ -81,8 +78,9 @@ The following example unfurls URLs.
|
|
|
81
78
|
```ruby
|
|
82
79
|
SlackRubyBotServer::Events.configure do |config|
|
|
83
80
|
config.on :event, 'event_callback', 'link_shared' do |event|
|
|
81
|
+
team = Team.where(team_id: event[:team_id]).first
|
|
84
82
|
event[:event][:links].each do |link|
|
|
85
|
-
Slack::Web::Client.new(token:
|
|
83
|
+
Slack::Web::Client.new(token: team.token).chat_unfurl(
|
|
86
84
|
channel: event[:event][:channel],
|
|
87
85
|
ts: event[:event][:message_ts],
|
|
88
86
|
unfurls: {
|
|
@@ -106,10 +104,20 @@ SlackRubyBotServer::Events.configure do |config|
|
|
|
106
104
|
end
|
|
107
105
|
```
|
|
108
106
|
|
|
107
|
+
Pass an array of values to handle several events with one callback.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
SlackRubyBotServer::Events.configure do |config|
|
|
111
|
+
config.on :event, 'event_callback', %w[pin_added pin_removed] do |event|
|
|
112
|
+
# handle event[:event][:type] of pin_added or pin_removed
|
|
113
|
+
true
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
```
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
### Actions
|
|
111
119
|
|
|
112
|
-
Respond to [Shortcuts](https://api.slack.com/interactivity/shortcuts) and [Interactive Messages](https://api.slack.com/messaging/interactivity) as well as [Attached Interactive Message Buttons(Outmoded)](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
|
|
120
|
+
Respond to [Shortcuts](https://api.slack.com/interactivity/shortcuts) and [Interactive Messages](https://api.slack.com/messaging/interactivity) as well as [Attached Interactive Message Buttons (Outmoded)](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
|
|
113
121
|
|
|
114
122
|
The following example posts an ephemeral message that counts the letters in a message shortcut.
|
|
115
123
|
|
|
@@ -134,8 +142,7 @@ SlackRubyBotServer::Events.configure do |config|
|
|
|
134
142
|
end
|
|
135
143
|
```
|
|
136
144
|
|
|
137
|
-
The following example responds to an interactive message.
|
|
138
|
-
You can compose rich message layouts using [Block Kit Builder](https://app.slack.com/block-kit-builder).
|
|
145
|
+
The following example responds to an interactive message. You can compose rich message layouts using [Block Kit Builder](https://app.slack.com/block-kit-builder).
|
|
139
146
|
|
|
140
147
|
```ruby
|
|
141
148
|
SlackRubyBotServer::Events.configure do |config|
|
|
@@ -143,7 +150,7 @@ SlackRubyBotServer::Events.configure do |config|
|
|
|
143
150
|
payload = action[:payload]
|
|
144
151
|
|
|
145
152
|
Faraday.post(payload[:response_url], {
|
|
146
|
-
text:
|
|
153
|
+
text: 'The action "your_action_id" has been invoked.',
|
|
147
154
|
response_type: 'ephemeral'
|
|
148
155
|
}.to_json, 'Content-Type' => 'application/json')
|
|
149
156
|
|
|
@@ -152,7 +159,34 @@ SlackRubyBotServer::Events.configure do |config|
|
|
|
152
159
|
end
|
|
153
160
|
```
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
The following example loads the options of an [external select menu](https://api.slack.com/reference/block-kit/block-elements#external_select) with `action_id: 'your_action_id'`. For `block_suggestion` payloads the action ID is read from `payload.action_id`.
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
SlackRubyBotServer::Events.configure do |config|
|
|
166
|
+
config.on :action, 'block_suggestion', 'your_action_id' do |action|
|
|
167
|
+
query = action[:payload][:value]
|
|
168
|
+
{
|
|
169
|
+
options: %w[one two three].grep(/#{Regexp.escape(query)}/).map do |value|
|
|
170
|
+
{ text: { type: 'plain_text', text: value }, value: value }
|
|
171
|
+
end
|
|
172
|
+
}
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The following example handles the submission of a [modal](https://api.slack.com/surfaces/modals) opened with `callback_id: 'your_callback_id'`. For `view_submission` and `view_closed` payloads the callback ID is read from `payload.view.callback_id`.
|
|
178
|
+
|
|
179
|
+
```ruby
|
|
180
|
+
SlackRubyBotServer::Events.configure do |config|
|
|
181
|
+
config.on :action, 'view_submission', 'your_callback_id' do |action|
|
|
182
|
+
values = action[:payload][:view][:state][:values]
|
|
183
|
+
action.logger.info "Submitted #{values}."
|
|
184
|
+
{ response_action: 'clear' }
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Commands
|
|
156
190
|
|
|
157
191
|
Respond to [Slash Commands](https://api.slack.com/interactivity/slash-commands) by implementing `SlackRubyBotServer::Events::Config#on :command`.
|
|
158
192
|
|
|
@@ -171,7 +205,47 @@ SlackRubyBotServer::Events.configure do |config|
|
|
|
171
205
|
end
|
|
172
206
|
```
|
|
173
207
|
|
|
174
|
-
|
|
208
|
+
## Testing
|
|
209
|
+
|
|
210
|
+
Test callbacks by posting a request to the API with [Rack::Test](https://github.com/rack/rack-test) and stubbing Slack's signature verification. Pass the parameters as the second argument to `post`, not as `params:`, and include every parameter that Slack sends and the endpoint requires, otherwise the API responds with a `400` error before any callback runs. Check the response status to catch such errors.
|
|
211
|
+
|
|
212
|
+
The following spec tests the `/ping` command above.
|
|
213
|
+
|
|
214
|
+
```ruby
|
|
215
|
+
describe '/ping' do
|
|
216
|
+
include Rack::Test::Methods
|
|
217
|
+
|
|
218
|
+
def app
|
|
219
|
+
SlackRubyBotServer::Api::Middleware.instance
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
before do
|
|
223
|
+
allow_any_instance_of(Slack::Events::Request).to receive(:verify!)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
let(:command) do
|
|
227
|
+
{
|
|
228
|
+
command: '/ping',
|
|
229
|
+
text: '',
|
|
230
|
+
token: 'deprecated',
|
|
231
|
+
user_id: 'U12345',
|
|
232
|
+
channel_id: 'C12345',
|
|
233
|
+
channel_name: 'general',
|
|
234
|
+
team_id: 'T12345'
|
|
235
|
+
}
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'responds with pong' do
|
|
239
|
+
post '/api/slack/command', command
|
|
240
|
+
expect(last_response.status).to eq 201
|
|
241
|
+
expect(JSON.parse(last_response.body)).to eq('text' => 'pong')
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Events are posted to `/api/slack/event` and actions to `/api/slack/action` with a JSON `payload` parameter, for example `post '/api/slack/action', payload: { type: 'block_actions', ... }.to_json`. See [spec/slack-ruby-bot-server-events/api/endpoints/slack](spec/slack-ruby-bot-server-events/api/endpoints/slack) for more examples.
|
|
247
|
+
|
|
248
|
+
## Copyright & License
|
|
175
249
|
|
|
176
250
|
Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2020-2025
|
|
177
251
|
|
data/RELEASING.md
CHANGED
|
@@ -1,61 +1,39 @@
|
|
|
1
1
|
# Releasing Slack-Ruby-Bot-Server-Events
|
|
2
2
|
|
|
3
|
-
There
|
|
3
|
+
There are no hard rules about when to release slack-ruby-bot-server-events. Release bug fixes frequently, features not so frequently, and breaking API changes rarely.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Releases use [ruby-gem-release](https://github.com/dblock/ruby-gem-release) 0.9.0 through a manually dispatched [Release workflow](.github/workflows/release.yml). Keep the `ruby-gem-release` gem in [Gemfile](Gemfile) and the reusable workflow in `release.yml` pinned to the same version. The workflow publishes through RubyGems Trusted Publishing, so no RubyGems API key or one-time password is needed. It only runs from `master` in `slack-ruby/slack-ruby-bot-server-events`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## One-Time Setup
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
bundle install
|
|
11
|
-
rake
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Check that the last build succeeded in [Travis CI](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events) for all supported platforms.
|
|
15
|
-
|
|
16
|
-
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
### 0.2.2 (7/10/2015)
|
|
20
|
-
```
|
|
9
|
+
Before the first automated release, a maintainer must:
|
|
21
10
|
|
|
22
|
-
|
|
11
|
+
1. Create the GitHub environment `release` in `slack-ruby/slack-ruby-bot-server-events`, for example with `gh api --method PUT repos/slack-ruby/slack-ruby-bot-server-events/environments/release`, and restrict its deployment branches to `master`. Add required reviewers to require maintainer approval before publication.
|
|
12
|
+
2. At the [trusted publishers for slack-ruby-bot-server-events](https://rubygems.org/gems/slack-ruby-bot-server-events/trusted_publishers), add a GitHub Actions publisher with repository owner `slack-ruby`, repository `slack-ruby-bot-server-events`, workflow filename `release.yml`, environment `release`, and the separate workflow repository owner `dblock` and repository `ruby-gem-release`.
|
|
13
|
+
3. Allow GitHub Actions to push release commits and `v*` tags to `master`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
Verify the setup without publishing with a [dry run](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#dry-run), which never edits files, builds, pushes, or publishes:
|
|
25
16
|
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
git commit -m "Preparing for release, 0.2.2."
|
|
29
|
-
git push origin master
|
|
17
|
+
```sh
|
|
18
|
+
gh workflow run release.yml --repo slack-ruby/slack-ruby-bot-server-events --ref master -f dry-run=true
|
|
30
19
|
```
|
|
31
20
|
|
|
32
|
-
|
|
21
|
+
## Prepare
|
|
33
22
|
|
|
34
|
-
|
|
35
|
-
$ rake release
|
|
23
|
+
Start with a clean, up-to-date `master` and verify that the latest [CI checks](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions) pass for all supported Ruby versions, MongoDB, and PostgreSQL. The Release workflow cannot start a database, so it runs lint and the release specs, but not the database specs; the Test workflow on `master` is the only check of those. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/slack-ruby-bot-server-events/version.rb](lib/slack-ruby-bot-server-events/version.rb) and the matching `(Next)` heading in [CHANGELOG.md](CHANGELOG.md), and change both in a pull request if needed, or pass a `version` override when dispatching.
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
Tagged v0.2.2.
|
|
39
|
-
Pushed git commits and tags.
|
|
40
|
-
Pushed slack-ruby-bot-server-events 0.2.2 to rubygems.org.
|
|
41
|
-
```
|
|
25
|
+
The workflow dates the `(Next)` heading using `YYYY/MM/DD` and removes the `* Your contribution here.` placeholder; a section without notes cannot be released.
|
|
42
26
|
|
|
43
|
-
|
|
27
|
+
Release automation requires MRI Ruby 3.3 or newer; the release dependency and tasks are skipped on older Ruby versions and JRuby. Release specs in [spec/release](spec/release) run the actual release tasks against a local fixture with the [ruby-gem-release RSpec helpers](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/testing.md), without contacting RubyGems or GitHub.
|
|
44
28
|
|
|
45
|
-
|
|
29
|
+
## Publish
|
|
46
30
|
|
|
31
|
+
```sh
|
|
32
|
+
gh workflow run release.yml --repo slack-ruby/slack-ruby-bot-server-events --ref master
|
|
47
33
|
```
|
|
48
|
-
### 0.2.3 (Next)
|
|
49
34
|
|
|
50
|
-
|
|
51
|
-
```
|
|
35
|
+
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `master` while it runs. The workflow prepares the release commit, runs lint and release specs on Ruby 3.3, builds the gem, preserves recovery artifacts, publishes to RubyGems, pushes the release commit and `v` tag, and creates a GitHub Release with the changelog notes and the gem attached. It then increments the patch version, adds a new `(Next)` section, and pushes the next development commit. Verify the published version on [RubyGems](https://rubygems.org/gems/slack-ruby-bot-server-events), the tag, the [GitHub Release](https://github.com/slack-ruby/slack-ruby-bot-server-events/releases), and the next development commit.
|
|
52
36
|
|
|
53
|
-
|
|
37
|
+
## Recover a Partial Release
|
|
54
38
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
git add CHANGELOG.md lib/slack-ruby-bot-server-events/version.rb
|
|
59
|
-
git commit -m "Preparing for next development iteration, 0.2.3."
|
|
60
|
-
git push origin master
|
|
61
|
-
```
|
|
39
|
+
Inspect the failed run, RubyGems, remote commits and tags, and the GitHub Release before retrying. Publication may have succeeded even if a later step failed. Never move a published tag or republish a version with different contents. Use the run's retained recovery artifacts and the upstream [recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts).
|
data/Rakefile
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'bundler/gem_tasks'
|
|
5
5
|
|
|
6
|
+
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
7
|
+
Gem.loaded_specs.key?('ruby-gem-release')
|
|
8
|
+
require_relative 'script/release'
|
|
9
|
+
SlackRubyBotServerEventsRelease.workflow.install_tasks
|
|
10
|
+
|
|
11
|
+
%w[release release:rubygem_push release:source_control_push].each do |name|
|
|
12
|
+
Rake::Task[name].clear
|
|
13
|
+
desc 'Disabled; releases run through GitHub Actions, see RELEASING.md'
|
|
14
|
+
task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
6
18
|
require 'rspec/core'
|
|
7
19
|
require 'rspec/core/rake_task'
|
|
8
20
|
|
|
@@ -10,7 +22,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
|
10
22
|
spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext/(?!#{ENV.fetch('DATABASE_ADAPTER', nil)})})
|
|
11
23
|
end
|
|
12
24
|
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
lint = RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
26
|
+
Gem.loaded_specs.key?('rubocop')
|
|
27
|
+
if lint
|
|
28
|
+
require 'rubocop/rake_task'
|
|
29
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
30
|
+
|
|
31
|
+
desc 'Lint Ruby, Markdown, YAML, and spelling'
|
|
32
|
+
task lint: :rubocop
|
|
33
|
+
end
|
|
15
34
|
|
|
16
|
-
task default: %i[rubocop spec]
|
|
35
|
+
task default: lint ? %i[rubocop spec] : %i[spec]
|
|
@@ -67,13 +67,55 @@ module SlackRubyBotServer
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
|
+
|
|
71
|
+
given type: ->(val) { val == 'block_suggestion' } do
|
|
72
|
+
optional :token, type: String
|
|
73
|
+
requires :action_id, type: String
|
|
74
|
+
optional :block_id, type: String
|
|
75
|
+
optional :value, type: String
|
|
76
|
+
requires :user, type: Hash do
|
|
77
|
+
requires :id, type: String
|
|
78
|
+
optional :name, type: String
|
|
79
|
+
end
|
|
80
|
+
requires :team, type: Hash do
|
|
81
|
+
requires :id, type: String
|
|
82
|
+
optional :domain, type: String
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
given type: ->(val) { %w[view_submission view_closed].include? val } do
|
|
87
|
+
optional :token, type: String
|
|
88
|
+
optional :trigger_id, type: String
|
|
89
|
+
requires :user, type: Hash do
|
|
90
|
+
requires :id, type: String
|
|
91
|
+
optional :name, type: String
|
|
92
|
+
end
|
|
93
|
+
requires :team, type: Hash do
|
|
94
|
+
requires :id, type: String
|
|
95
|
+
optional :domain, type: String
|
|
96
|
+
end
|
|
97
|
+
requires :view, type: Hash do
|
|
98
|
+
requires :id, type: String
|
|
99
|
+
optional :type, type: String
|
|
100
|
+
optional :callback_id, type: String
|
|
101
|
+
optional :private_metadata, type: String
|
|
102
|
+
end
|
|
103
|
+
end
|
|
70
104
|
end
|
|
71
105
|
end
|
|
72
106
|
post '/action' do
|
|
73
107
|
action = SlackRubyBotServer::Events::Requests::Action.new(params, request)
|
|
74
108
|
payload_type = params[:payload][:type]
|
|
75
|
-
callback_id =
|
|
76
|
-
|
|
109
|
+
callback_id = if %w[view_submission view_closed].include?(payload_type)
|
|
110
|
+
params[:payload].dig(:view, :callback_id).presence
|
|
111
|
+
else
|
|
112
|
+
params[:payload][:callback_id]
|
|
113
|
+
end
|
|
114
|
+
action_ids = if payload_type == 'block_suggestion'
|
|
115
|
+
[params[:payload][:action_id]]
|
|
116
|
+
else
|
|
117
|
+
params[:payload].fetch(:actions, []).map { |entity| entity[:action_id] }
|
|
118
|
+
end
|
|
77
119
|
SlackRubyBotServer::Events.config.run_callbacks(
|
|
78
120
|
:action,
|
|
79
121
|
([payload_type, callback_id] + action_ids).compact,
|
|
@@ -23,10 +23,16 @@ module SlackRubyBotServer
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
# Register a callback for a type and an optional path of values, e.g. on(:event, 'event_callback', 'team_join').
|
|
27
|
+
# The path may also be given as a single array. An array within the path lists alternatives, and the callback
|
|
28
|
+
# is registered for each combination, e.g. on(:event, 'event_callback', %w[pin_added pin_removed]).
|
|
26
29
|
def on(type, *values, &block)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
values = values.first if values.size == 1 && values.first.is_a?(Array)
|
|
31
|
+
alternatives = values.compact.map { |value| Array(value).map(&:to_s) }
|
|
32
|
+
paths = alternatives.empty? ? [[]] : alternatives.first.product(*alternatives.drop(1))
|
|
33
|
+
paths.each do |path|
|
|
34
|
+
callbacks[[type.to_s, *path].join('/')] << block
|
|
35
|
+
end
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def run_callbacks(type, value, args)
|
|
@@ -36,19 +42,30 @@ module SlackRubyBotServer
|
|
|
36
42
|
|
|
37
43
|
# more specific callbacks first
|
|
38
44
|
while keys.any?
|
|
39
|
-
|
|
45
|
+
key = keys.join('/')
|
|
46
|
+
callbacks += self.callbacks[key].map { |c| [key, c] }
|
|
40
47
|
keys.pop
|
|
41
48
|
end
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
callbacks.each do |c|
|
|
46
|
-
rc = c.call(args || value)
|
|
50
|
+
callbacks.each do |key, c|
|
|
51
|
+
rc = run_callback(key, c, args || value)
|
|
47
52
|
return rc if rc
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
nil
|
|
51
56
|
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def run_callback(key, callback, args)
|
|
61
|
+
callback.call(args)
|
|
62
|
+
rescue StandardError => e
|
|
63
|
+
location = callback.source_location&.first(2)&.join(':')
|
|
64
|
+
SlackRubyBotServer::Api::Middleware.logger.error(
|
|
65
|
+
"#{e.class.name} in #{key} callback defined at #{location || 'an unknown location'}: #{e.message}"
|
|
66
|
+
)
|
|
67
|
+
raise
|
|
68
|
+
end
|
|
52
69
|
end
|
|
53
70
|
|
|
54
71
|
class << self
|
data/script/release.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruby-gem-release/changelog'
|
|
4
|
+
require 'ruby-gem-release/workflow/ruby_gem'
|
|
5
|
+
|
|
6
|
+
# Builds the ruby-gem-release workflow used by the Rakefile, the Release GitHub Actions workflow, and spec/release.
|
|
7
|
+
module SlackRubyBotServerEventsRelease
|
|
8
|
+
def self.workflow(**options)
|
|
9
|
+
RubyGemRelease::Workflow::RubyGem.new(
|
|
10
|
+
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/slack-ruby-bot-server-events/version.rb', constant: 'VERSION'),
|
|
11
|
+
changelog: RubyGemRelease::Changelog::Intridea.new(placeholder: '* Your contribution here.'),
|
|
12
|
+
**options
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require 'slack-ruby-bot-server-events/version'
|
|
3
|
+
require_relative 'lib/slack-ruby-bot-server-events/version'
|
|
6
4
|
|
|
7
5
|
Gem::Specification.new do |spec|
|
|
8
6
|
spec.name = 'slack-ruby-bot-server-events'
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack-ruby-bot-server-events
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Doubrovkine
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: slack-ruby-bot-server
|
|
@@ -23,25 +24,27 @@ dependencies:
|
|
|
23
24
|
- - ">="
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
26
|
version: 0.12.0
|
|
27
|
+
description:
|
|
26
28
|
email:
|
|
27
29
|
- dblock@dblock.org
|
|
28
30
|
executables: []
|
|
29
31
|
extensions: []
|
|
30
32
|
extra_rdoc_files: []
|
|
31
33
|
files:
|
|
34
|
+
- ".github/workflows/danger-comment.yml"
|
|
32
35
|
- ".github/workflows/danger.yml"
|
|
33
|
-
- ".github/workflows/
|
|
34
|
-
- ".github/workflows/
|
|
35
|
-
- ".github/workflows/test
|
|
36
|
+
- ".github/workflows/lint.yml"
|
|
37
|
+
- ".github/workflows/release.yml"
|
|
38
|
+
- ".github/workflows/test.yml"
|
|
36
39
|
- ".gitignore"
|
|
37
40
|
- ".rspec"
|
|
38
41
|
- ".rubocop.yml"
|
|
39
42
|
- ".rubocop_todo.yml"
|
|
43
|
+
- ".spellcheck.txt"
|
|
40
44
|
- CHANGELOG.md
|
|
41
45
|
- CONTRIBUTING.md
|
|
42
46
|
- Dangerfile
|
|
43
47
|
- Gemfile
|
|
44
|
-
- Gemfile.danger
|
|
45
48
|
- LICENSE
|
|
46
49
|
- README.md
|
|
47
50
|
- RELEASING.md
|
|
@@ -62,11 +65,13 @@ files:
|
|
|
62
65
|
- lib/slack-ruby-bot-server-events/version.rb
|
|
63
66
|
- lib/slack-ruby-bot-server/api.rb
|
|
64
67
|
- lib/slack-ruby-bot-server/api/endpoints.rb
|
|
68
|
+
- script/release.rb
|
|
65
69
|
- slack-ruby-bot-server-events.gemspec
|
|
66
70
|
homepage: https://github.com/slack-ruby/slack-ruby-bot-server-events
|
|
67
71
|
licenses: []
|
|
68
72
|
metadata:
|
|
69
73
|
rubygems_mfa_required: 'true'
|
|
74
|
+
post_install_message:
|
|
70
75
|
rdoc_options: []
|
|
71
76
|
require_paths:
|
|
72
77
|
- lib
|
|
@@ -81,7 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
81
86
|
- !ruby/object:Gem::Version
|
|
82
87
|
version: '0'
|
|
83
88
|
requirements: []
|
|
84
|
-
rubygems_version: 3.
|
|
89
|
+
rubygems_version: 3.5.22
|
|
90
|
+
signing_key:
|
|
85
91
|
specification_version: 4
|
|
86
92
|
summary: Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
|
|
87
93
|
test_files: []
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: lint
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
jobs:
|
|
5
|
-
lint:
|
|
6
|
-
name: RuboCop
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v2
|
|
10
|
-
- name: Set up Ruby
|
|
11
|
-
uses: ruby/setup-ruby@v1
|
|
12
|
-
with:
|
|
13
|
-
ruby-version: 3.4
|
|
14
|
-
bundler-cache: true
|
|
15
|
-
- name: Run RuboCop
|
|
16
|
-
run: bundle exec rubocop
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: test with mongodb
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
jobs:
|
|
5
|
-
test:
|
|
6
|
-
runs-on: ubuntu-latest
|
|
7
|
-
strategy:
|
|
8
|
-
matrix:
|
|
9
|
-
entry:
|
|
10
|
-
- { ruby: 3.1, mongoid: 6.4.8, mongodb: 4.4 }
|
|
11
|
-
- { ruby: 3.1, mongoid: 7.3.0, mongodb: 5.0 }
|
|
12
|
-
- { ruby: 3.1, mongoid: 7.3.0, mongodb: 5.0 }
|
|
13
|
-
- { ruby: 3.2, mongoid: 8.1.11, mongodb: 6.0 }
|
|
14
|
-
- { ruby: 3.4, mongoid: 8.1.11, mongodb: 7.0 }
|
|
15
|
-
- { ruby: 3.4, mongoid: 9.0.8, mongodb: 8.0 }
|
|
16
|
-
name: test (ruby=${{ matrix.entry.ruby }}, mongoid=${{ matrix.entry.mongoid }}, mongodb=${{ matrix.entry.mongodb }})
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@v2
|
|
19
|
-
- uses: ruby/setup-ruby@v1
|
|
20
|
-
with:
|
|
21
|
-
ruby-version: ${{ matrix.entry.ruby }}
|
|
22
|
-
- uses: supercharge/mongodb-github-action@1.7.0
|
|
23
|
-
with:
|
|
24
|
-
mongodb-version: ${{ matrix.entry.mongodb }}
|
|
25
|
-
- name: Test
|
|
26
|
-
run: |
|
|
27
|
-
bundle install
|
|
28
|
-
bundle exec rake spec
|
|
29
|
-
env:
|
|
30
|
-
DATABASE_ADAPTER: mongoid
|
|
31
|
-
DATABASE_URL: "mongodb://localhost"
|
|
32
|
-
MONGOID_VERSION: ${{ matrix.entry.mongoid }}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: test with postgresql
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
jobs:
|
|
5
|
-
test:
|
|
6
|
-
runs-on: ubuntu-latest
|
|
7
|
-
strategy:
|
|
8
|
-
matrix:
|
|
9
|
-
entry:
|
|
10
|
-
- { ruby: 3.1, postgresql: 11 }
|
|
11
|
-
- { ruby: 3.1, postgresql: 14 }
|
|
12
|
-
- { ruby: 3.1, postgresql: 14 }
|
|
13
|
-
- { ruby: 3.2, postgresql: 15 }
|
|
14
|
-
- { ruby: 3.3, postgresql: 16 }
|
|
15
|
-
- { ruby: 3.4, postgresql: 17 }
|
|
16
|
-
name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }})
|
|
17
|
-
services:
|
|
18
|
-
postgres:
|
|
19
|
-
image: postgres:${{ matrix.entry.postgresql }}
|
|
20
|
-
env:
|
|
21
|
-
POSTGRES_USER: test
|
|
22
|
-
POSTGRES_PASSWORD: password
|
|
23
|
-
POSTGRES_DB: slack_ruby_bot_server_events_test
|
|
24
|
-
ports:
|
|
25
|
-
- 5432:5432
|
|
26
|
-
# needed because the postgres container does not provide a healthcheck
|
|
27
|
-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
28
|
-
steps:
|
|
29
|
-
- uses: actions/checkout@v2
|
|
30
|
-
- uses: ruby/setup-ruby@v1
|
|
31
|
-
with:
|
|
32
|
-
ruby-version: ${{ matrix.entry.ruby }}
|
|
33
|
-
- name: Test
|
|
34
|
-
run: |
|
|
35
|
-
bundle install
|
|
36
|
-
bundle exec rake spec
|
|
37
|
-
env:
|
|
38
|
-
DATABASE_ADAPTER: activerecord
|
|
39
|
-
DATABASE_URL: postgres://test:password@localhost/slack_ruby_bot_server_events_test
|