grape-slack-bot 1.6.1 → 1.6.3

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: c4cd56999a5a9b67729fe61e5f95a79f6a0ab89aeafaa43f7537b4501fe6b81a
4
- data.tar.gz: 867a61f2c1f28c82f1c0d3e5bef97ecf6602176c7d89fe221d57c8161048b628
3
+ metadata.gz: 1329dfec4d088344fdfec6196c57d74afb0da0b97c4366a5613d1d73f4a86137
4
+ data.tar.gz: c55a6ac5ed4bbe4315e418f8fee85ae8c46725ebc1bb7e772d74dfb2caaf20a7
5
5
  SHA512:
6
- metadata.gz: 1bed9b092db2eaa13610c7e892663d2d5313321d49dc5e097b7278a1d12f9e47d812e101f153892b8b3d7a71cb5141a2fc189fd5689f54cbcd36ae747e7510f3
7
- data.tar.gz: bce0459566f928181c2bef05062109d11f2633717c06e60841b2001c003bf0d317b92f234ed1eb7b0fdba0424120fd7fe6886f7753cedc3a2f784c3cd03a78c1
6
+ metadata.gz: 67d60fcee908e3f81b56ccecd4698f709ea91a3873288a557c44b59a7c3b3c0005e39f3cb386110b7466266e8a5711cd2fc3d6b8b6315d57f422f5d6873f1da9
7
+ data.tar.gz: 35ec83c38bf5072996657f701067d4e4efb6e271755cc1ada7affd77935c2cb8915a1cff0f123ece587b40cdb96cf5e5dcc8975190f5cd56a5c73e42db128379
data/README.md CHANGED
@@ -141,6 +141,7 @@ SlackBot::Config.configure do
141
141
 
142
142
  # TODO: Register event handlers
143
143
  event :app_home_opened, MySlackBot::AppHomeOpenedEvent
144
+ interaction MySlackBot::AppHomeInteraction
144
145
 
145
146
  # TODO: Register slash command handlers
146
147
  slash_command_endpoint :game, MySlackBot::Game::MenuCommand do
@@ -57,16 +57,19 @@ module SlackBot
57
57
  view.send(view_name)
58
58
  end
59
59
 
60
- def open_modal(view_name, context: nil)
61
- view_payload = render_view(view_name, context: context)
62
- self.class.interaction_klass.open_modal(
63
- trigger_id: params[:trigger_id],
64
- channel_id: params[:channel_id],
60
+ def open_modal(view_name, context: nil, callback: nil)
61
+ callback ||= Callback.create(
65
62
  class_name: self.class.name,
66
63
  user: @current_user,
67
- payload: view_payload,
64
+ channel_id: params[:channel_id],
68
65
  config: config
69
66
  )
67
+ view_payload = render_view(view_name, context: context)
68
+ self.class.interaction_klass.open_modal(
69
+ callback: callback,
70
+ trigger_id: params[:trigger_id],
71
+ payload: view_payload
72
+ )
70
73
  render_response
71
74
  end
72
75
  end
@@ -21,12 +21,18 @@ module SlackBot
21
21
  @callback_user_finder_method = method_lambda
22
22
  end
23
23
 
24
+ def interaction(interaction_klass, handler_name: nil)
25
+ handler_name ||= interaction_klass.name
26
+ handler_class(handler_name, interaction_klass)
27
+ end
28
+
24
29
  def event_handlers
25
30
  @event_handlers ||= {}
26
31
  end
27
32
 
28
- def event(event_type, event_klass)
29
- handler_class(event_klass.name, event_klass)
33
+ def event(event_type, event_klass, handler_name: nil)
34
+ handler_name ||= event_klass.name
35
+ handler_class(handler_name, event_klass)
30
36
  event_handlers[event_type.to_sym] = event_klass
31
37
  end
32
38
 
@@ -34,12 +40,17 @@ module SlackBot
34
40
  event_handlers[event_type.to_sym]
35
41
  end
36
42
 
37
- def slash_command_endpoint(url_token, command_klass = nil, &block)
43
+ def slash_command_endpoint(url_token, command_klass = nil, handler_name: nil, &block)
38
44
  @slash_command_endpoints ||= {}
39
45
  @slash_command_endpoints[url_token.to_sym] ||=
40
46
  begin
41
47
  endpoint =
42
- SlashCommandEndpointConfig.new(url_token, command_klass: command_klass, config: self)
48
+ SlashCommandEndpointConfig.new(
49
+ url_token,
50
+ command_klass: command_klass,
51
+ config: self,
52
+ handler_name: handler_name
53
+ )
43
54
  endpoint.instance_eval(&block) if block_given?
44
55
  endpoint
45
56
  end
@@ -81,16 +92,19 @@ module SlackBot
81
92
 
82
93
  class SlashCommandEndpointConfig
83
94
  attr_reader :url_token, :command_klass, :routes, :config
84
- def initialize(url_token, config:, command_klass: nil, routes: {})
95
+ def initialize(url_token, config:, command_klass: nil, routes: {}, handler_name: nil)
85
96
  @url_token = url_token
86
97
  @command_klass = command_klass
87
98
  @routes = routes
88
99
  @config = config
89
100
 
90
- config.handler_class(command_klass.name, command_klass) if command_klass.present?
101
+ if command_klass.present?
102
+ handler_name ||= command_klass.name
103
+ config.handler_class(handler_name, command_klass)
104
+ end
91
105
  end
92
106
 
93
- def command(command_token, command_klass, &block)
107
+ def command(command_token, command_klass, handler_name: nil, &block)
94
108
  @command_configs ||= {}
95
109
  @command_configs[command_token.to_sym] ||=
96
110
  begin
@@ -98,7 +112,8 @@ module SlackBot
98
112
  SlashCommandConfig.new(
99
113
  command_klass: command_klass,
100
114
  token: command_token,
101
- endpoint: self
115
+ endpoint: self,
116
+ handler_name: handler_name
102
117
  )
103
118
  command.instance_eval(&block) if block_given?
104
119
  command
@@ -127,14 +142,16 @@ module SlackBot
127
142
  end
128
143
 
129
144
  attr_accessor :command_klass, :token, :parent_configs, :endpoint
130
- def initialize(command_klass:, token:, endpoint:, parent_configs: [])
145
+ def initialize(command_klass:, token:, endpoint:, parent_configs: [], handler_name: nil)
131
146
  @command_klass = command_klass
132
147
  @token = token
133
148
  @parent_configs = parent_configs || []
134
149
  @endpoint = endpoint
135
150
 
136
151
  endpoint.routes[full_token] = self
137
- endpoint.config.handler_class(command_klass.name, command_klass)
152
+
153
+ handler_name ||= command_klass.name
154
+ endpoint.config.handler_class(handler_name, command_klass)
138
155
  end
139
156
 
140
157
  def argument_command(argument_token, klass = nil, &block)
@@ -8,22 +8,7 @@ module SlackBot
8
8
 
9
9
  include SlackBot::Concerns::ViewKlass
10
10
 
11
- def self.open_modal(
12
- trigger_id:,
13
- payload:,
14
- class_name:,
15
- user:,
16
- channel_id: nil,
17
- config: nil
18
- )
19
- callback =
20
- Callback.create(
21
- class_name: class_name,
22
- user: user,
23
- channel_id: channel_id,
24
- config: config
25
- )
26
-
11
+ def self.open_modal(callback:, trigger_id:, payload:)
27
12
  view = payload.merge({ type: "modal", callback_id: callback.id })
28
13
  response =
29
14
  SlackBot::ApiClient.new.views_open(trigger_id: trigger_id, view: view)
@@ -38,23 +23,7 @@ module SlackBot
38
23
  SlackViewsReply.new(callback.id, view_id)
39
24
  end
40
25
 
41
- def self.update_modal(
42
- callback_id: nil,
43
- view_id:,
44
- payload:,
45
- class_name: nil,
46
- user: nil,
47
- channel_id: nil,
48
- config: nil
49
- )
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
- )
57
-
26
+ def self.update_modal(callback:, view_id:, payload:)
58
27
  view = payload.merge({ type: "modal", callback_id: callback.id })
59
28
  response =
60
29
  SlackBot::ApiClient.new.views_update(view_id: view_id, view: view)
@@ -102,14 +71,17 @@ module SlackBot
102
71
  view.send(view_name)
103
72
  end
104
73
 
105
- def open_modal(view_name, context: nil)
74
+ def open_modal(view_name, context: nil, callback: nil)
75
+ callback ||= Callback.create(
76
+ class_name: self.class.name,
77
+ user: @current_user,
78
+ config: config
79
+ )
106
80
  view_payload = render_view(view_name, context: context)
107
81
  self.class.open_modal(
82
+ callback: callback,
108
83
  trigger_id: payload["trigger_id"],
109
- payload: view_payload,
110
- class_name: self.class.name,
111
- user: current_user,
112
- config: config
84
+ payload: view_payload
113
85
  )
114
86
  end
115
87
 
@@ -122,8 +94,7 @@ module SlackBot
122
94
  self.class.update_modal(
123
95
  view_id: view_id,
124
96
  payload: payload,
125
- callback_id: callback.id,
126
- config: config
97
+ callback: callback
127
98
  )
128
99
  end
129
100
 
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.6.1'.freeze
25
+ VERSION = '1.6.3'.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.6.1
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov