grape-slack-bot 1.2.2 → 1.3.0
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 +8 -0
- data/lib/slack_bot/callback.rb +3 -4
- data/lib/slack_bot/command.rb +1 -2
- data/lib/slack_bot/event.rb +2 -2
- data/lib/slack_bot/grape_extension.rb +2 -4
- data/lib/slack_bot/interaction.rb +0 -4
- data/lib/slack_bot.rb +1 -1
- data/spec/slack_bot/callback_spec.rb +3 -13
- 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: 669dbf492365849f4628ed362f0a047e70d15cb80a62a236260be26d76fbaacc
|
4
|
+
data.tar.gz: e17819f3afa4096b5623c4a8d19f6443522c2010d528ac6a14fefc17fb3c3309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05de3c891473d52722c368bd587e7a90b7d8e9eaa96c4f6bd59bd4bbb5f867c265e2fab1b2e95076abd8b75c0dd9460a51ea460909afd538e9c0c0962fe8250c
|
7
|
+
data.tar.gz: c80d3a362202a526df44c32dad70270109ef344180d7d83d27cca9a24c9f308d422c7f8f91215a0a31b357ef2e86d14771b048f344051a7bc48ca27f80fa73d1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 1.3.0
|
2
|
+
|
3
|
+
* Clean up callback arguments, remove unused `method_name`
|
4
|
+
|
5
|
+
# 1.2.3
|
6
|
+
|
7
|
+
* Minor fix for Events API
|
8
|
+
|
1
9
|
# 1.2.2
|
2
10
|
|
3
11
|
* `SlackBot::Callback.find` method will raise `SlackBot::Errors::CallbackNotFound` if callback is not resolved or has wrong data
|
data/lib/slack_bot/callback.rb
CHANGED
@@ -14,19 +14,18 @@ module SlackBot
|
|
14
14
|
nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.create(class_name:,
|
17
|
+
def self.create(class_name:, user:, channel_id: nil, config: nil)
|
18
18
|
callback =
|
19
|
-
new(class_name: class_name,
|
19
|
+
new(class_name: class_name, user: user, channel_id: channel_id, config: config)
|
20
20
|
callback.save
|
21
21
|
callback
|
22
22
|
end
|
23
23
|
|
24
24
|
attr_reader :id, :data, :args, :config
|
25
|
-
def initialize(id: nil, class_name: nil,
|
25
|
+
def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, extra: nil, config: nil)
|
26
26
|
@id = id
|
27
27
|
@data = {
|
28
28
|
class_name: class_name,
|
29
|
-
method_name: method_name,
|
30
29
|
user_id: user&.id,
|
31
30
|
channel_id: channel_id,
|
32
31
|
extra: extra
|
data/lib/slack_bot/command.rb
CHANGED
@@ -48,7 +48,7 @@ module SlackBot
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def open_modal(view_name,
|
51
|
+
def open_modal(view_name, context: nil)
|
52
52
|
view = self.class.view_klass.new(
|
53
53
|
args: args,
|
54
54
|
current_user: @current_user,
|
@@ -61,7 +61,6 @@ module SlackBot
|
|
61
61
|
trigger_id: params[:trigger_id],
|
62
62
|
channel_id: params[:channel_id],
|
63
63
|
class_name: self.class.name,
|
64
|
-
method_name: method_name,
|
65
64
|
user: @current_user,
|
66
65
|
payload: payload,
|
67
66
|
config: config
|
data/lib/slack_bot/event.rb
CHANGED
@@ -22,11 +22,11 @@ module SlackBot
|
|
22
22
|
params["event"]["type"]
|
23
23
|
end
|
24
24
|
|
25
|
-
def publish_view(view_method_name)
|
25
|
+
def publish_view(view_method_name, context: nil)
|
26
26
|
user_id = params["event"]["user"]
|
27
27
|
view =
|
28
28
|
self.class.view_klass
|
29
|
-
.new(current_user: current_user, params: params)
|
29
|
+
.new(current_user: current_user, params: params, context: context)
|
30
30
|
.send(view_method_name)
|
31
31
|
response =
|
32
32
|
SlackBot::ApiClient.new.views_publish(user_id: user_id, view: view)
|
@@ -84,11 +84,9 @@ module SlackBot
|
|
84
84
|
|
85
85
|
def handle_block_actions_view(view:, user:, params:)
|
86
86
|
callback_id = view&.dig("callback_id")
|
87
|
-
callback = SlackBot::Callback.find(callback_id, config: config)
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
end
|
88
|
+
callback = SlackBot::Callback.find(callback_id, config: config)
|
89
|
+
raise SlackBot::Errors::CallbackNotFound.new if callback.blank?
|
92
90
|
|
93
91
|
SlackBot::DevConsole.log_check "SlackApi::Interactions##{__method__}: #{callback.id} #{callback.extra} #{callback.user_id} #{user&.id}"
|
94
92
|
|
@@ -12,7 +12,6 @@ module SlackBot
|
|
12
12
|
trigger_id:,
|
13
13
|
payload:,
|
14
14
|
class_name:,
|
15
|
-
method_name:,
|
16
15
|
user:,
|
17
16
|
channel_id:,
|
18
17
|
config: nil
|
@@ -20,7 +19,6 @@ module SlackBot
|
|
20
19
|
callback =
|
21
20
|
Callback.create(
|
22
21
|
class_name: class_name,
|
23
|
-
method_name: method_name,
|
24
22
|
user: user,
|
25
23
|
channel_id: channel_id,
|
26
24
|
config: config
|
@@ -45,7 +43,6 @@ module SlackBot
|
|
45
43
|
view_id:,
|
46
44
|
payload:,
|
47
45
|
class_name: nil,
|
48
|
-
method_name: nil,
|
49
46
|
user: nil,
|
50
47
|
channel_id: nil,
|
51
48
|
config: nil
|
@@ -54,7 +51,6 @@ module SlackBot
|
|
54
51
|
callback ||=
|
55
52
|
Callback.create(
|
56
53
|
class_name: class_name,
|
57
|
-
method_name: method_name,
|
58
54
|
user: user,
|
59
55
|
channel_id: channel_id,
|
60
56
|
config: config
|
data/lib/slack_bot.rb
CHANGED
@@ -4,7 +4,6 @@ describe SlackBot::Callback do
|
|
4
4
|
subject(:callback) {
|
5
5
|
described_class.new(
|
6
6
|
class_name: "Test",
|
7
|
-
method_name: "test",
|
8
7
|
user: user,
|
9
8
|
channel_id: "test_channel_id",
|
10
9
|
extra: { test: "test" },
|
@@ -34,7 +33,7 @@ describe SlackBot::Callback do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
context "when callback is found" do
|
37
|
-
let(:data) { { class_name: "Test",
|
36
|
+
let(:data) { { class_name: "Test", user_id: 1, channel_id: "test_channel_id", extra: { test: "test" }, args: "" } }
|
38
37
|
|
39
38
|
it "returns callback" do
|
40
39
|
expect(find).to be_a(described_class)
|
@@ -43,7 +42,6 @@ describe SlackBot::Callback do
|
|
43
42
|
expect(find.user).to eq(user)
|
44
43
|
expect(find.user_id).to eq(1)
|
45
44
|
expect(find.channel_id).to eq("test_channel_id")
|
46
|
-
expect(find.method_name).to eq("test")
|
47
45
|
expect(find.extra).to eq({ test: "test" })
|
48
46
|
end
|
49
47
|
end
|
@@ -58,21 +56,20 @@ describe SlackBot::Callback do
|
|
58
56
|
end
|
59
57
|
|
60
58
|
describe ".create" do
|
61
|
-
subject(:create) { described_class.create(class_name: "Test",
|
59
|
+
subject(:create) { described_class.create(class_name: "Test", user: user, channel_id: "test_channel_id", config: config) }
|
62
60
|
|
63
61
|
before do
|
64
62
|
allow_any_instance_of(described_class).to receive(:generate_id).and_return("test_callback_id")
|
65
63
|
allow(callback_storage_instance).to receive(:write).with("slack-bot-callback:test_callback_id", {
|
66
64
|
args: "",
|
67
65
|
class_name: "Test",
|
68
|
-
method_name: "test",
|
69
66
|
user_id: 1,
|
70
67
|
channel_id: "test_channel_id",
|
71
68
|
extra: nil
|
72
69
|
}, expires_in: 1.hour)
|
73
70
|
end
|
74
71
|
|
75
|
-
let(:data) { { class_name: "Test",
|
72
|
+
let(:data) { { class_name: "Test", user_id: 1, channel_id: "test_channel_id", extra: nil } }
|
76
73
|
|
77
74
|
it "returns callback" do
|
78
75
|
expect(create).to be_a(described_class)
|
@@ -81,7 +78,6 @@ describe SlackBot::Callback do
|
|
81
78
|
expect(create.user).to eq(user)
|
82
79
|
expect(create.user_id).to eq(1)
|
83
80
|
expect(create.channel_id).to eq("test_channel_id")
|
84
|
-
expect(create.method_name).to eq("test")
|
85
81
|
expect(create.extra).to eq(nil)
|
86
82
|
end
|
87
83
|
end
|
@@ -94,7 +90,6 @@ describe SlackBot::Callback do
|
|
94
90
|
let(:data) {
|
95
91
|
{
|
96
92
|
class_name: "Test",
|
97
|
-
method_name: "test",
|
98
93
|
user_id: 1,
|
99
94
|
channel_id: "test_channel_id",
|
100
95
|
extra: { test: "test" },
|
@@ -113,7 +108,6 @@ describe SlackBot::Callback do
|
|
113
108
|
expect(reload.user).to eq(user)
|
114
109
|
expect(reload.user_id).to eq(1)
|
115
110
|
expect(reload.channel_id).to eq("test_channel_id")
|
116
|
-
expect(reload.method_name).to eq("test")
|
117
111
|
expect(reload.extra).to eq({ test: "test" })
|
118
112
|
end
|
119
113
|
|
@@ -131,7 +125,6 @@ describe SlackBot::Callback do
|
|
131
125
|
let(:callback) {
|
132
126
|
described_class.new(
|
133
127
|
class_name: "Test",
|
134
|
-
method_name: "test",
|
135
128
|
user: user,
|
136
129
|
channel_id: "test_channel_id",
|
137
130
|
extra: { test: "test" },
|
@@ -144,7 +137,6 @@ describe SlackBot::Callback do
|
|
144
137
|
allow(callback_storage_instance).to receive(:write).with("slack-bot-callback:test_callback_id", {
|
145
138
|
args: "",
|
146
139
|
class_name: "Test",
|
147
|
-
method_name: "test",
|
148
140
|
user_id: 1,
|
149
141
|
channel_id: "test_channel_id",
|
150
142
|
extra: { test: "test" }
|
@@ -165,7 +157,6 @@ describe SlackBot::Callback do
|
|
165
157
|
described_class.new(
|
166
158
|
id: "test_callback_id",
|
167
159
|
class_name: "Test",
|
168
|
-
method_name: "test",
|
169
160
|
user: user,
|
170
161
|
channel_id: "test_channel_id",
|
171
162
|
extra: { test: "test" },
|
@@ -177,7 +168,6 @@ describe SlackBot::Callback do
|
|
177
168
|
allow(callback_storage_instance).to receive(:write).with("slack-bot-callback:test_callback_id", {
|
178
169
|
args: "",
|
179
170
|
class_name: "Test",
|
180
|
-
method_name: "test",
|
181
171
|
user_id: 1,
|
182
172
|
channel_id: "test_channel_id",
|
183
173
|
extra: { test: "test" },
|