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

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: 43c5fbc5296102a8b2118e79f806b9ba7d655c3af099efd82e5b76f7e8e6c68a
4
+ data.tar.gz: 93362081e74a6a60f356feb93ae4fae9768832b530f231c16f5a3f2d987886d6
5
5
  SHA512:
6
- metadata.gz: fef7839cbbdd0892aebc3177a5996603a2cbf89d54b06ed71fb06d85163f27039f7ece113c2ade62b8d12b49cab24d7dfd31d7c67d39b96dde1bfbb7fab1ac73
7
- data.tar.gz: a08625699825f3bbfee9c1ec6929bec5a1f7ecdf3a6a16d111a7d543f151000c4498949da68fec417b05d56d1aad23dcd065bffb2b97a752ca3ea22a3108ef9f
6
+ metadata.gz: 1248508f228df67ecc1fff934a812fc9514129dcdbb5fe3d38529c43c6fa4e337ac5884d3a1f4c94d5d775f48fb8fa94ee9f37104ac0f69e4cba434dc744b9cd
7
+ data.tar.gz: 349b80b69c44546ce9355af267e63edd1a2e06c4c6a1babd5a6a1811dd05e430ec4bcace07a58b990f5b1805f3e655af33a23a12a81569037d573aa8abb0a30c
@@ -1,5 +1,9 @@
1
1
  ### Changelog
2
2
 
3
+ #### 0.3.0 (12/30/2020)
4
+
5
+ * [#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).
6
+
3
7
  #### 0.2.0 (07/19/2020)
4
8
 
5
9
  * Include action type in actions callbacks - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -22,6 +22,21 @@ gem 'slack-ruby-bot-server-events'
22
22
 
23
23
  #### Configure
24
24
 
25
+ ##### OAuth
26
+
27
+ 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.
28
+
29
+ ```ruby
30
+ SlackRubyBotServer.configure do |config|
31
+ config.oauth_version = :v2
32
+ config.oauth_scope = ['users:read', 'channels:read', 'groups:read', 'chat:write', 'commands', 'incoming-webhook']
33
+ end
34
+ ```
35
+
36
+ ##### Events
37
+
38
+ Configure events-specific settings.
39
+
25
40
  ```ruby
26
41
  SlackRubyBotServer::Events.configure do |config|
27
42
  config.signing_secret = 'secret'
@@ -78,7 +93,7 @@ end
78
93
 
79
94
  #### Actions
80
95
 
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`.
96
+ 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
97
 
83
98
  The following example posts an ephemeral message that counts the letters in a message shortcut.
84
99
 
@@ -93,7 +108,7 @@ SlackRubyBotServer::Events.configure do |config|
93
108
  response_type: 'ephemeral'
94
109
  }.to_json, 'Content-Type' => 'application/json')
95
110
 
96
- true
111
+ { ok: true }
97
112
  end
98
113
 
99
114
  config.on :action do |action|
@@ -103,6 +118,24 @@ SlackRubyBotServer::Events.configure do |config|
103
118
  end
104
119
  ```
105
120
 
121
+ The following example responds to an interactive message.
122
+ You can compose rich message layouts using [Block Kit Builder](https://app.slack.com/block-kit-builder).
123
+
124
+ ```ruby
125
+ SlackRubyBotServer::Events.configure do |config|
126
+ config.on :action, 'block_actions', 'your_action_id' do |action|
127
+ payload = action[:payload]
128
+
129
+ Faraday.post(payload[:response_url], {
130
+ text: "The action \"your_action_id\" has been invoked.",
131
+ response_type: 'ephemeral'
132
+ }.to_json, 'Content-Type' => 'application/json')
133
+
134
+ { ok: true }
135
+ end
136
+ end
137
+ ```
138
+
106
139
  #### Commands
107
140
 
108
141
  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
+ requires :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][: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.0'
6
6
  end
7
7
  end
@@ -16,5 +16,5 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
17
17
  spec.require_paths = ['lib']
18
18
 
19
- spec.add_dependency 'slack-ruby-bot-server', '>= 0.12.0'
19
+ spec.add_dependency 'slack-ruby-bot-server', '>= 1.2.0'
20
20
  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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-bot-server
@@ -16,15 +16,15 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.12.0
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.12.0
27
- description:
26
+ version: 1.2.0
27
+ description:
28
28
  email:
29
29
  - dblock@dblock.org
30
30
  executables: []
@@ -64,7 +64,7 @@ files:
64
64
  homepage: https://github.com/slack-ruby/slack-ruby-bot-server-events
65
65
  licenses: []
66
66
  metadata: {}
67
- post_install_message:
67
+ post_install_message:
68
68
  rdoc_options: []
69
69
  require_paths:
70
70
  - lib
@@ -79,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.1.3
83
- signing_key:
82
+ rubygems_version: 3.1.4
83
+ signing_key:
84
84
  specification_version: 4
85
85
  summary: Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
86
86
  test_files: []