slack-ruby-bot-server-events 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -3
- data/CHANGELOG.md +4 -0
- data/README.md +32 -15
- data/lib/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint.rb +4 -3
- data/lib/slack-ruby-bot-server-events/config.rb +4 -6
- data/lib/slack-ruby-bot-server-events/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a7e4563e7eb26dcd8ca99fbe366c3024d927d0716576984ce7371578148ff7
|
4
|
+
data.tar.gz: 7c366ef08784262accb9de4e9a9432c01a30226c24c4e01f3ff0eb6875593701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef7839cbbdd0892aebc3177a5996603a2cbf89d54b06ed71fb06d85163f27039f7ece113c2ade62b8d12b49cab24d7dfd31d7c67d39b96dde1bfbb7fab1ac73
|
7
|
+
data.tar.gz: a08625699825f3bbfee9c1ec6929bec5a1f7ecdf3a6a16d111a7d543f151000c4498949da68fec417b05d56d1aad23dcd065bffb2b97a752ca3ea22a3108ef9f
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2020-07-19
|
3
|
+
# on 2020-07-19 23:46:20 -0400 using RuboCop version 0.81.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -13,9 +13,8 @@ Naming/FileName:
|
|
13
13
|
Exclude:
|
14
14
|
- 'lib/slack-ruby-bot-server-events.rb'
|
15
15
|
|
16
|
-
# Offense count:
|
16
|
+
# Offense count: 1
|
17
17
|
# Configuration parameters: MinBodyLength.
|
18
18
|
Style/GuardClause:
|
19
19
|
Exclude:
|
20
|
-
- 'spec/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint_spec.rb'
|
21
20
|
- 'spec/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint_spec.rb'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
Slack Ruby Bot Server
|
1
|
+
Slack Ruby Bot Server Events Extension
|
2
2
|
======================================
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/slack-ruby-bot-server-events)
|
5
5
|
[](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events)
|
6
6
|
|
7
|
-
An extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that
|
7
|
+
An extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that makes it easy to handle Slack slash commands, interactive buttons and events.
|
8
8
|
|
9
9
|
### Sample
|
10
10
|
|
@@ -43,13 +43,15 @@ This library supports events, actions and commands. When implementing multiple c
|
|
43
43
|
|
44
44
|
#### Events
|
45
45
|
|
46
|
-
Respond to [Slack Events](https://api.slack.com/events-api) by implementing `SlackRubyBotServer::Events::Config#on :event`.
|
46
|
+
Respond to [Slack Events](https://api.slack.com/events-api) by implementing `SlackRubyBotServer::Events::Config#on :event`.
|
47
|
+
|
48
|
+
The following example unfurls URLs.
|
47
49
|
|
48
50
|
```ruby
|
49
51
|
SlackRubyBotServer::Events.configure do |config|
|
50
|
-
config.on :event,
|
52
|
+
config.on :event, 'event_callback', 'link_shared' do |event|
|
51
53
|
event[:event][:links].each do |link|
|
52
|
-
Slack::Web::Client.new(token:
|
54
|
+
Slack::Web::Client.new(token: ...).chat_unfurl(
|
53
55
|
channel: event[:event][:channel],
|
54
56
|
ts: event[:event][:message_ts],
|
55
57
|
unfurls: {
|
@@ -62,11 +64,13 @@ SlackRubyBotServer::Events.configure do |config|
|
|
62
64
|
end
|
63
65
|
|
64
66
|
config.on :event, 'event_callback' do |event|
|
65
|
-
|
67
|
+
# handle any event callback
|
68
|
+
false
|
66
69
|
end
|
67
70
|
|
68
71
|
config.on :event do |event|
|
69
|
-
|
72
|
+
# handle any event[:event][:type]
|
73
|
+
false
|
70
74
|
end
|
71
75
|
end
|
72
76
|
```
|
@@ -74,17 +78,27 @@ end
|
|
74
78
|
|
75
79
|
#### Actions
|
76
80
|
|
77
|
-
Respond to [Interactive Message Buttons](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
|
81
|
+
Respond to [Shortcuts](https://api.slack.com/interactivity/shortcuts) and [Interactive Message Buttons](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
|
82
|
+
|
83
|
+
The following example posts an ephemeral message that counts the letters in a message shortcut.
|
78
84
|
|
79
85
|
```ruby
|
80
86
|
SlackRubyBotServer::Events.configure do |config|
|
81
|
-
config.on :action, 'action_id' do |action|
|
82
|
-
|
83
|
-
|
87
|
+
config.on :action, 'interactive_message', 'action_id' do |action|
|
88
|
+
payload = action[:payload]
|
89
|
+
message = payload[:message]
|
90
|
+
|
91
|
+
Faraday.post(payload[:response_url], {
|
92
|
+
text: "The text \"#{message[:text]}\" has #{message[:text].size} letter(s).",
|
93
|
+
response_type: 'ephemeral'
|
94
|
+
}.to_json, 'Content-Type' => 'application/json')
|
95
|
+
|
96
|
+
true
|
84
97
|
end
|
85
98
|
|
86
99
|
config.on :action do |action|
|
87
|
-
|
100
|
+
# handle any other action
|
101
|
+
false
|
88
102
|
end
|
89
103
|
end
|
90
104
|
```
|
@@ -93,14 +107,17 @@ end
|
|
93
107
|
|
94
108
|
Respond to [Slash Commands](https://api.slack.com/interactivity/slash-commands) by implementing `SlackRubyBotServer::Events::Config#on :command`.
|
95
109
|
|
110
|
+
The following example responds to `/ping` with `pong`.
|
111
|
+
|
96
112
|
```ruby
|
97
113
|
SlackRubyBotServer::Events.configure do |config|
|
98
|
-
config.on :command, '/
|
99
|
-
{ text: '
|
114
|
+
config.on :command, '/ping' do
|
115
|
+
{ text: 'pong' }
|
100
116
|
end
|
101
117
|
|
102
118
|
config.on :command do |command|
|
103
|
-
|
119
|
+
# handle any other command
|
120
|
+
false
|
104
121
|
end
|
105
122
|
end
|
106
123
|
```
|
@@ -14,7 +14,7 @@ module SlackRubyBotServer
|
|
14
14
|
optional :type, type: String
|
15
15
|
optional :trigger_id, type: String
|
16
16
|
optional :response_url, type: String
|
17
|
-
|
17
|
+
optional :channel, type: Hash do
|
18
18
|
requires :id, type: String
|
19
19
|
optional :name, type: String
|
20
20
|
end
|
@@ -31,7 +31,7 @@ module SlackRubyBotServer
|
|
31
31
|
end
|
32
32
|
optional :message, type: Hash do
|
33
33
|
requires :type, type: String
|
34
|
-
|
34
|
+
optional :user, type: String
|
35
35
|
requires :ts, type: String
|
36
36
|
requires :text, type: String
|
37
37
|
end
|
@@ -39,8 +39,9 @@ module SlackRubyBotServer
|
|
39
39
|
end
|
40
40
|
post '/action' do
|
41
41
|
action = SlackRubyBotServer::Events::Requests::Action.new(params, request)
|
42
|
+
payload_type = params[:payload][:type]
|
42
43
|
callback_id = params[:payload][:callback_id]
|
43
|
-
SlackRubyBotServer::Events.config.run_callbacks(:action, callback_id, action) || body(false)
|
44
|
+
SlackRubyBotServer::Events.config.run_callbacks(:action, [payload_type, callback_id].compact, action) || body(false)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
@@ -23,12 +23,10 @@ module SlackRubyBotServer
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def on(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
callbacks[key] << block
|
31
|
-
end
|
26
|
+
def on(type, *values, &block)
|
27
|
+
value_key = values.compact.join('/') if values.any?
|
28
|
+
key = [type.to_s, value_key].compact.join('/')
|
29
|
+
callbacks[key] << block
|
32
30
|
end
|
33
31
|
|
34
32
|
def run_callbacks(type, value, args)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-bot-server-events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-bot-server
|