grape-slack-bot 1.6.4 → 1.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slack_bot/callback.rb +30 -7
- data/lib/slack_bot/interaction.rb +2 -2
- data/lib/slack_bot.rb +1 -1
- data/spec/slack_bot/callback_spec.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae374ea5f4698b8505bde66baa7a67eaf75764e130d2f40e9de6fd29848966a8
|
4
|
+
data.tar.gz: 01ec55f539994166f4d3b90cf70953c5b4e2f421a9622affa5a44d7d0adcf888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a0223855ad9173023eb667115a6e2137212164c06069ca78db6289a813b9ea92da38c062577b6ab18642a4e3f1689326f353b159e21c05672e2447573e248e7
|
7
|
+
data.tar.gz: b44baf6641e68b2815afaf915485e9052d2594a1d43e92ae56d7e9a25463de0395253819627349ec8257814c0372bef1fb1fd72bb7b3ed91b436e7c2e84a5aba
|
data/lib/slack_bot/callback.rb
CHANGED
@@ -15,6 +15,14 @@ module SlackBot
|
|
15
15
|
nil
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.find_by_view_id(view_id, user: nil, config: nil)
|
19
|
+
callback = new(view_id: view_id, user: user, config: config)
|
20
|
+
callback_id = callback.read_view_callback_id
|
21
|
+
return if callback_id.blank?
|
22
|
+
|
23
|
+
find(callback_id, user: user, config: config)
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.create(id: nil, class_name:, user:, channel_id: nil, config: nil, payload: nil, expires_in: nil, user_scope: nil)
|
19
27
|
callback =
|
20
28
|
new(id: id, class_name: class_name, user: user, channel_id: channel_id, payload: payload, config: config, expires_in: expires_in, user_scope: user_scope)
|
@@ -30,12 +38,13 @@ module SlackBot
|
|
30
38
|
end
|
31
39
|
|
32
40
|
attr_reader :id, :data, :args, :config, :expires_in, :user_scope
|
33
|
-
def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, payload: nil, config: nil, expires_in: nil, user_scope: nil)
|
41
|
+
def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, payload: nil, config: nil, expires_in: nil, user_scope: nil, view_id: nil)
|
34
42
|
@id = id
|
35
43
|
@data = {
|
36
44
|
class_name: class_name,
|
37
45
|
user_id: user&.id,
|
38
46
|
channel_id: channel_id,
|
47
|
+
view_id: view_id,
|
39
48
|
payload: payload
|
40
49
|
}
|
41
50
|
@args = SlackBot::Args.new
|
@@ -105,6 +114,10 @@ module SlackBot
|
|
105
114
|
@data[:payload] = payload
|
106
115
|
end
|
107
116
|
|
117
|
+
def view_id=(view_id)
|
118
|
+
@data[:view_id] = view_id
|
119
|
+
end
|
120
|
+
|
108
121
|
def handler_class=(handler_class)
|
109
122
|
new_class_name = handler_class&.name
|
110
123
|
config.find_handler_class(class_name)
|
@@ -125,6 +138,12 @@ module SlackBot
|
|
125
138
|
super
|
126
139
|
end
|
127
140
|
|
141
|
+
def read_view_callback_id
|
142
|
+
return if view_id.blank?
|
143
|
+
|
144
|
+
config.callback_storage_instance.read(view_storage_key)
|
145
|
+
end
|
146
|
+
|
128
147
|
private
|
129
148
|
|
130
149
|
def parse_args
|
@@ -140,13 +159,15 @@ module SlackBot
|
|
140
159
|
end
|
141
160
|
|
142
161
|
def storage_key
|
143
|
-
if
|
144
|
-
raise "User is required for scoped callback" if user.blank?
|
162
|
+
raise "User is required for scoped callback" if user.blank?
|
145
163
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
164
|
+
"#{CALLBACK_KEY_PREFIX}:u#{user.id}:#{id}"
|
165
|
+
end
|
166
|
+
|
167
|
+
def view_storage_key
|
168
|
+
raise "User is required for scoped callback" if user.blank?
|
169
|
+
|
170
|
+
"#{CALLBACK_KEY_PREFIX}:u#{user.id}:#{view_id}"
|
150
171
|
end
|
151
172
|
|
152
173
|
def read_data
|
@@ -155,10 +176,12 @@ module SlackBot
|
|
155
176
|
|
156
177
|
def write_data(data, expires_in: nil)
|
157
178
|
expires_in ||= CALLBACK_RECORD_EXPIRES_IN
|
179
|
+
config.callback_storage_instance.write(view_storage_key, id, expires_in: expires_in) if view_id.present?
|
158
180
|
config.callback_storage_instance.write(storage_key, data, expires_in: expires_in)
|
159
181
|
end
|
160
182
|
|
161
183
|
def delete_data
|
184
|
+
config.callback_storage_instance.delete(view_storage_key) if view_id.present?
|
162
185
|
config.callback_storage_instance.delete(storage_key)
|
163
186
|
end
|
164
187
|
end
|
@@ -18,7 +18,7 @@ module SlackBot
|
|
18
18
|
end
|
19
19
|
|
20
20
|
view_id = response.data.dig("view", "id")
|
21
|
-
callback.
|
21
|
+
callback.view_id = view_id if view_id.present?
|
22
22
|
|
23
23
|
SlackViewsReply.new(callback.id, view_id)
|
24
24
|
end
|
@@ -33,7 +33,7 @@ module SlackBot
|
|
33
33
|
end
|
34
34
|
|
35
35
|
view_id = response.data.dig("view", "id")
|
36
|
-
callback.
|
36
|
+
callback.view_id = view_id if view_id.present?
|
37
37
|
|
38
38
|
SlackViewsReply.new(callback.id, view_id)
|
39
39
|
end
|
data/lib/slack_bot.rb
CHANGED