grape-slack-bot 1.6.0 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/slack_bot/command.rb +7 -3
- data/lib/slack_bot/config.rb +27 -10
- data/lib/slack_bot/event.rb +12 -4
- data/lib/slack_bot/interaction.rb +24 -11
- 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: 82392f6ebad8f2ffdf5eb575cfb6c76773567805144202cd8d9ca3124fc7352e
|
4
|
+
data.tar.gz: 8829c6658a0577206e927f1750b4d5c063c4666abc1d37b2428134ec65f05358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23f3d1b7e26aa66af1e8e0a0f0ca74c4b534b016a341aed1c1d47746e46a9df9d6280eb1a5671d75a331ed6f36c79e16cd08e37486ce521d051d656b1966ffd6
|
7
|
+
data.tar.gz: e1f2d01b86e6134a49f92f2a84d5ed9f7943a1a80f8b6c528f941f5de431dbd8fdff48c13d03407a79db1a93846acc32cc9d32055975dcc20e2565f13830444a
|
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
|
data/lib/slack_bot/command.rb
CHANGED
@@ -46,7 +46,7 @@ module SlackBot
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def
|
49
|
+
def render_view(view_name, context: nil)
|
50
50
|
view = self.class.view_klass.new(
|
51
51
|
args: args,
|
52
52
|
current_user: @current_user,
|
@@ -54,13 +54,17 @@ module SlackBot
|
|
54
54
|
context: context,
|
55
55
|
config: config
|
56
56
|
)
|
57
|
-
|
57
|
+
view.send(view_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def open_modal(view_name, context: nil)
|
61
|
+
view_payload = render_view(view_name, context: context)
|
58
62
|
self.class.interaction_klass.open_modal(
|
59
63
|
trigger_id: params[:trigger_id],
|
60
64
|
channel_id: params[:channel_id],
|
61
65
|
class_name: self.class.name,
|
62
66
|
user: @current_user,
|
63
|
-
payload:
|
67
|
+
payload: view_payload,
|
64
68
|
config: config
|
65
69
|
)
|
66
70
|
render_response
|
data/lib/slack_bot/config.rb
CHANGED
@@ -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
|
-
|
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(
|
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
|
-
|
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
|
-
|
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)
|
data/lib/slack_bot/event.rb
CHANGED
@@ -32,12 +32,20 @@ module SlackBot
|
|
32
32
|
params["event"]["type"]
|
33
33
|
end
|
34
34
|
|
35
|
+
def render_view(view_name, context: nil)
|
36
|
+
view = self.class.view_klass.new(
|
37
|
+
args: callback&.args,
|
38
|
+
current_user: current_user,
|
39
|
+
params: params,
|
40
|
+
context: context,
|
41
|
+
config: config
|
42
|
+
)
|
43
|
+
view.send(view_name)
|
44
|
+
end
|
45
|
+
|
35
46
|
def publish_view(view_method_name, context: nil)
|
36
47
|
user_id = params["event"]["user"]
|
37
|
-
view =
|
38
|
-
self.class.view_klass
|
39
|
-
.new(current_user: current_user, params: params, context: context)
|
40
|
-
.send(view_method_name)
|
48
|
+
view = render_view(view_method_name, context: context)
|
41
49
|
view = view.merge(callback_id: callback.id) if callback.present?
|
42
50
|
view = view.merge(private_metadata: metadata) if metadata.present?
|
43
51
|
response =
|
@@ -13,7 +13,7 @@ module SlackBot
|
|
13
13
|
payload:,
|
14
14
|
class_name:,
|
15
15
|
user:,
|
16
|
-
channel_id
|
16
|
+
channel_id: nil,
|
17
17
|
config: nil
|
18
18
|
)
|
19
19
|
callback =
|
@@ -91,20 +91,33 @@ module SlackBot
|
|
91
91
|
payload["actions"]
|
92
92
|
end
|
93
93
|
|
94
|
+
def render_view(view_name, context: nil)
|
95
|
+
view = self.class.view_klass.new(
|
96
|
+
args: callback&.args,
|
97
|
+
current_user: current_user,
|
98
|
+
params: params,
|
99
|
+
context: context,
|
100
|
+
config: config
|
101
|
+
)
|
102
|
+
view.send(view_name)
|
103
|
+
end
|
104
|
+
|
105
|
+
def open_modal(view_name, context: nil)
|
106
|
+
view_payload = render_view(view_name, context: context)
|
107
|
+
self.class.open_modal(
|
108
|
+
trigger_id: payload["trigger_id"],
|
109
|
+
payload: view_payload,
|
110
|
+
class_name: self.class.name,
|
111
|
+
user: current_user,
|
112
|
+
config: config
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
94
116
|
def update_modal(view_name, context: nil)
|
95
117
|
return if callback.blank?
|
96
118
|
|
97
119
|
view_id = payload["view"]["id"]
|
98
|
-
|
99
|
-
view =
|
100
|
-
self.class.view_klass.new(
|
101
|
-
args: args,
|
102
|
-
current_user: current_user,
|
103
|
-
params: params,
|
104
|
-
context: context,
|
105
|
-
config: config
|
106
|
-
)
|
107
|
-
payload = view.send(view_name)
|
120
|
+
payload = render_view(view_name, context: context)
|
108
121
|
|
109
122
|
self.class.update_modal(
|
110
123
|
view_id: view_id,
|
data/lib/slack_bot.rb
CHANGED