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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3de1463a851b1c0e6cc5daa8b2919211d82bffac137626309ac970b16ec0c85
4
- data.tar.gz: 3fccc170cf87469ea75374572ca628629bedf43acbd2ef7844b8a67c1147c9cd
3
+ metadata.gz: 17a7e4563e7eb26dcd8ca99fbe366c3024d927d0716576984ce7371578148ff7
4
+ data.tar.gz: 7c366ef08784262accb9de4e9a9432c01a30226c24c4e01f3ff0eb6875593701
5
5
  SHA512:
6
- metadata.gz: c72a69682bed9b58795030edb2f23356e2734bd046d5cbd61c6785bafcb28f2695409586f8fdc727a4098b53036e7c06a5cb554818440ffe30709f82c605edc6
7
- data.tar.gz: 8f3eb21e7ddc06069e0109dffd068d64d0d43bdd89656641ad01be26aeaa2ae2e36d01baa191d42cbae6d861d6260879a78fb2407fab484e129433ea184e0862
6
+ metadata.gz: fef7839cbbdd0892aebc3177a5996603a2cbf89d54b06ed71fb06d85163f27039f7ece113c2ade62b8d12b49cab24d7dfd31d7c67d39b96dde1bfbb7fab1ac73
7
+ data.tar.gz: a08625699825f3bbfee9c1ec6929bec5a1f7ecdf3a6a16d111a7d543f151000c4498949da68fec417b05d56d1aad23dcd065bffb2b97a752ca3ea22a3108ef9f
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-07-19 11:07:59 -0400 using RuboCop version 0.81.0.
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: 2
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'
@@ -1,5 +1,9 @@
1
1
  ### Changelog
2
2
 
3
+ #### 0.2.0 (07/19/2020)
4
+
5
+ * Include action type in actions callbacks - [@dblock](https://github.com/dblock).
6
+
3
7
  #### 0.1.0 (07/19/2020)
4
8
 
5
9
  * Initial public release - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- Slack Ruby Bot Server Slack Extensions
1
+ Slack Ruby Bot Server Events Extension
2
2
  ======================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/slack-ruby-bot-server-events.svg)](https://badge.fury.io/rb/slack-ruby-bot-server-events)
5
5
  [![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events.svg?branch=master)](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 enables handling of Slack slash commands, interactive buttons and events.
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`. The following example unfurls URLs and fails any other event type.
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, ['event_callback', 'link_shared'] do |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: '...').chat_unfurl(
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
- raise "I don't know how to handle #{event[:event][:type]}."
67
+ # handle any event callback
68
+ false
66
69
  end
67
70
 
68
71
  config.on :event do |event|
69
- raise "I don't know how to handle #{event[:type]}."
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
- # action[:payload][:callback_id] is 'action_id'
83
- { text: 'Success!' }
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
- { text: "I don't know how to handle #{action[:payload][:callback_id]}." }
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, '/test' do
99
- { text: 'Success!' }
114
+ config.on :command, '/ping' do
115
+ { text: 'pong' }
100
116
  end
101
117
 
102
118
  config.on :command do |command|
103
- { text: "I don't know how to handle #{command[:command]}." }
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
- requires :channel, type: Hash do
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
- requires :user, type: String
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(types, value = nil, &block)
27
- Array(types).each do |type|
28
- value_key = Array(value).compact.join('/') if value
29
- key = [type.to_s, value_key].compact.join('/')
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SlackRubyBotServer
4
4
  module Events
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.1.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-19 00:00:00.000000000 Z
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