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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8369c909fff6a3b4da241ee643cc4eb88aea44b4cf36b46d23894d98485b99b7
4
- data.tar.gz: 6b20d7329e693eada51866d5a20fa57f964bbf24996ff59b073773751dd59843
3
+ metadata.gz: 953075c11d83ecf06161ba1ffdda403a08c673c87a598a5d924443a8bf7bb587
4
+ data.tar.gz: c99d95f100f8e067e19502c2d144454b9d8416534b2e8ef930d31136d1b13ec7
5
5
  SHA512:
6
- metadata.gz: e6e153e24e4b69c9447ab1a91f989213b0786f05ce25fb9ef726b855fe93e847c03ae00496379aa67f24de67f2a4b96e9a49f4c29589898044f04cda73131d41
7
- data.tar.gz: 00aa26edbe0a901e646905ce3ba7b154ca112fd33340a86592860ec9e766ac1ee37bc616d0eaf63bbc9785ca901f761f46f8e60e2da4c0ea8fee31a6a11aedda
6
+ metadata.gz: 3f184bf86ddce2dacaecce93f8377ef62b562b8ba5cf010993903bac8910af115b5659be794fb9e7961c2ab51d3f48f46622705a595d79aadff089a909c4fce2
7
+ data.tar.gz: 6e821e2e1aea7494d01ece594de33ba5264ed6ff9e3ab6937ad44a4fb65ddfda1ff44bd717358c3fc4c0ff5a6bf8368988085e277677086d8dffdc5417d6ed7a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.5.7
2
+
3
+ * Raise error if handler class not resolved
4
+ * App home interaction example added
5
+ * Callback logic and usage fixed
6
+ * Views improvements
7
+
1
8
  # 1.5.0
2
9
 
3
10
  * Complete upgrade of callback storage logic
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
@@ -107,7 +107,7 @@ module SlackBot
107
107
 
108
108
  def handler_class=(handler_class)
109
109
  new_class_name = handler_class&.name
110
- raise "Callback handler class not found" if !config.find_handler_class(class_name)
110
+ config.find_handler_class(class_name)
111
111
 
112
112
  self.class_name = new_class_name
113
113
  end
@@ -72,7 +72,9 @@ module SlackBot
72
72
 
73
73
  def find_handler_class(class_name)
74
74
  @handler_classes ||= {}
75
- @handler_classes[class_name.to_sym]
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
 
@@ -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.find(callback_id, config: config) if callback_id.present?
51
- callback ||=
52
- Callback.create(
53
- class_name: class_name,
54
- user: user,
55
- channel_id: channel_id,
56
- config: config
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
@@ -22,5 +22,5 @@ require 'slack_bot/pager'
22
22
  require 'slack_bot/grape_extension'
23
23
 
24
24
  module SlackBot
25
- VERSION = '1.5.5'.freeze
25
+ VERSION = '1.5.7'.freeze
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-slack-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov