grape-slack-bot 1.5.5 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +31 -0
- data/lib/slack_bot/callback.rb +1 -1
- data/lib/slack_bot/config.rb +3 -1
- data/lib/slack_bot/errors.rb +10 -0
- data/lib/slack_bot/grape_extension.rb +1 -1
- data/lib/slack_bot/interaction.rb +7 -8
- data/lib/slack_bot.rb +1 -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: 953075c11d83ecf06161ba1ffdda403a08c673c87a598a5d924443a8bf7bb587
|
4
|
+
data.tar.gz: c99d95f100f8e067e19502c2d144454b9d8416534b2e8ef930d31136d1b13ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f184bf86ddce2dacaecce93f8377ef62b562b8ba5cf010993903bac8910af115b5659be794fb9e7961c2ab51d3f48f46622705a595d79aadff089a909c4fce2
|
7
|
+
data.tar.gz: 6e821e2e1aea7494d01ece594de33ba5264ed6ff9e3ab6937ad44a4fb65ddfda1ff44bd717358c3fc4c0ff5a6bf8368988085e277677086d8dffdc5417d6ed7a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -292,6 +292,30 @@ module MySlackBot::Game
|
|
292
292
|
end
|
293
293
|
```
|
294
294
|
|
295
|
+
App home interaction example:
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
module MySlackBot
|
299
|
+
class AppHomeInteraction < SlackBot::Event
|
300
|
+
view MySlackBot::AppHomeView
|
301
|
+
|
302
|
+
def call
|
303
|
+
action_id = payload.dig("actions", 0, "action_id")
|
304
|
+
case action_id
|
305
|
+
when "add_game"
|
306
|
+
add_game
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
private
|
311
|
+
|
312
|
+
def add_game
|
313
|
+
open_modal :add_game_modal
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
```
|
318
|
+
|
295
319
|
## View example
|
296
320
|
|
297
321
|
Modal view example:
|
@@ -452,6 +476,13 @@ module MySlackBot
|
|
452
476
|
class AppHomeOpenedEvent < SlackBot::Event
|
453
477
|
view MySlackBot::AppHomeView
|
454
478
|
def call
|
479
|
+
# NOTE: we have to create callback here in order to handle interactions
|
480
|
+
self.callback = SlackBot::Callback.find_or_create(
|
481
|
+
id: "app_home_opened",
|
482
|
+
user: current_user,
|
483
|
+
class_name: VacationsBot::AppHomeInteraction.name
|
484
|
+
)
|
485
|
+
|
455
486
|
publish_view :index_view
|
456
487
|
end
|
457
488
|
end
|
data/lib/slack_bot/callback.rb
CHANGED
@@ -107,7 +107,7 @@ module SlackBot
|
|
107
107
|
|
108
108
|
def handler_class=(handler_class)
|
109
109
|
new_class_name = handler_class&.name
|
110
|
-
|
110
|
+
config.find_handler_class(class_name)
|
111
111
|
|
112
112
|
self.class_name = new_class_name
|
113
113
|
end
|
data/lib/slack_bot/config.rb
CHANGED
@@ -72,7 +72,9 @@ module SlackBot
|
|
72
72
|
|
73
73
|
def find_handler_class(class_name)
|
74
74
|
@handler_classes ||= {}
|
75
|
-
@handler_classes
|
75
|
+
@handler_classes.fetch(class_name.to_sym)
|
76
|
+
rescue KeyError
|
77
|
+
raise SlackBot::Errors::HandlerClassNotFound.new(class_name, handler_classes: @handler_classes)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
data/lib/slack_bot/errors.rb
CHANGED
@@ -21,6 +21,16 @@ module SlackBot
|
|
21
21
|
class CallbackNotFound < SlackBot::Error
|
22
22
|
end
|
23
23
|
|
24
|
+
class HandlerClassNotFound < SlackBot::Error
|
25
|
+
attr_reader :class_name, :handler_classes
|
26
|
+
def initialize(class_name, handler_classes:)
|
27
|
+
@class_name = class_name
|
28
|
+
@handler_classes = handler_classes
|
29
|
+
|
30
|
+
super("Handler class not found for #{class_name}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
class SlackResponseError < SlackBot::Error
|
25
35
|
attr_reader :error, :data, :payload
|
26
36
|
def initialize(error, data: nil, payload: nil)
|
@@ -84,7 +84,7 @@ module SlackBot
|
|
84
84
|
def handle_block_actions_view(view:, user:, params:)
|
85
85
|
callback_id = view&.dig("callback_id")
|
86
86
|
|
87
|
-
callback = SlackBot::Callback.find(callback_id, config: config)
|
87
|
+
callback = SlackBot::Callback.find(callback_id, user: user, config: config)
|
88
88
|
raise SlackBot::Errors::CallbackNotFound.new if callback.blank?
|
89
89
|
|
90
90
|
SlackBot::DevConsole.log_check "SlackApi::Interactions##{__method__}: #{callback.id} #{callback.payload} #{callback.user_id} #{user&.id}"
|
@@ -47,14 +47,13 @@ module SlackBot
|
|
47
47
|
channel_id: nil,
|
48
48
|
config: nil
|
49
49
|
)
|
50
|
-
callback = Callback.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
)
|
50
|
+
callback = Callback.find_or_create(
|
51
|
+
id: callback_id,
|
52
|
+
class_name: class_name,
|
53
|
+
user: user,
|
54
|
+
channel_id: channel_id,
|
55
|
+
config: config
|
56
|
+
)
|
58
57
|
|
59
58
|
view = payload.merge({ type: "modal", callback_id: callback.id })
|
60
59
|
response =
|
data/lib/slack_bot.rb
CHANGED