grape-slack-bot 1.5.6 → 1.5.8
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 +25 -1
- data/lib/slack_bot/callback.rb +1 -1
- data/lib/slack_bot/config.rb +4 -1
- data/lib/slack_bot/errors.rb +10 -0
- data/lib/slack_bot/event.rb +4 -0
- 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: 2b60e4e6431b476b397857caf09be7d11d1f2215e4ab5ab912e77c1289ab5285
|
4
|
+
data.tar.gz: 5a11a97b7ed08470a83163f4c77fa52eb895bdbe260159c87c2fbae1c302fe58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 669f0d6b4b8b5475b5fdcfe58d281d9b3b0f3f49fa6b083469708789cbf2fa2202d2cb427a78148a9502154325680a4c6d3f254e10367a25b17441c9b91fcfcf
|
7
|
+
data.tar.gz: 8c0e1357083e27ec6477c7cfd9a9f029178bfc38ad68af451af1cee21e16261744b6268782cdd9aada62aae83bfcae328182647f7157f4385ff5ca3de6701a9b
|
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:
|
@@ -456,7 +480,7 @@ module MySlackBot
|
|
456
480
|
self.callback = SlackBot::Callback.find_or_create(
|
457
481
|
id: "app_home_opened",
|
458
482
|
user: current_user,
|
459
|
-
class_name:
|
483
|
+
class_name: self.class.name
|
460
484
|
)
|
461
485
|
|
462
486
|
publish_view :index_view
|
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
@@ -26,6 +26,7 @@ module SlackBot
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def event(event_type, event_klass)
|
29
|
+
handler_class(event_klass.name, event_klass)
|
29
30
|
event_handlers[event_type.to_sym] = event_klass
|
30
31
|
end
|
31
32
|
|
@@ -72,7 +73,9 @@ module SlackBot
|
|
72
73
|
|
73
74
|
def find_handler_class(class_name)
|
74
75
|
@handler_classes ||= {}
|
75
|
-
@handler_classes
|
76
|
+
@handler_classes.fetch(class_name.to_sym)
|
77
|
+
rescue KeyError
|
78
|
+
raise SlackBot::Errors::HandlerClassNotFound.new(class_name, handler_classes: @handler_classes)
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
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)
|
data/lib/slack_bot/event.rb
CHANGED
data/lib/slack_bot.rb
CHANGED