slack-ruby-bot-server-events 0.2.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17a7e4563e7eb26dcd8ca99fbe366c3024d927d0716576984ce7371578148ff7
4
- data.tar.gz: 7c366ef08784262accb9de4e9a9432c01a30226c24c4e01f3ff0eb6875593701
3
+ metadata.gz: 6c97cea49ad88b67c93b7d7bd75b7bae4cb873abad8f3afb0760623124679deb
4
+ data.tar.gz: d49cecc2fefaef91fff2c7b0da99ea665e956a55d3d806bc9a26bd97e89ff491
5
5
  SHA512:
6
- metadata.gz: fef7839cbbdd0892aebc3177a5996603a2cbf89d54b06ed71fb06d85163f27039f7ece113c2ade62b8d12b49cab24d7dfd31d7c67d39b96dde1bfbb7fab1ac73
7
- data.tar.gz: a08625699825f3bbfee9c1ec6929bec5a1f7ecdf3a6a16d111a7d543f151000c4498949da68fec417b05d56d1aad23dcd065bffb2b97a752ca3ea22a3108ef9f
6
+ metadata.gz: 2ab1888588e34c0920955e5975fe8f3ece436e036271ef78556cfd9c2ba655b42ef886ee3a8ea481c43cd0c6356e871fb85b8a97fcaef4489202cebbd0e57038
7
+ data.tar.gz: 3d1e7ae990f0e91e73a07a3305d2a4b7b993316c987f50e4e27d171131c22ad0a60e4f449ac1a3b5ed8321b4af6bd8271b67d5bf972e78951cf5ce88d2c44a1b
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: danger
3
+ on: [pull_request]
4
+ jobs:
5
+ danger:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ with:
10
+ fetch-depth: 0
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.6
15
+ bundler-cache: true
16
+ - name: Run Danger
17
+ env:
18
+ BUNDLE_GEMFILE: Gemfile.danger
19
+ run: |
20
+ bundle install
21
+ # the personal token is public, this is ok, base64 encode to avoid tripping Github
22
+ TOKEN=$(echo -n NWY1ZmM5MzEyMzNlYWY4OTZiOGU3MmI3MWQ3Mzk0MzgxMWE4OGVmYwo= | base64 --decode)
23
+ DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
@@ -0,0 +1,16 @@
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: 2.7
14
+ bundler-cache: true
15
+ - name: Run RuboCop
16
+ run: bundle exec rubocop
@@ -0,0 +1,29 @@
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: 2.6.2, mongoid: 6.4.8, mongodb: 4.4 }
11
+ - { ruby: 2.7.2, mongoid: 7.3.0, mongodb: 5.0 }
12
+ - { ruby: 3.1.1, mongoid: 7.3.0, mongodb: 5.0 }
13
+ name: test (ruby=${{ matrix.entry.ruby }}, mongoid=${{ matrix.entry.mongoid }}, mongodb=${{ matrix.entry.mongodb }})
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.entry.ruby }}
19
+ - uses: supercharge/mongodb-github-action@1.7.0
20
+ with:
21
+ mongodb-version: ${{ matrix.entry.mongodb }}
22
+ - name: Test
23
+ run: |
24
+ bundle install
25
+ bundle exec rake spec
26
+ env:
27
+ DATABASE_ADAPTER: mongoid
28
+ DATABASE_URL: "mongodb://localhost"
29
+ MONGOID_VERSION: ${{ matrix.entry.mongoid }}
@@ -0,0 +1,36 @@
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: 2.6.2, postgresql: 11 }
11
+ - { ruby: 2.7.2, postgresql: 14 }
12
+ - { ruby: 3.1.1, postgresql: 14 }
13
+ name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }})
14
+ services:
15
+ postgres:
16
+ image: postgres:${{ matrix.entry.postgresql }}
17
+ env:
18
+ POSTGRES_USER: test
19
+ POSTGRES_PASSWORD: password
20
+ POSTGRES_DB: slack_ruby_bot_server_events_test
21
+ ports:
22
+ - 5432:5432
23
+ # needed because the postgres container does not provide a healthcheck
24
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.entry.ruby }}
30
+ - name: Test
31
+ run: |
32
+ bundle install
33
+ bundle exec rake spec
34
+ env:
35
+ DATABASE_ADAPTER: activerecord
36
+ DATABASE_URL: postgres://test:password@localhost/slack_ruby_bot_server_events_test
data/CHANGELOG.md CHANGED
@@ -1,9 +1,23 @@
1
1
  ### Changelog
2
2
 
3
- #### 0.2.0 (07/19/2020)
3
+ #### 0.3.2 (2022/06/09)
4
+
5
+ * [#13](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/13): Replace Travis CI with Github Actions - [@CrazyOptimist](https://github.com/CrazyOptimist).
6
+ * [#10](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/10): Fix actions endpoint for block dropdowns - [@maths22](https://github.com/maths22).
7
+ * [#14](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/14): Added support for Ruby 3.1 - [@CrazyOptimist](https://github.com/CrazyOptimist).
8
+
9
+ #### 0.3.1 (2021/02/04)
10
+
11
+ * [#9](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/9): Provide default value when actions are missing in payload - [@nijave](https://github.com/nijave).
12
+
13
+ #### 0.3.0 (2020/12/30)
14
+
15
+ * [#6](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/6): Add support for block_actions interaction type - [@CrazyOptimist](https://github.com/CrazyOptimist).
16
+
17
+ #### 0.2.0 (2020/07/19)
4
18
 
5
19
  * Include action type in actions callbacks - [@dblock](https://github.com/dblock).
6
20
 
7
- #### 0.1.0 (07/19/2020)
21
+ #### 0.1.0 (2020/07/19)
8
22
 
9
23
  * Initial public release - [@dblock](https://github.com/dblock).
data/Gemfile CHANGED
@@ -8,10 +8,10 @@ when 'mongoid' then
8
8
  gem 'mongoid'
9
9
  gem 'mongoid-scroll'
10
10
  when 'activerecord' then
11
- gem 'activerecord', '~> 5.0.0'
12
- gem 'otr-activerecord', '~> 1.2.1'
11
+ gem 'activerecord'
12
+ gem 'otr-activerecord'
13
13
  gem 'virtus'
14
- gem 'cursor_pagination' # rubocop:disable Bundler/OrderedGems
14
+ gem 'cursor_pagination', github: 'dblock/cursor_pagination', branch: 'misc' # rubocop:disable Bundler/OrderedGems
15
15
  gem 'pg'
16
16
  when nil
17
17
  warn "Missing ENV['DATABASE_ADAPTER']."
@@ -34,7 +34,3 @@ group :development, :test do
34
34
  gem 'vcr'
35
35
  gem 'webmock'
36
36
  end
37
-
38
- group :test do
39
- gem 'slack-ruby-danger', '~> 0.1.0', require: false
40
- end
data/Gemfile.danger ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'danger-toc', '~> 0.2.0', require: false
5
+ gem 'slack-ruby-danger', '~> 0.2.0', require: false
6
+ end
data/README.md CHANGED
@@ -2,10 +2,26 @@ Slack Ruby Bot Server Events Extension
2
2
  ======================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/slack-ruby-bot-server-events.svg)](https://badge.fury.io/rb/slack-ruby-bot-server-events)
5
- [![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events.svg?branch=master)](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events)
5
+ [![lint](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/rubocop.yml/badge.svg)](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/rubocop.yml)
6
+ [![test with mongodb](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-mongodb.yml/badge.svg)](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-mongodb.yml)
7
+ [![test with postgresql](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-postgresql.yml/badge.svg)](https://github.com/slack-ruby/slack-ruby-bot-server-events/actions/workflows/test-postgresql.yml)
6
8
 
7
9
  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.
8
10
 
11
+ ### Table of Contents
12
+
13
+ - [Sample](#sample)
14
+ - [Usage](#usage)
15
+ - [Gemfile](#gemfile)
16
+ - [Configure](#configure)
17
+ - [OAuth](#oauth)
18
+ - [Events](#events)
19
+ - [Implement Callbacks](#implement-callbacks)
20
+ - [Events](#events-1)
21
+ - [Actions](#actions)
22
+ - [Commands](#commands)
23
+ - [Copyright & License](#copyright--license)
24
+
9
25
  ### Sample
10
26
 
11
27
  See [slack-ruby/slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample) for a working sample.
@@ -22,6 +38,21 @@ gem 'slack-ruby-bot-server-events'
22
38
 
23
39
  #### Configure
24
40
 
41
+ ##### OAuth
42
+
43
+ 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
+
45
+ ```ruby
46
+ SlackRubyBotServer.configure do |config|
47
+ config.oauth_version = :v2
48
+ config.oauth_scope = ['users:read', 'channels:read', 'groups:read', 'chat:write', 'commands', 'incoming-webhook']
49
+ end
50
+ ```
51
+
52
+ ##### Events
53
+
54
+ Configure events-specific settings.
55
+
25
56
  ```ruby
26
57
  SlackRubyBotServer::Events.configure do |config|
27
58
  config.signing_secret = 'secret'
@@ -78,7 +109,7 @@ end
78
109
 
79
110
  #### Actions
80
111
 
81
- Respond to [Shortcuts](https://api.slack.com/interactivity/shortcuts) and [Interactive Message Buttons](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
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`.
82
113
 
83
114
  The following example posts an ephemeral message that counts the letters in a message shortcut.
84
115
 
@@ -93,7 +124,7 @@ SlackRubyBotServer::Events.configure do |config|
93
124
  response_type: 'ephemeral'
94
125
  }.to_json, 'Content-Type' => 'application/json')
95
126
 
96
- true
127
+ { ok: true }
97
128
  end
98
129
 
99
130
  config.on :action do |action|
@@ -103,6 +134,24 @@ SlackRubyBotServer::Events.configure do |config|
103
134
  end
104
135
  ```
105
136
 
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).
139
+
140
+ ```ruby
141
+ SlackRubyBotServer::Events.configure do |config|
142
+ config.on :action, 'block_actions', 'your_action_id' do |action|
143
+ payload = action[:payload]
144
+
145
+ Faraday.post(payload[:response_url], {
146
+ text: "The action \"your_action_id\" has been invoked.",
147
+ response_type: 'ephemeral'
148
+ }.to_json, 'Content-Type' => 'application/json')
149
+
150
+ { ok: true }
151
+ end
152
+ end
153
+ ```
154
+
106
155
  #### Commands
107
156
 
108
157
  Respond to [Slash Commands](https://api.slack.com/interactivity/slash-commands) by implementing `SlackRubyBotServer::Events::Config#on :command`.
@@ -9,31 +9,63 @@ module SlackRubyBotServer
9
9
  desc 'Respond to interactive slack buttons and actions.'
10
10
  params do
11
11
  requires :payload, type: JSON do
12
- requires :token, type: String
13
- requires :callback_id, type: String
14
- optional :type, type: String
15
- optional :trigger_id, type: String
16
- optional :response_url, type: String
17
- optional :channel, type: Hash do
18
- requires :id, type: String
19
- optional :name, type: String
12
+ requires :type, type: String
13
+ given type: ->(val) { %w[message_action shortcut].include? val } do
14
+ requires :token, type: String
15
+ requires :callback_id, type: String
16
+ optional :trigger_id, type: String
17
+ optional :response_url, type: String
18
+ optional :channel, type: Hash do
19
+ requires :id, type: String
20
+ optional :name, type: String
21
+ end
22
+ requires :user, type: Hash do
23
+ requires :id, type: String
24
+ optional :name, type: String
25
+ end
26
+ requires :team, type: Hash do
27
+ requires :id, type: String
28
+ optional :domain, type: String
29
+ end
30
+ optional :actions, type: Array do
31
+ requires :value, type: String
32
+ end
33
+ optional :message, type: Hash do
34
+ requires :type, type: String
35
+ optional :user, type: String
36
+ requires :ts, type: String
37
+ requires :text, type: String
38
+ end
20
39
  end
21
- requires :user, type: Hash do
22
- requires :id, type: String
23
- optional :name, type: String
24
- end
25
- requires :team, type: Hash do
26
- requires :id, type: String
27
- optional :domain, type: String
28
- end
29
- optional :actions, type: Array do
30
- requires :value, type: String
31
- end
32
- optional :message, type: Hash do
33
- requires :type, type: String
34
- optional :user, type: String
35
- requires :ts, type: String
36
- requires :text, type: String
40
+
41
+ given type: ->(val) { val == 'block_actions' } do
42
+ optional :trigger_id, type: String
43
+ optional :response_url, type: String
44
+ requires :token, type: String
45
+ requires :user, type: Hash do
46
+ requires :id, type: String
47
+ optional :name, type: String
48
+ end
49
+ requires :team, type: Hash do
50
+ requires :id, type: String
51
+ optional :domain, type: String
52
+ end
53
+ requires :actions, type: Array do
54
+ requires :action_id, type: String
55
+ optional :block_id, type: String
56
+ optional :type, type: String
57
+ optional :action_ts, type: String
58
+ end
59
+ optional :message, type: Hash do
60
+ requires :type, type: String
61
+ optional :user, type: String
62
+ requires :ts, type: String
63
+ requires :text, type: String
64
+ optional :blocks, type: Array do
65
+ requires :type, type: String
66
+ requires :block_id, type: String
67
+ end
68
+ end
37
69
  end
38
70
  end
39
71
  end
@@ -41,7 +73,12 @@ module SlackRubyBotServer
41
73
  action = SlackRubyBotServer::Events::Requests::Action.new(params, request)
42
74
  payload_type = params[:payload][:type]
43
75
  callback_id = params[:payload][:callback_id]
44
- SlackRubyBotServer::Events.config.run_callbacks(:action, [payload_type, callback_id].compact, action) || body(false)
76
+ action_ids = params[:payload].fetch(:actions, []).map { |entity| entity[:action_id] }
77
+ SlackRubyBotServer::Events.config.run_callbacks(
78
+ :action,
79
+ ([payload_type, callback_id] + action_ids).compact,
80
+ action
81
+ ) || body(false)
45
82
  end
46
83
  end
47
84
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SlackRubyBotServer
4
4
  module Events
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +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.2.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-bot-server
@@ -31,15 +31,19 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/danger.yml"
35
+ - ".github/workflows/rubocop.yml"
36
+ - ".github/workflows/test-mongodb.yml"
37
+ - ".github/workflows/test-postgresql.yml"
34
38
  - ".gitignore"
35
39
  - ".rspec"
36
40
  - ".rubocop.yml"
37
41
  - ".rubocop_todo.yml"
38
- - ".travis.yml"
39
42
  - CHANGELOG.md
40
43
  - CONTRIBUTING.md
41
44
  - Dangerfile
42
45
  - Gemfile
46
+ - Gemfile.danger
43
47
  - LICENSE
44
48
  - README.md
45
49
  - RELEASING.md
@@ -79,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  - !ruby/object:Gem::Version
80
84
  version: '0'
81
85
  requirements: []
82
- rubygems_version: 3.1.3
86
+ rubygems_version: 3.0.6
83
87
  signing_key:
84
88
  specification_version: 4
85
89
  summary: Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
-
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.6.6
8
- script:
9
- - bundle exec danger
10
- - rvm: 2.6.6
11
- env: DATABASE_ADAPTER=activerecord
12
- services:
13
- - postgresql
14
- - rvm: 2.6.6
15
- env: DATABASE_ADAPTER=mongoid
16
- services:
17
- - mongodb