slack-ruby-bot-server-events 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d3de1463a851b1c0e6cc5daa8b2919211d82bffac137626309ac970b16ec0c85
4
+ data.tar.gz: 3fccc170cf87469ea75374572ca628629bedf43acbd2ef7844b8a67c1147c9cd
5
+ SHA512:
6
+ metadata.gz: c72a69682bed9b58795030edb2f23356e2734bd046d5cbd61c6785bafcb28f2695409586f8fdc727a4098b53036e7c06a5cb554818440ffe30709f82c605edc6
7
+ data.tar.gz: 8f3eb21e7ddc06069e0109dffd068d64d0d43bdd89656641ad01be26aeaa2ae2e36d01baa191d42cbae6d861d6260879a78fb2407fab484e129433ea184e0862
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ .irbrc
4
+ .bundle
5
+ log
6
+ .env
7
+ *.swp
8
+ Gemfile.lock
9
+ .ruby-version
10
+ pkg
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
@@ -0,0 +1,15 @@
1
+ Metrics:
2
+ Enabled: false
3
+
4
+ Layout/LineLength:
5
+ Max: 500
6
+ Enabled: false
7
+
8
+ Style/Documentation:
9
+ Enabled: false
10
+
11
+ Style/ModuleFunction:
12
+ EnforcedStyle: extend_self
13
+
14
+ inherit_from: .rubocop_todo.yml
15
+
@@ -0,0 +1,21 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-07-19 11:07:59 -0400 using RuboCop version 0.81.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
11
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
12
+ Naming/FileName:
13
+ Exclude:
14
+ - 'lib/slack-ruby-bot-server-events.rb'
15
+
16
+ # Offense count: 2
17
+ # Configuration parameters: MinBodyLength.
18
+ Style/GuardClause:
19
+ Exclude:
20
+ - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint_spec.rb'
21
+ - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint_spec.rb'
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ matrix:
6
+ include:
7
+ - rvm: 2.6.6
8
+ script:
9
+ - bundle exec danger
10
+ - rvm: 2.6.6
11
+ env: DATABASE_ADAPTER=activerecord
12
+ services:
13
+ - postgresql
14
+ - rvm: 2.6.6
15
+ env: DATABASE_ADAPTER=mongoid
16
+ services:
17
+ - mongodb
@@ -0,0 +1,5 @@
1
+ ### Changelog
2
+
3
+ #### 0.1.0 (07/19/2020)
4
+
5
+ * Initial public release - [@dblock](https://github.com/dblock).
@@ -0,0 +1,125 @@
1
+ # Contributing to SlackRubyBotServer::Events
2
+
3
+ This project is work of [many contributors](https://github.com/slack-ruby/slack-ruby-bot-server-events/graphs/contributors).
4
+
5
+ You're encouraged to submit [pull requests](https://github.com/slack-ruby/slack-ruby-bot-server-events/pulls), [propose features and discuss issues](https://github.com/slack-ruby/slack-ruby-bot-server-events/issues).
6
+
7
+ In the examples below, substitute your Github username for `contributor` in URLs.
8
+
9
+ ## Fork the Project
10
+
11
+ Fork the [project on Github](https://github.com/slack-ruby/slack-ruby-bot-server-events) and check out your copy.
12
+
13
+ ```
14
+ git clone https://github.com/contributor/slack-ruby-bot-server-events.git
15
+ cd slack-ruby-bot-server-events
16
+ git remote add upstream https://github.com/slack-ruby/slack-ruby-bot-server-events.git
17
+ ```
18
+
19
+ ## Create a Topic Branch
20
+
21
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
22
+
23
+ ```
24
+ git checkout master
25
+ git pull upstream master
26
+ git checkout -b my-feature-branch
27
+ ```
28
+
29
+ ## Bundle Install and Test
30
+
31
+ Ensure that you can build the project and run tests.
32
+
33
+ ```
34
+ bundle install
35
+ bundle exec rake
36
+ ```
37
+
38
+ ## Write Tests
39
+
40
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
41
+ Add to [spec](spec).
42
+
43
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
44
+
45
+ ## Write Code
46
+
47
+ Implement your feature or bug fix.
48
+
49
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
50
+ Run `bundle exec rubocop` and fix any style issues highlighted.
51
+
52
+ Make sure that `bundle exec rake` completes without errors.
53
+
54
+ ## Write Documentation
55
+
56
+ Document any external behavior in the [README](README.md).
57
+
58
+ ## Update Changelog
59
+
60
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
61
+ Make it look like every other line, including your name and link to your Github account.
62
+
63
+ ## Commit Changes
64
+
65
+ Make sure git knows your name and email address:
66
+
67
+ ```
68
+ git config --global user.name "Your Name"
69
+ git config --global user.email "contributor@example.com"
70
+ ```
71
+
72
+ Writing good commit logs is important. A commit log should describe what changed and why.
73
+
74
+ ```
75
+ git add ...
76
+ git commit
77
+ ```
78
+
79
+ ## Push
80
+
81
+ ```
82
+ git push origin my-feature-branch
83
+ ```
84
+
85
+ ## Make a Pull Request
86
+
87
+ Go to https://github.com/contributor/slack-ruby-bot-server-events and select your feature branch.
88
+ Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
+
90
+ ## Rebase
91
+
92
+ If you've been working on a change for a while, rebase with upstream/master.
93
+
94
+ ```
95
+ git fetch upstream
96
+ git rebase upstream/master
97
+ git push origin my-feature-branch -f
98
+ ```
99
+
100
+ ## Update CHANGELOG Again
101
+
102
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
103
+
104
+ ```
105
+ * [#123](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
106
+ ```
107
+
108
+ Amend your previous commit and force push the changes.
109
+
110
+ ```
111
+ git commit --amend
112
+ git push origin my-feature-branch -f
113
+ ```
114
+
115
+ ## Check on Your Pull Request
116
+
117
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+
119
+ ## Be Patient
120
+
121
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
+
123
+ ## Thank You
124
+
125
+ Please do know that we really appreciate and value your time and work. We love you, really.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ danger.import_dangerfile(gem: 'slack-ruby-danger')
data/Gemfile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ case ENV['DATABASE_ADAPTER']
6
+ when 'mongoid' then
7
+ gem 'kaminari-mongoid'
8
+ gem 'mongoid'
9
+ gem 'mongoid-scroll'
10
+ when 'activerecord' then
11
+ gem 'activerecord', '~> 5.0.0'
12
+ gem 'otr-activerecord', '~> 1.2.1'
13
+ gem 'virtus'
14
+ gem 'cursor_pagination' # rubocop:disable Bundler/OrderedGems
15
+ gem 'pg'
16
+ when nil
17
+ warn "Missing ENV['DATABASE_ADAPTER']."
18
+ else
19
+ warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}."
20
+ end
21
+
22
+ gemspec
23
+
24
+ group :development, :test do
25
+ gem 'bundler'
26
+ gem 'database_cleaner'
27
+ gem 'fabrication'
28
+ gem 'faker'
29
+ gem 'hyperclient'
30
+ gem 'rack-test'
31
+ gem 'rake'
32
+ gem 'rspec'
33
+ gem 'rubocop', '0.81.0'
34
+ gem 'vcr'
35
+ gem 'webmock'
36
+ end
37
+
38
+ group :test do
39
+ gem 'slack-ruby-danger', '~> 0.1.0', require: false
40
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Daniel Doubrovkine & Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,112 @@
1
+ Slack Ruby Bot Server Slack Extensions
2
+ ======================================
3
+
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
+ [![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
+
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.
8
+
9
+ ### Sample
10
+
11
+ See [slack-ruby/slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample) for a working sample.
12
+
13
+ ### Usage
14
+
15
+ #### Gemfile
16
+
17
+ Add 'slack-ruby-bot-server-events' to Gemfile.
18
+
19
+ ```ruby
20
+ gem 'slack-ruby-bot-server-events'
21
+ ```
22
+
23
+ #### Configure
24
+
25
+ ```ruby
26
+ SlackRubyBotServer::Events.configure do |config|
27
+ config.signing_secret = 'secret'
28
+ end
29
+ ```
30
+
31
+ The following settings are supported.
32
+
33
+ setting | description
34
+ ----------------------|------------------------------------------------------------------
35
+ signing_secret | Slack signing secret, defaults is `ENV['SLACK_SIGNING_SECRET']`.
36
+ signature_expires_in | Signature expiration window in seconds, default is `300`.
37
+
38
+ Get the signing secret from [your app's](https://api.slack.com/apps) _Basic Information_ settings.
39
+
40
+ #### Implement Callbacks
41
+
42
+ This library supports events, actions and commands. When implementing multiple callbacks for each type, the response from the first callback to return a non `nil` value will be used and no further callbacks will be invoked. Callbacks receive subclasses of [SlackRubyBotServer::Events::Requests::Request](lib/slack-ruby-bot-server-events/requests/request.rb).
43
+
44
+ #### Events
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.
47
+
48
+ ```ruby
49
+ SlackRubyBotServer::Events.configure do |config|
50
+ config.on :event, ['event_callback', 'link_shared'] do |event|
51
+ event[:event][:links].each do |link|
52
+ Slack::Web::Client.new(token: '...').chat_unfurl(
53
+ channel: event[:event][:channel],
54
+ ts: event[:event][:message_ts],
55
+ unfurls: {
56
+ link[:url] => { text: 'Unfurled URL.' }
57
+ }.to_json
58
+ )
59
+ end
60
+
61
+ true # return true to avoid invoking further callbacks
62
+ end
63
+
64
+ config.on :event, 'event_callback' do |event|
65
+ raise "I don't know how to handle #{event[:event][:type]}."
66
+ end
67
+
68
+ config.on :event do |event|
69
+ raise "I don't know how to handle #{event[:type]}."
70
+ end
71
+ end
72
+ ```
73
+
74
+
75
+ #### Actions
76
+
77
+ Respond to [Interactive Message Buttons](https://api.slack.com/legacy/message-buttons) by implementing `SlackRubyBotServer::Events::Config#on :action`.
78
+
79
+ ```ruby
80
+ SlackRubyBotServer::Events.configure do |config|
81
+ config.on :action, 'action_id' do |action|
82
+ # action[:payload][:callback_id] is 'action_id'
83
+ { text: 'Success!' }
84
+ end
85
+
86
+ config.on :action do |action|
87
+ { text: "I don't know how to handle #{action[:payload][:callback_id]}." }
88
+ end
89
+ end
90
+ ```
91
+
92
+ #### Commands
93
+
94
+ Respond to [Slash Commands](https://api.slack.com/interactivity/slash-commands) by implementing `SlackRubyBotServer::Events::Config#on :command`.
95
+
96
+ ```ruby
97
+ SlackRubyBotServer::Events.configure do |config|
98
+ config.on :command, '/test' do
99
+ { text: 'Success!' }
100
+ end
101
+
102
+ config.on :command do |command|
103
+ { text: "I don't know how to handle #{command[:command]}." }
104
+ end
105
+ end
106
+ ```
107
+
108
+ ### Copyright & License
109
+
110
+ Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2020
111
+
112
+ [MIT License](LICENSE)
@@ -0,0 +1,61 @@
1
+ # Releasing Slack-Ruby-Bot-Server-Events
2
+
3
+ There're no hard rules about when to release slack-ruby-bot-server-events. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Release
6
+
7
+ Run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded in [Travis CI](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-events) for all supported platforms.
15
+
16
+ Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
17
+
18
+ ```
19
+ ### 0.2.2 (7/10/2015)
20
+ ```
21
+
22
+ Remove the line with "Your contribution here.", since there will be no more contributions to this release.
23
+
24
+ Commit your changes.
25
+
26
+ ```
27
+ git add CHANGELOG.md
28
+ git commit -m "Preparing for release, 0.2.2."
29
+ git push origin master
30
+ ```
31
+
32
+ Release.
33
+
34
+ ```
35
+ $ rake release
36
+
37
+ slack-ruby-bot-server-events 0.2.2 built to pkg/slack-ruby-bot-server-events-0.2.2.gem.
38
+ Tagged v0.2.2.
39
+ Pushed git commits and tags.
40
+ Pushed slack-ruby-bot-server-events 0.2.2 to rubygems.org.
41
+ ```
42
+
43
+ ### Prepare for the Next Version
44
+
45
+ Add the next release to [CHANGELOG.md](CHANGELOG.md).
46
+
47
+ ```
48
+ ### 0.2.3 (Next)
49
+
50
+ * Your contribution here.
51
+ ```
52
+
53
+ Increment the third version number in [lib/slack-ruby-bot-server-events/version.rb](lib/slack-ruby-bot-server-events/version.rb).
54
+
55
+ Commit your changes.
56
+
57
+ ```
58
+ git add CHANGELOG.md lib/slack-ruby-bot-server-events/version.rb
59
+ git commit -m "Preparing for next development iteration, 0.2.3."
60
+ git push origin master
61
+ ```
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV['DATABASE_ADAPTER']})})
11
+ end
12
+
13
+ require 'rubocop/rake_task'
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[rubocop spec]
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'slack-ruby-bot-server'
4
+
5
+ require_relative 'slack-ruby-bot-server-events/version'
6
+ require_relative 'slack-ruby-bot-server-events/config'
7
+ require_relative 'slack-ruby-bot-server-events/requests'
8
+ require_relative 'slack-ruby-bot-server-events/api'
9
+
10
+ require_relative 'slack-ruby-bot-server/api'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'api/endpoints'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'endpoints/slack'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'slack/actions_endpoint'
4
+ require_relative 'slack/commands_endpoint'
5
+ require_relative 'slack/events_endpoint'
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Api
6
+ module Endpoints
7
+ module Slack
8
+ class ActionsEndpoint < Grape::API
9
+ desc 'Respond to interactive slack buttons and actions.'
10
+ params do
11
+ requires :payload, type: JSON do
12
+ requires :token, type: String
13
+ requires :callback_id, type: String
14
+ optional :type, type: String
15
+ optional :trigger_id, type: String
16
+ optional :response_url, type: String
17
+ requires :channel, type: Hash do
18
+ requires :id, type: String
19
+ optional :name, type: String
20
+ end
21
+ requires :user, type: Hash do
22
+ requires :id, type: String
23
+ optional :name, type: String
24
+ end
25
+ requires :team, type: Hash do
26
+ requires :id, type: String
27
+ optional :domain, type: String
28
+ end
29
+ optional :actions, type: Array do
30
+ requires :value, type: String
31
+ end
32
+ optional :message, type: Hash do
33
+ requires :type, type: String
34
+ requires :user, type: String
35
+ requires :ts, type: String
36
+ requires :text, type: String
37
+ end
38
+ end
39
+ end
40
+ post '/action' do
41
+ action = SlackRubyBotServer::Events::Requests::Action.new(params, request)
42
+ callback_id = params[:payload][:callback_id]
43
+ SlackRubyBotServer::Events.config.run_callbacks(:action, callback_id, action) || body(false)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Api
6
+ module Endpoints
7
+ module Slack
8
+ class CommandsEndpoint < Grape::API
9
+ desc 'Respond to slash commands.'
10
+ params do
11
+ requires :command, type: String
12
+ requires :text, type: String
13
+ requires :token, type: String
14
+ requires :user_id, type: String
15
+ requires :channel_id, type: String
16
+ requires :channel_name, type: String
17
+ requires :team_id, type: String
18
+ end
19
+ post '/command' do
20
+ command = SlackRubyBotServer::Events::Requests::Command.new(params, request)
21
+ command_name = command[:command]
22
+ SlackRubyBotServer::Events.config.run_callbacks(:command, command_name, command) || body(false)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Api
6
+ module Endpoints
7
+ module Slack
8
+ class EventsEndpoint < Grape::API
9
+ desc 'Handle Slack events.'
10
+ params do
11
+ requires :token, type: String
12
+ requires :type, type: String
13
+ optional :challenge, type: String
14
+ end
15
+ post '/event' do
16
+ event = SlackRubyBotServer::Events::Requests::Event.new(params, request)
17
+ type = event[:type]
18
+ event_type = event[:event][:type] if event.key?(:event)
19
+ key = [type, event_type].compact
20
+ SlackRubyBotServer::Events.config.run_callbacks(:event, key, event) || body(false)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Config
6
+ extend self
7
+
8
+ ATTRIBUTES = %i[
9
+ signing_secret
10
+ signature_expires_in
11
+ callbacks
12
+ ].freeze
13
+
14
+ attr_accessor(*Config::ATTRIBUTES)
15
+
16
+ def reset!
17
+ self.callbacks = Hash.new { |h, k| h[k] = [] }
18
+ self.signing_secret = ENV['SLACK_SIGNING_SECRET']
19
+ self.signature_expires_in = 5 * 60
20
+
21
+ on :event, 'url_verification' do |event|
22
+ { challenge: event[:challenge] }
23
+ end
24
+ end
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
32
+ end
33
+
34
+ def run_callbacks(type, value, args)
35
+ callbacks = []
36
+
37
+ keys = ([type.to_s] + Array(value)).compact
38
+
39
+ # more specific callbacks first
40
+ while keys.any?
41
+ callbacks += self.callbacks[keys.join('/')]
42
+ keys.pop
43
+ end
44
+
45
+ return nil unless callbacks&.any?
46
+
47
+ callbacks.each do |c|
48
+ rc = c.call(args || value)
49
+ return rc if rc
50
+ end
51
+
52
+ nil
53
+ end
54
+ end
55
+
56
+ class << self
57
+ def configure
58
+ block_given? ? yield(Config) : Config
59
+ end
60
+
61
+ def config
62
+ Config
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ SlackRubyBotServer::Events::Config.reset!
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'requests/request'
4
+ require_relative 'requests/event'
5
+ require_relative 'requests/command'
6
+ require_relative 'requests/action'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Requests
6
+ class Action < Request
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Requests
6
+ class Command < Request
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Requests
6
+ class Event < Request
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ module Requests
6
+ class Request < ActiveSupport::HashWithIndifferentAccess
7
+ attr_reader :request
8
+
9
+ def initialize(params, request)
10
+ @request = request
11
+ super params
12
+ end
13
+
14
+ def logger
15
+ SlackRubyBotServer::Api::Middleware.logger
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Events
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'api/endpoints'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackRubyBotServer
4
+ module Api
5
+ module Endpoints
6
+ class RootEndpoint
7
+ namespace :slack do
8
+ format :json
9
+
10
+ before do
11
+ begin
12
+ ::Slack::Events::Request.new(
13
+ request,
14
+ signing_secret: SlackRubyBotServer::Events.config.signing_secret,
15
+ signature_expires_in: SlackRubyBotServer::Events.config.signature_expires_in
16
+ ).verify!
17
+ rescue ::Slack::Events::Request::TimestampExpired
18
+ error!('Invalid Signature', 403)
19
+ end
20
+ end
21
+
22
+ mount SlackRubyBotServer::Events::Api::Endpoints::Slack::CommandsEndpoint
23
+ mount SlackRubyBotServer::Events::Api::Endpoints::Slack::ActionsEndpoint
24
+ mount SlackRubyBotServer::Events::Api::Endpoints::Slack::EventsEndpoint
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'slack-ruby-bot-server-events/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'slack-ruby-bot-server-events'
9
+ spec.version = SlackRubyBotServer::Events::VERSION
10
+ spec.authors = ['Daniel Doubrovkine']
11
+ spec.email = ['dblock@dblock.org']
12
+
13
+ spec.summary = 'Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.'
14
+ spec.homepage = 'https://github.com/slack-ruby/slack-ruby-bot-server-events'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'slack-ruby-bot-server', '>= 0.12.0'
20
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack-ruby-bot-server-events
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Doubrovkine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-ruby-bot-server
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ description:
28
+ email:
29
+ - dblock@dblock.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - ".rubocop_todo.yml"
38
+ - ".travis.yml"
39
+ - CHANGELOG.md
40
+ - CONTRIBUTING.md
41
+ - Dangerfile
42
+ - Gemfile
43
+ - LICENSE
44
+ - README.md
45
+ - RELEASING.md
46
+ - Rakefile
47
+ - lib/slack-ruby-bot-server-events.rb
48
+ - lib/slack-ruby-bot-server-events/api.rb
49
+ - lib/slack-ruby-bot-server-events/api/endpoints.rb
50
+ - lib/slack-ruby-bot-server-events/api/endpoints/slack.rb
51
+ - lib/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint.rb
52
+ - lib/slack-ruby-bot-server-events/api/endpoints/slack/commands_endpoint.rb
53
+ - lib/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint.rb
54
+ - lib/slack-ruby-bot-server-events/config.rb
55
+ - lib/slack-ruby-bot-server-events/requests.rb
56
+ - lib/slack-ruby-bot-server-events/requests/action.rb
57
+ - lib/slack-ruby-bot-server-events/requests/command.rb
58
+ - lib/slack-ruby-bot-server-events/requests/event.rb
59
+ - lib/slack-ruby-bot-server-events/requests/request.rb
60
+ - lib/slack-ruby-bot-server-events/version.rb
61
+ - lib/slack-ruby-bot-server/api.rb
62
+ - lib/slack-ruby-bot-server/api/endpoints.rb
63
+ - slack-ruby-bot-server-events.gemspec
64
+ homepage: https://github.com/slack-ruby/slack-ruby-bot-server-events
65
+ licenses: []
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.1.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
86
+ test_files: []