grape-slack-bot 1.6.3 → 1.6.5
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: 6dd62b47329ef32dcdcca944a6e92d61010e99c3521bdc10993a8d7495a5f664
|
4
|
+
data.tar.gz: 2c8a5746152b33a557567405079a14a9646e4ba7fcb1819a042128c9e2830f7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b2faa38f309c0851235d6528eda0b110f219eed374c7791999f8b3ded2063ca050360d5a312fa1f9cafd56d3e44041c0b1c08e40f9200637007f8350f84c77c
|
7
|
+
data.tar.gz: 681ebb8c167698b46c8f300491d3097a85809da8584796688f305a783ea64f3d6e5be56cee798338474f081aa25e51241e4a98f4b9de41a3ab7082205c84eaf1
|
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
|
@@ -71,8 +71,8 @@ module SlackBot
|
|
71
71
|
view.send(view_name)
|
72
72
|
end
|
73
73
|
|
74
|
-
def open_modal(view_name, context: nil
|
75
|
-
callback ||= Callback.create(
|
74
|
+
def open_modal(view_name, context: nil)
|
75
|
+
self.callback ||= Callback.create(
|
76
76
|
class_name: self.class.name,
|
77
77
|
user: @current_user,
|
78
78
|
config: config
|
data/lib/slack_bot.rb
CHANGED