grape-slack-bot 2.1.0 → 2.1.3
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/CHANGELOG.md +20 -0
- data/README.md +12 -0
- data/grape-slack-bot.gemspec +4 -3
- data/lib/slack_bot/api_client.rb +71 -32
- data/lib/slack_bot/grape_extension.rb +24 -13
- data/lib/slack_bot/grape_helpers/dispatch.rb +4 -4
- data/lib/slack_bot/grape_helpers/interactions.rb +4 -4
- data/lib/slack_bot.rb +1 -1
- data/sig/slack_bot.rbs +1 -0
- metadata +24 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3e52396043a337cfa348d788ca11ea7d6b76c8486d080a2a0d43c69cf73ad4e
|
|
4
|
+
data.tar.gz: a20fd5e43a9695978b06250cd66a9c13bc2732b9246c9a1a8685e1986b9302f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a25326a96fafe69c94ff3a2490bc9b674e5f8ee40e3c7dc481a5fef4f7ccb3a19cbc1fe471f6fb155b605e4c544c68785bf817a1a4f1a8686351e672201cd59
|
|
7
|
+
data.tar.gz: bb3fd2179189e08f5795a4a6cccbbb82f96d4157e455fbd0f28b955a7ca5ae7112b9da548326d1523aacfd2fb5640972aecaa05677ce9ff2b7bad760106f3822
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 2.1.3 (2026-11-07)
|
|
4
|
+
|
|
5
|
+
- Memoize parsed JSON in `SlackBot::ApiResponse#data` so repeated reads do not re-parse the response body
|
|
6
|
+
- Encode Slack API request bodies with `JSON.generate` instead of ActiveSupport `Hash#to_json`
|
|
7
|
+
- Verify Slack signatures with `HMAC.digest` and binary `secure_compare`; cache the request body for the verify pass
|
|
8
|
+
- Keep `ApiResponse` hot-path shortcuts always on; drop `SlackBot::PressureOpts` / `SLACK_PRESSURE_*` feature flags
|
|
9
|
+
- Return HTTP 401 when Slack request signature verification fails
|
|
10
|
+
- Clamp a negative `Retry-After` value to zero before the bounded retry
|
|
11
|
+
- Fail closed when release confirmation input reaches EOF
|
|
12
|
+
- Require a matching `CHANGELOG.md` version heading before publish
|
|
13
|
+
- Give the test workflow read-only `contents` permission
|
|
14
|
+
|
|
15
|
+
## 2.1.2 (2026-09-15)
|
|
16
|
+
|
|
17
|
+
- Allow grape 4.x by expanding the runtime dependency to `< 5.0`
|
|
18
|
+
|
|
19
|
+
## 2.1.1 (2026-09-07)
|
|
20
|
+
|
|
21
|
+
- Store SlackBot config in `@slack_bot_config` so Grape 3.3+ can keep `Endpoint::Options` in `@config`
|
|
22
|
+
|
|
3
23
|
## 2.1.0 (2026-07-10)
|
|
4
24
|
|
|
5
25
|
- Add `block_action` registration for message-level block action buttons outside modal callbacks
|
data/README.md
CHANGED
|
@@ -568,6 +568,18 @@ Or use the release script:
|
|
|
568
568
|
usr/bin/release.rb
|
|
569
569
|
```
|
|
570
570
|
|
|
571
|
+
## Links
|
|
572
|
+
|
|
573
|
+
- [GitHub](https://github.com/amkisko/grape-slack-bot.rb)
|
|
574
|
+
- [GitLab](https://gitlab.com/amkisko/grape-slack-bot.rb)
|
|
575
|
+
- [RubyGems](https://rubygems.org/gems/grape-slack-bot)
|
|
576
|
+
- [libraries.io](https://libraries.io/rubygems/grape-slack-bot)
|
|
577
|
+
- [Deps.dev](https://deps.dev/rubygems/grape-slack-bot)
|
|
578
|
+
- [SonarCloud](https://sonarcloud.io/project/overview?id=amkisko_grape-slack-bot.rb)
|
|
579
|
+
- [Snyk](https://snyk.io/test/github/amkisko/grape-slack-bot.rb)
|
|
580
|
+
- [Codecov](https://app.codecov.io/github/amkisko/grape-slack-bot.rb)
|
|
581
|
+
- [OpenSSF Scorecard](https://scorecard.dev/viewer/?uri=github.com/amkisko/grape-slack-bot.rb)
|
|
582
|
+
|
|
571
583
|
## License
|
|
572
584
|
|
|
573
585
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/grape-slack-bot.gemspec
CHANGED
|
@@ -29,12 +29,13 @@ Gem::Specification.new do |gem|
|
|
|
29
29
|
gem.require_paths = ["lib"]
|
|
30
30
|
|
|
31
31
|
gem.add_runtime_dependency "rack", "~> 3.0"
|
|
32
|
-
gem.add_runtime_dependency "grape", ">= 1.6", "<
|
|
32
|
+
gem.add_runtime_dependency "grape", ">= 1.6", "< 5.0"
|
|
33
33
|
gem.add_runtime_dependency "faraday", ">= 2.14.3", "< 3.0"
|
|
34
|
-
gem.add_runtime_dependency "activesupport", ">=
|
|
34
|
+
gem.add_runtime_dependency "activesupport", ">= 7.2.3.2", "< 9.0"
|
|
35
|
+
gem.add_runtime_dependency "ostruct", ">= 0.6"
|
|
35
36
|
|
|
36
37
|
gem.add_development_dependency "rspec", "~> 3"
|
|
37
|
-
gem.add_development_dependency "polyrun", "
|
|
38
|
+
gem.add_development_dependency "polyrun", ">= 2.2.9"
|
|
38
39
|
gem.add_development_dependency "webmock", "~> 3"
|
|
39
40
|
gem.add_development_dependency "rake", "~> 13"
|
|
40
41
|
gem.add_development_dependency "standard", "~> 1.52"
|
data/lib/slack_bot/api_client.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "faraday"
|
|
2
|
+
require "json"
|
|
2
3
|
|
|
3
4
|
module SlackBot
|
|
4
5
|
class ApiResponse
|
|
@@ -16,43 +17,78 @@ module SlackBot
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def self.rate_limit_retry_sleep_seconds(retry_after)
|
|
19
|
-
|
|
20
|
+
retry_after.to_i.clamp(0, RATE_LIMIT_RETRY_SLEEP_SECONDS)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def initialize(&block)
|
|
23
24
|
@response = block.call
|
|
24
|
-
|
|
25
|
+
if response.respond_to?(:headers)
|
|
26
|
+
@retry_after_header = response.headers["Retry-After"]&.to_i
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
def ok?
|
|
28
|
-
response.status == 200
|
|
31
|
+
return false unless response.status == 200
|
|
32
|
+
|
|
33
|
+
b = response.body
|
|
34
|
+
return true if b.is_a?(String) && b.start_with?('{"ok":true')
|
|
35
|
+
|
|
36
|
+
data["ok"]
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def error
|
|
40
|
+
b = response.body
|
|
41
|
+
return nil if b.is_a?(String) && !b.include?('"error"')
|
|
42
|
+
|
|
32
43
|
data["error"]
|
|
33
44
|
end
|
|
34
45
|
|
|
35
46
|
def rate_limited?
|
|
36
|
-
response.status == 429
|
|
47
|
+
return true if response.status == 429
|
|
48
|
+
|
|
49
|
+
b = response.body
|
|
50
|
+
return false if b.is_a?(String) && b.start_with?('{"ok":true')
|
|
51
|
+
|
|
52
|
+
data_rate_limited_payload
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def data_rate_limited_payload
|
|
56
|
+
data["ok"] == false && data["error"] == "rate_limited"
|
|
37
57
|
end
|
|
38
58
|
|
|
39
59
|
def retry_after
|
|
60
|
+
if @retry_after_header.is_a?(Integer) && !@retry_after_header.zero?
|
|
61
|
+
return @retry_after_header
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
return 60 unless response.respond_to?(:headers)
|
|
65
|
+
|
|
40
66
|
response.headers["Retry-After"]&.to_i || 60
|
|
41
67
|
end
|
|
42
68
|
|
|
43
69
|
def slack_error?
|
|
44
|
-
|
|
70
|
+
return false if ok?
|
|
71
|
+
|
|
72
|
+
e = error
|
|
73
|
+
e.present? || response.status != 200
|
|
45
74
|
end
|
|
46
75
|
|
|
47
76
|
def authentication_error?
|
|
48
|
-
|
|
77
|
+
return false unless slack_error?
|
|
78
|
+
|
|
79
|
+
e = error
|
|
80
|
+
return false if e.blank?
|
|
81
|
+
|
|
82
|
+
%w[invalid_auth account_inactive].include?(e)
|
|
49
83
|
end
|
|
50
84
|
|
|
51
85
|
def data
|
|
52
|
-
|
|
86
|
+
return @data if instance_variable_defined?(:@data)
|
|
87
|
+
|
|
88
|
+
@data = JSON.parse(response.body)
|
|
53
89
|
rescue JSON::ParserError => e
|
|
54
90
|
SlackBot::Logger.error("Failed to parse Slack API response: #{e.message}")
|
|
55
|
-
{"ok" => false, "error" => "invalid_json_response"}
|
|
91
|
+
@data = {"ok" => false, "error" => "invalid_json_response"}
|
|
56
92
|
end
|
|
57
93
|
end
|
|
58
94
|
|
|
@@ -73,69 +109,72 @@ module SlackBot
|
|
|
73
109
|
end
|
|
74
110
|
|
|
75
111
|
def views_open(trigger_id:, view:)
|
|
76
|
-
perform_request { client.post("views.open",
|
|
112
|
+
perform_request { client.post("views.open", JSON.generate(trigger_id: trigger_id, view: view)) }
|
|
77
113
|
end
|
|
78
114
|
|
|
79
115
|
def views_update(view_id:, view:)
|
|
80
|
-
perform_request { client.post("views.update",
|
|
116
|
+
perform_request { client.post("views.update", JSON.generate(view_id: view_id, view: view)) }
|
|
81
117
|
end
|
|
82
118
|
|
|
83
119
|
def chat_post_message(channel:, text:, blocks:)
|
|
84
|
-
perform_request { client.post("chat.postMessage",
|
|
120
|
+
perform_request { client.post("chat.postMessage", JSON.generate(channel: channel, text: text, blocks: blocks)) }
|
|
85
121
|
end
|
|
86
122
|
|
|
87
123
|
def chat_update(channel:, ts:, text:, blocks:)
|
|
88
|
-
perform_request { client.post("chat.update",
|
|
124
|
+
perform_request { client.post("chat.update", JSON.generate(channel: channel, ts: ts, text: text, blocks: blocks)) }
|
|
89
125
|
end
|
|
90
126
|
|
|
91
127
|
def chat_delete(channel:, ts:)
|
|
92
|
-
perform_request { client.post("chat.delete",
|
|
128
|
+
perform_request { client.post("chat.delete", JSON.generate(channel: channel, ts: ts)) }
|
|
93
129
|
end
|
|
94
130
|
|
|
95
131
|
def chat_unfurl(channel:, ts:, unfurls:, source: nil, unfurl_id: nil, user_auth_blocks: nil, user_auth_message: nil, user_auth_required: nil, user_auth_url: nil)
|
|
96
132
|
perform_request do
|
|
97
|
-
client.post(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
133
|
+
client.post(
|
|
134
|
+
"chat.unfurl",
|
|
135
|
+
JSON.generate(
|
|
136
|
+
channel: channel,
|
|
137
|
+
ts: ts,
|
|
138
|
+
unfurls: unfurls,
|
|
139
|
+
source: source,
|
|
140
|
+
unfurl_id: unfurl_id,
|
|
141
|
+
user_auth_blocks: user_auth_blocks,
|
|
142
|
+
user_auth_message: user_auth_message,
|
|
143
|
+
user_auth_required: user_auth_required,
|
|
144
|
+
user_auth_url: user_auth_url
|
|
145
|
+
)
|
|
146
|
+
)
|
|
108
147
|
end
|
|
109
148
|
end
|
|
110
149
|
|
|
111
150
|
def chat_schedule_message(channel:, text:, post_at:, blocks: nil)
|
|
112
|
-
perform_request { client.post("chat.scheduleMessage",
|
|
151
|
+
perform_request { client.post("chat.scheduleMessage", JSON.generate(channel: channel, text: text, post_at: post_at, blocks: blocks)) }
|
|
113
152
|
end
|
|
114
153
|
|
|
115
154
|
def scheduled_messages_list(channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil)
|
|
116
155
|
args = compact_payload(channel: channel, cursor: cursor, limit: limit, latest: latest, oldest: oldest, team_id: team_id)
|
|
117
|
-
perform_request { client.post("scheduled_messages.list", args
|
|
156
|
+
perform_request { client.post("scheduled_messages.list", JSON.generate(args)) }
|
|
118
157
|
end
|
|
119
158
|
|
|
120
159
|
def chat_delete_scheduled_message(channel:, scheduled_message_id:)
|
|
121
|
-
perform_request { client.post("chat.deleteScheduledMessage",
|
|
160
|
+
perform_request { client.post("chat.deleteScheduledMessage", JSON.generate(channel: channel, scheduled_message_id: scheduled_message_id)) }
|
|
122
161
|
end
|
|
123
162
|
|
|
124
163
|
def chat_get_permalink(channel:, message_ts:)
|
|
125
|
-
perform_request { client.post("chat.getPermalink",
|
|
164
|
+
perform_request { client.post("chat.getPermalink", JSON.generate(channel: channel, message_ts: message_ts)) }
|
|
126
165
|
end
|
|
127
166
|
|
|
128
167
|
def users_info(user_id:)
|
|
129
|
-
perform_request { client.post("users.info",
|
|
168
|
+
perform_request { client.post("users.info", JSON.generate(user: user_id)) }
|
|
130
169
|
end
|
|
131
170
|
|
|
132
171
|
def views_publish(user_id:, view:)
|
|
133
|
-
perform_request { client.post("views.publish",
|
|
172
|
+
perform_request { client.post("views.publish", JSON.generate(user_id: user_id, view: view)) }
|
|
134
173
|
end
|
|
135
174
|
|
|
136
175
|
def users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil)
|
|
137
176
|
args = compact_payload(cursor: cursor, limit: limit, include_locale: include_locale, team_id: team_id)
|
|
138
|
-
perform_request { client.post("users.list", args
|
|
177
|
+
perform_request { client.post("users.list", JSON.generate(args)) }
|
|
139
178
|
end
|
|
140
179
|
|
|
141
180
|
def chat_post_ephemeral(channel:, user:, text:, as_user: nil, attachments: nil, blocks: nil, icon_emoji: nil, icon_url: nil, link_names: nil, parse: nil, thread_ts: nil, username: nil)
|
|
@@ -153,7 +192,7 @@ module SlackBot
|
|
|
153
192
|
thread_ts: thread_ts,
|
|
154
193
|
username: username
|
|
155
194
|
)
|
|
156
|
-
perform_request { client.post("chat.postEphemeral", args
|
|
195
|
+
perform_request { client.post("chat.postEphemeral", JSON.generate(args)) }
|
|
157
196
|
end
|
|
158
197
|
|
|
159
198
|
private
|
|
@@ -24,6 +24,8 @@ module SlackBot
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def verify_slack_signature!
|
|
27
|
+
remove_instance_variable(:@request_body_content) if instance_variable_defined?(:@request_body_content)
|
|
28
|
+
|
|
27
29
|
slack_signing_secret = ENV["SLACK_SIGNING_SECRET"]
|
|
28
30
|
timestamp = slack_request_header("x-slack-request-timestamp", "X-Slack-Request-Timestamp")
|
|
29
31
|
slack_signature = slack_request_header("x-slack-signature", "X-Slack-Signature")
|
|
@@ -63,6 +65,10 @@ module SlackBot
|
|
|
63
65
|
raise SlackBot::Errors::UserAuthenticationError.new("User is not authorized")
|
|
64
66
|
end
|
|
65
67
|
|
|
68
|
+
def slack_bot_config
|
|
69
|
+
@slack_bot_config ||= SlackBot::Config.current_instance
|
|
70
|
+
end
|
|
71
|
+
|
|
66
72
|
def slack_request_retry?
|
|
67
73
|
slack_request_header("x-slack-retry-num", "X-Slack-Retry-Num").present?
|
|
68
74
|
end
|
|
@@ -91,7 +97,7 @@ module SlackBot
|
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
def validate_request_timestamp!(timestamp)
|
|
94
|
-
request_timestamp = timestamp
|
|
100
|
+
request_timestamp = Integer(timestamp, 10)
|
|
95
101
|
current_timestamp = Time.now.to_i
|
|
96
102
|
return if (current_timestamp - request_timestamp).abs <= TIMESTAMP_TOLERANCE_SECONDS
|
|
97
103
|
|
|
@@ -99,23 +105,25 @@ module SlackBot
|
|
|
99
105
|
end
|
|
100
106
|
|
|
101
107
|
def verify_signature_match!(slack_signing_secret, timestamp, slack_signature)
|
|
102
|
-
|
|
108
|
+
body = request_body_content
|
|
109
|
+
sig_basestring = "v0:#{timestamp}:#{body}"
|
|
110
|
+
expected_digest_bin = OpenSSL::HMAC.digest("SHA256", slack_signing_secret, sig_basestring)
|
|
111
|
+
actual_hex = slack_signature.delete_prefix("v0=")
|
|
112
|
+
return true if ActiveSupport::SecurityUtils.secure_compare(expected_digest_bin, [actual_hex].pack("H*"))
|
|
103
113
|
|
|
104
114
|
raise SlackBot::Errors::SignatureAuthenticationError.new("Signature mismatch")
|
|
105
115
|
end
|
|
106
116
|
|
|
107
|
-
def computed_signature(slack_signing_secret, timestamp)
|
|
108
|
-
sig_basestring = "v0:#{timestamp}:#{request_body_content}"
|
|
109
|
-
"v0=" + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), slack_signing_secret, sig_basestring)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
117
|
def request_body_content
|
|
113
|
-
return
|
|
118
|
+
return @request_body_content if instance_variable_defined?(:@request_body_content)
|
|
119
|
+
|
|
120
|
+
return @request_body_content = "" unless request.body
|
|
114
121
|
|
|
115
122
|
request.body.rewind if request.body.respond_to?(:rewind)
|
|
116
123
|
body_content = request.body.read
|
|
117
124
|
request.body.rewind if request.body.respond_to?(:rewind)
|
|
118
|
-
|
|
125
|
+
|
|
126
|
+
@request_body_content = body_content
|
|
119
127
|
end
|
|
120
128
|
|
|
121
129
|
def parse_interaction_payload!(raw_payload)
|
|
@@ -148,6 +156,9 @@ module SlackBot
|
|
|
148
156
|
base.content_type :json, "application/json"
|
|
149
157
|
base.use ActionDispatch::RemoteIp if defined?(ActionDispatch::RemoteIp)
|
|
150
158
|
base.helpers SlackBot::GrapeHelpers
|
|
159
|
+
base.rescue_from SlackBot::Errors::SignatureAuthenticationError do |e|
|
|
160
|
+
error!({error: e.message}, 401)
|
|
161
|
+
end
|
|
151
162
|
base.rescue_from SlackBot::Error do |e|
|
|
152
163
|
error!({error: e.message}, 200)
|
|
153
164
|
end
|
|
@@ -159,14 +170,14 @@ module SlackBot
|
|
|
159
170
|
def self.add_commands_resource!(base)
|
|
160
171
|
base.resource :commands do
|
|
161
172
|
post ":url_token" do
|
|
162
|
-
command_config =
|
|
173
|
+
command_config = slack_bot_config.find_slash_command_config(params[:url_token], params[:command], params[:text])
|
|
163
174
|
command_klass = command_config&.command_klass
|
|
164
175
|
raise SlackBot::Errors::SlashCommandNotImplemented.new if command_klass.blank?
|
|
165
176
|
|
|
166
177
|
args = params[:text].gsub(/^#{command_config.full_token}\s?/, "")
|
|
167
178
|
SlackBot::DevConsole.log_input "SlackApi::SlashCommands#post: #{command_config.url_token} | #{command_config.full_token} | #{args}"
|
|
168
179
|
|
|
169
|
-
action = command_klass.new(current_user: current_user, params: params, args: args, config:
|
|
180
|
+
action = command_klass.new(current_user: current_user, params: params, args: args, config: slack_bot_config)
|
|
170
181
|
verify_slack_team! if action.only_slack_team?
|
|
171
182
|
verify_direct_message_channel! if action.only_direct_message?
|
|
172
183
|
verify_current_user! if action.only_user?
|
|
@@ -222,10 +233,10 @@ module SlackBot
|
|
|
222
233
|
SlackBot::DevConsole.log_input "SlackApi::MenuOptions#get: #{params.inspect}"
|
|
223
234
|
|
|
224
235
|
verify_slack_team!
|
|
225
|
-
menu_options_klass =
|
|
236
|
+
menu_options_klass = slack_bot_config.find_menu_options(params[:action_id])
|
|
226
237
|
raise SlackBot::Errors::MenuOptionsNotImplemented.new if menu_options_klass.blank?
|
|
227
238
|
|
|
228
|
-
menu_options = menu_options_klass.new(current_user: current_user, params: params, config:
|
|
239
|
+
menu_options = menu_options_klass.new(current_user: current_user, params: params, config: slack_bot_config).call
|
|
229
240
|
return blank_slack_response! if menu_options.blank?
|
|
230
241
|
|
|
231
242
|
menu_options
|
|
@@ -18,7 +18,7 @@ module SlackBot
|
|
|
18
18
|
def resolve_user_session(team_id, user_id)
|
|
19
19
|
return if team_id.blank? || user_id.blank?
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
slack_bot_config.user_session_resolver!.call(team_id, user_id)
|
|
22
22
|
rescue SlackBot::Errors::ConfigurationError
|
|
23
23
|
nil
|
|
24
24
|
end
|
|
@@ -28,7 +28,7 @@ module SlackBot
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def dispatch_event(handler:, params:, current_user:)
|
|
31
|
-
|
|
31
|
+
slack_bot_config.event_dispatcher_method.call(handler: handler, params: params, current_user: current_user)
|
|
32
32
|
false
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -40,12 +40,12 @@ module SlackBot
|
|
|
40
40
|
|
|
41
41
|
def event_handler_for(params)
|
|
42
42
|
event_type = params[:event][:type] || params[:event]["type"]
|
|
43
|
-
|
|
43
|
+
slack_bot_config.find_event_handler(event_type.to_sym)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def run_event_handler(handler, params)
|
|
47
47
|
current_user = resolve_event_user(params)
|
|
48
|
-
return dispatch_event(handler: handler, params: params, current_user: current_user) if
|
|
48
|
+
return dispatch_event(handler: handler, params: params, current_user: current_user) if slack_bot_config.event_dispatcher_method
|
|
49
49
|
|
|
50
50
|
handler.new(params: params, current_user: current_user).call
|
|
51
51
|
end
|
|
@@ -20,10 +20,10 @@ module SlackBot
|
|
|
20
20
|
action_id = payload.dig("actions", 0, "action_id")
|
|
21
21
|
return false if action_id.blank?
|
|
22
22
|
|
|
23
|
-
interaction_klass =
|
|
23
|
+
interaction_klass = slack_bot_config.find_block_action(action_id)
|
|
24
24
|
raise SlackBot::Errors::BlockActionNotImplemented.new if interaction_klass.blank?
|
|
25
25
|
|
|
26
|
-
interaction_klass.new(current_user: user, params: params, config:
|
|
26
|
+
interaction_klass.new(current_user: user, params: params, config: slack_bot_config).call
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def validate_callback_user!(callback, user)
|
|
@@ -40,13 +40,13 @@ module SlackBot
|
|
|
40
40
|
interaction_klass = callback_interaction_klass(callback)
|
|
41
41
|
return false if interaction_klass.blank?
|
|
42
42
|
|
|
43
|
-
interaction_klass.new(current_user: user, params: params, callback: callback, config:
|
|
43
|
+
interaction_klass.new(current_user: user, params: params, callback: callback, config: slack_bot_config).call
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
private
|
|
47
47
|
|
|
48
48
|
def find_callback!(view:, user:)
|
|
49
|
-
callback = SlackBot::Callback.find(view&.dig("callback_id"), user: user, config:
|
|
49
|
+
callback = SlackBot::Callback.find(view&.dig("callback_id"), user: user, config: slack_bot_config)
|
|
50
50
|
raise SlackBot::Errors::CallbackNotFound.new if callback.blank?
|
|
51
51
|
|
|
52
52
|
callback
|
data/lib/slack_bot.rb
CHANGED
data/sig/slack_bot.rbs
CHANGED
|
@@ -327,6 +327,7 @@ module SlackBot
|
|
|
327
327
|
def verify_direct_message_channel!: () -> bool
|
|
328
328
|
def verify_current_user!: () -> bool
|
|
329
329
|
def slack_request_retry?: () -> bool
|
|
330
|
+
def slack_bot_config: () -> SlackBot::Config
|
|
330
331
|
def resolve_user_session: (String? team_id, String? user_id) -> untyped?
|
|
331
332
|
def resolve_event_user: (Hash[String, untyped] params) -> untyped?
|
|
332
333
|
def events_callback: (Hash[String, untyped] params) -> untyped
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape-slack-bot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -32,7 +32,7 @@ dependencies:
|
|
|
32
32
|
version: '1.6'
|
|
33
33
|
- - "<"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: '
|
|
35
|
+
version: '5.0'
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -42,7 +42,7 @@ dependencies:
|
|
|
42
42
|
version: '1.6'
|
|
43
43
|
- - "<"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: '
|
|
45
|
+
version: '5.0'
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: faraday
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -69,7 +69,7 @@ dependencies:
|
|
|
69
69
|
requirements:
|
|
70
70
|
- - ">="
|
|
71
71
|
- !ruby/object:Gem::Version
|
|
72
|
-
version:
|
|
72
|
+
version: 7.2.3.2
|
|
73
73
|
- - "<"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: '9.0'
|
|
@@ -79,10 +79,24 @@ dependencies:
|
|
|
79
79
|
requirements:
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
82
|
+
version: 7.2.3.2
|
|
83
83
|
- - "<"
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
85
|
version: '9.0'
|
|
86
|
+
- !ruby/object:Gem::Dependency
|
|
87
|
+
name: ostruct
|
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0.6'
|
|
93
|
+
type: :runtime
|
|
94
|
+
prerelease: false
|
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0.6'
|
|
86
100
|
- !ruby/object:Gem::Dependency
|
|
87
101
|
name: rspec
|
|
88
102
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -101,16 +115,16 @@ dependencies:
|
|
|
101
115
|
name: polyrun
|
|
102
116
|
requirement: !ruby/object:Gem::Requirement
|
|
103
117
|
requirements:
|
|
104
|
-
- - "
|
|
118
|
+
- - ">="
|
|
105
119
|
- !ruby/object:Gem::Version
|
|
106
|
-
version:
|
|
120
|
+
version: 2.2.9
|
|
107
121
|
type: :development
|
|
108
122
|
prerelease: false
|
|
109
123
|
version_requirements: !ruby/object:Gem::Requirement
|
|
110
124
|
requirements:
|
|
111
|
-
- - "
|
|
125
|
+
- - ">="
|
|
112
126
|
- !ruby/object:Gem::Version
|
|
113
|
-
version:
|
|
127
|
+
version: 2.2.9
|
|
114
128
|
- !ruby/object:Gem::Dependency
|
|
115
129
|
name: webmock
|
|
116
130
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -350,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
350
364
|
- !ruby/object:Gem::Version
|
|
351
365
|
version: '0'
|
|
352
366
|
requirements: []
|
|
353
|
-
rubygems_version:
|
|
367
|
+
rubygems_version: 4.0.6
|
|
354
368
|
specification_version: 4
|
|
355
369
|
summary: Slack bot implementation for ruby-grape
|
|
356
370
|
test_files: []
|