slack_bot-events 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +29 -0
- data/.github/CODEOWNERS +1 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Dockerfile +13 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +75 -0
- data/Makefile +18 -0
- data/README.md +0 -0
- data/Rakefile +8 -0
- data/bin/console +11 -0
- data/bin/setup +10 -0
- data/bin/start +9 -0
- data/docker-compose.yml +14 -0
- data/lib/slack_bot/events/client.rb +64 -0
- data/lib/slack_bot/events/configuration.rb +33 -0
- data/lib/slack_bot/events/schemas/authorization.rb +20 -0
- data/lib/slack_bot/events/schemas/data_payload.rb +62 -0
- data/lib/slack_bot/events/schemas/socket_payload.rb +25 -0
- data/lib/slack_bot/events/schemas/type/base.rb +34 -0
- data/lib/slack_bot/events/schemas/type/block.rb +22 -0
- data/lib/slack_bot/events/schemas/type/element.rb +22 -0
- data/lib/slack_bot/events/schemas/type/item.rb +20 -0
- data/lib/slack_bot/events/schemas/type/message.rb +35 -0
- data/lib/slack_bot/events/schemas/type/reaction_modified.rb +33 -0
- data/lib/slack_bot/events/version.rb +7 -0
- data/lib/slack_bot/events.rb +40 -0
- data/slack_bot-events.gemspec +47 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 672fb67f9f0c21233f2dd8b1033f2be26532f6a619922af541cdec7645db4005
|
4
|
+
data.tar.gz: 8b7a3ec2b87ae3c881a59638c9b3acfd4dcb03453a125288d4894a9aa681d94f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdc46b80e5696c237ea14f087d549059fc7cbcc207fe604858be99298a09fd5b8b19b2b9785be75151ac834f296ad4f3c5b85c8d19aacbbd3eef018c8edda25b
|
7
|
+
data.tar.gz: 232a0dd741b28bed0a63c721fc635b3dee1ec3434b31c886726285beaa5f006ebefecf0e0c6148a3d601dec2e41d8396eedeaabff6f24f29ee83743e306b7b6e
|
@@ -0,0 +1,29 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
orbs:
|
4
|
+
ruby: circleci/ruby@1.0
|
5
|
+
node: circleci/node@2
|
6
|
+
cst: cst/framework@1
|
7
|
+
|
8
|
+
workflows:
|
9
|
+
version: 2
|
10
|
+
yeet-le-jobs:
|
11
|
+
jobs:
|
12
|
+
- cst/enforce-gem-version-bump
|
13
|
+
- cst/rspec-ruby:
|
14
|
+
rspec-system-args: "SIMPLE_COV_RUN=true"
|
15
|
+
cc-report-collect-ruby: "3.2.3"
|
16
|
+
matrix:
|
17
|
+
parameters:
|
18
|
+
ruby-version: ["3.2.3" , "3.2"]
|
19
|
+
alias: required-matrix-tests
|
20
|
+
name: test-ruby<< matrix.ruby-version >>
|
21
|
+
- cst/publish-gem:
|
22
|
+
publish-git: true
|
23
|
+
publish-default-gem: true
|
24
|
+
requires:
|
25
|
+
- required-matrix-tests
|
26
|
+
filters:
|
27
|
+
branches:
|
28
|
+
only:
|
29
|
+
- main
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @matttaylor
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
.DS_Store
|
10
|
+
.bash_history
|
11
|
+
.pry_history
|
12
|
+
.byebug_history
|
13
|
+
.idea
|
14
|
+
|
15
|
+
# rspec failure tracking
|
16
|
+
.rspec_status
|
17
|
+
|
18
|
+
# generated gems
|
19
|
+
*.gem
|
20
|
+
.env
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.3
|
data/Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
FROM ruby:3.2.3
|
2
|
+
|
3
|
+
WORKDIR /gem
|
4
|
+
COPY Gemfile /gem/Gemfile
|
5
|
+
|
6
|
+
COPY slack_bot-events.gemspec /gem/slack_bot-events.gemspec
|
7
|
+
COPY lib/slack_bot/events/version.rb /gem/lib/slack_bot/events/version.rb
|
8
|
+
|
9
|
+
RUN gem update --system
|
10
|
+
RUN gem install bundler
|
11
|
+
|
12
|
+
COPY . /gem
|
13
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies incl. version constraints in the gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'rspec_junit_formatter'
|
11
|
+
gem 'simplecov', require: false, group: :test
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack_bot-events (0.0.1)
|
5
|
+
class_composer (~> 1.0)
|
6
|
+
faraday
|
7
|
+
faye-websocket
|
8
|
+
json_schematize
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
byebug (11.1.3)
|
14
|
+
class_composer (1.0.2)
|
15
|
+
coderay (1.1.3)
|
16
|
+
diff-lcs (1.5.1)
|
17
|
+
docile (1.4.0)
|
18
|
+
eventmachine (1.2.7)
|
19
|
+
faraday (2.9.1)
|
20
|
+
faraday-net_http (>= 2.0, < 3.2)
|
21
|
+
faraday-net_http (3.1.0)
|
22
|
+
net-http
|
23
|
+
faye-websocket (0.11.3)
|
24
|
+
eventmachine (>= 0.12.0)
|
25
|
+
websocket-driver (>= 0.5.1)
|
26
|
+
json (2.7.2)
|
27
|
+
json_schematize (0.9.0)
|
28
|
+
class_composer (~> 1.0)
|
29
|
+
method_source (1.1.0)
|
30
|
+
net-http (0.4.1)
|
31
|
+
uri
|
32
|
+
pry (0.14.2)
|
33
|
+
coderay (~> 1.1)
|
34
|
+
method_source (~> 1.0)
|
35
|
+
pry-byebug (3.10.1)
|
36
|
+
byebug (~> 11.0)
|
37
|
+
pry (>= 0.13, < 0.15)
|
38
|
+
rspec (3.13.0)
|
39
|
+
rspec-core (~> 3.13.0)
|
40
|
+
rspec-expectations (~> 3.13.0)
|
41
|
+
rspec-mocks (~> 3.13.0)
|
42
|
+
rspec-core (3.13.0)
|
43
|
+
rspec-support (~> 3.13.0)
|
44
|
+
rspec-expectations (3.13.1)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.13.0)
|
47
|
+
rspec-mocks (3.13.1)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-support (3.13.1)
|
51
|
+
rspec_junit_formatter (0.6.0)
|
52
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
53
|
+
simplecov (0.17.1)
|
54
|
+
docile (~> 1.1)
|
55
|
+
json (>= 1.8, < 3)
|
56
|
+
simplecov-html (~> 0.10.0)
|
57
|
+
simplecov-html (0.10.2)
|
58
|
+
uri (0.13.0)
|
59
|
+
websocket-driver (0.7.6)
|
60
|
+
websocket-extensions (>= 0.1.0)
|
61
|
+
websocket-extensions (0.1.5)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
aarch64-linux
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
pry-byebug
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rspec_junit_formatter
|
71
|
+
simplecov
|
72
|
+
slack_bot-events!
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.5.13
|
data/Makefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
.PHONY: help bash build bundle rspec rubocop rubocop-todo
|
2
|
+
|
3
|
+
GEM=slack_bot-events
|
4
|
+
DC_FILE?=docker-compose.yml
|
5
|
+
FILES?=.
|
6
|
+
|
7
|
+
help: #: Show help topics
|
8
|
+
@grep "#:" Makefile | grep -v "@grep" | sed "s/.*:\([A-Za-z_ -]*\):.*#\(.*\)/$$(tput setaf 3)\1$$(tput sgr0)\2/g" | sort
|
9
|
+
|
10
|
+
bash: #: Get a bash prompt on your service container
|
11
|
+
@touch .bash_history
|
12
|
+
docker-compose -f $(DC_FILE) run $(GEM) bash
|
13
|
+
|
14
|
+
build: #: Build the containers that we'll need
|
15
|
+
docker-compose -f $(DC_FILE) build --pull
|
16
|
+
|
17
|
+
rspec: #: Run RSPEC, set TEST_FILE to run a specific file
|
18
|
+
docker-compose -f $(DC_FILE) run --rm -e RAILS_ENV=test $(GEM) bundle exec rspec --fail-fast $(FILES)
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/bin/start
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "eventmachine"
|
4
|
+
require "faraday"
|
5
|
+
require "faye/websocket"
|
6
|
+
require "pry"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
class Client
|
11
|
+
BASE_API = "https://slack.com/api"
|
12
|
+
|
13
|
+
def start!
|
14
|
+
EM.run do
|
15
|
+
websocket.on :open do |event|
|
16
|
+
p [:open]
|
17
|
+
end
|
18
|
+
|
19
|
+
websocket.on :message do |event|
|
20
|
+
parsed_data = JSON.parse(event.data)
|
21
|
+
if parsed_data["type"] == "events_api"
|
22
|
+
puts parsed_data.to_json
|
23
|
+
item = SlackBot::Events::Schemas::SocketPayload.new(parsed_data)
|
24
|
+
s = {
|
25
|
+
type: item.payload.event.type,
|
26
|
+
tldr: item.payload.event.tldr,
|
27
|
+
}
|
28
|
+
puts s
|
29
|
+
websocket.send("#{{ envelope_id: item.envelope_id }.to_json}")
|
30
|
+
else
|
31
|
+
puts event.data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
websocket.on :close do |event|
|
36
|
+
p [:close, event.code, event.reason]
|
37
|
+
@websocket = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def websocket
|
43
|
+
@websocket ||= Faye::WebSocket::Client.new(socket_endpoint)
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: Error handling here
|
47
|
+
def socket_endpoint
|
48
|
+
result = faraday_client.post("apps.connections.open")
|
49
|
+
json_body = JSON.parse(result.body)
|
50
|
+
json_body["url"]
|
51
|
+
end
|
52
|
+
|
53
|
+
def faraday_client
|
54
|
+
@faraday_client ||= Faraday.new(url: "https://slack.com/api", headers: faraday_headers)
|
55
|
+
end
|
56
|
+
|
57
|
+
def faraday_headers
|
58
|
+
{
|
59
|
+
'Authorization' => "Bearer #{SlackBot::Events.config.client_socket_token}"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "class_composer"
|
4
|
+
|
5
|
+
module SlackBot
|
6
|
+
module Events
|
7
|
+
class Configuration
|
8
|
+
include ClassComposer::Generator
|
9
|
+
add_composer :client_id, allowed: String, default: ENV["SLACK_CLIENT_ID"]
|
10
|
+
add_composer :client_secret, allowed: String, default: ENV["SLACK_CLIENT_SECRET"]
|
11
|
+
add_composer :client_signing_secret, allowed: String, default: ENV["SLACK_SIGNING_SECRET"]
|
12
|
+
add_composer :client_socket_token, allowed: String, default: ENV["SLACK_SOCKET_TOKEN"]
|
13
|
+
add_composer :client_verification_token, allowed: String, default: ENV["SLACK_VERIFICATION_TOKEN"]
|
14
|
+
|
15
|
+
def register_listener(name:, handler:)
|
16
|
+
@listeners ||= {}
|
17
|
+
|
18
|
+
if @listeners.has_key(name.to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
@listeners[name] = handler
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove_listener(name:)
|
27
|
+
@listeners ||= {}
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
module SlackBot
|
7
|
+
module Events
|
8
|
+
module Schemas
|
9
|
+
class Authorization < JsonSchematize::Generator
|
10
|
+
schema_default option: :dig_type, value: :string
|
11
|
+
|
12
|
+
add_field name: :enterprise_id, type: String, required: false
|
13
|
+
add_field name: :team_id, type: String
|
14
|
+
add_field name: :user_id, type: String
|
15
|
+
add_field name: :is_bot, type: JsonSchematize::Boolean
|
16
|
+
add_field name: :is_enterprise_install, type: JsonSchematize::Boolean
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/authorization"
|
7
|
+
require "slack_bot/events/schemas/type/base"
|
8
|
+
require "slack_bot/events/schemas/type/reaction_modified"
|
9
|
+
require "slack_bot/events/schemas/type/message"
|
10
|
+
|
11
|
+
module SlackBot
|
12
|
+
module Events
|
13
|
+
module Schemas
|
14
|
+
class DataPayload < JsonSchematize::Generator
|
15
|
+
schema_default option: :dig_type, value: :string
|
16
|
+
|
17
|
+
ALLOWED_EVENT_TYPES = [
|
18
|
+
SlackBot::Events::Schemas::Type::ReactionModified,
|
19
|
+
SlackBot::Events::Schemas::Type::Message,
|
20
|
+
SlackBot::Events::Schemas::Type::Base,
|
21
|
+
]
|
22
|
+
|
23
|
+
add_field name: :token, type: String
|
24
|
+
add_field name: :team_id, type: String
|
25
|
+
add_field name: :context_team_id, type: String, required: false
|
26
|
+
add_field name: :api_app_id, type: String, required: false
|
27
|
+
|
28
|
+
add_field name: :event, type: ALLOWED_EVENT_TYPES.first, types: ALLOWED_EVENT_TYPES, converter: ->(data) { DataPayload.event_type(data) }
|
29
|
+
|
30
|
+
add_field name: :type, type: String, required: false
|
31
|
+
add_field name: :event_id, type: String, required: false
|
32
|
+
add_field name: :event_time, type: Integer
|
33
|
+
|
34
|
+
add_field name: :authorizations, type: SlackBot::Events::Schemas::Authorization, array_of_types: true
|
35
|
+
|
36
|
+
add_field name: :is_ext_shared_channel, type: JsonSchematize::Boolean
|
37
|
+
add_field name: :event_context, type: String
|
38
|
+
|
39
|
+
def self.event_type(payload)
|
40
|
+
case payload["type"]
|
41
|
+
when "reaction_removed", "reaction_added"
|
42
|
+
SlackBot::Events::Schemas::Type::ReactionModified.new(payload)
|
43
|
+
when "message"
|
44
|
+
case payload["subtype"]
|
45
|
+
when nil
|
46
|
+
SlackBot::Events::Schemas::Type::Message.new(payload)
|
47
|
+
when "message_changed", "message_deleted"
|
48
|
+
SlackBot::Events::Schemas::Type::Base.new(payload.merge("tldr" => "subtype: #{payload["subtype"]}"))
|
49
|
+
else
|
50
|
+
# messages that were changed can be considered, but not at this time
|
51
|
+
SlackBot::Events::Schemas::Type::Base.new(payload)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
# When the event type does not exist yet; dont fret, give it the bare bones base objet that delegates
|
55
|
+
SlackBot::Events::Schemas::Type::Base.new(payload)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/data_payload"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
module Schemas
|
11
|
+
class SocketPayload < JsonSchematize::Generator
|
12
|
+
schema_default option: :dig_type, value: :string
|
13
|
+
|
14
|
+
add_field name: :envelope_id, type: String
|
15
|
+
|
16
|
+
add_field name: :payload, type: SlackBot::Events::Schemas::DataPayload
|
17
|
+
|
18
|
+
add_field name: :type, type: String
|
19
|
+
add_field name: :accepts_response_payload, type: JsonSchematize::Boolean
|
20
|
+
add_field name: :retry_attempt, type: Integer
|
21
|
+
add_field name: :retry_reason, type: String
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
module SlackBot
|
7
|
+
module Events
|
8
|
+
module Schemas
|
9
|
+
module Type
|
10
|
+
class Base < JsonSchematize::Generator
|
11
|
+
schema_default option: :dig_type, value: :string
|
12
|
+
|
13
|
+
add_field name: :tldr, type: String, required: false
|
14
|
+
|
15
|
+
def tldr
|
16
|
+
if @tldr
|
17
|
+
"type: #{type}; #{@tldr}"
|
18
|
+
else
|
19
|
+
"type: #{type}; unknown;"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(m, *args, &block)
|
24
|
+
if __raw_params.has_key?(m.to_s)
|
25
|
+
return __raw_params[m.to_s]
|
26
|
+
end
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/type/element"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
module Schemas
|
11
|
+
module Type
|
12
|
+
class Block < JsonSchematize::Generator
|
13
|
+
schema_default option: :dig_type, value: :string
|
14
|
+
|
15
|
+
add_field name: :type, type: String
|
16
|
+
add_field name: :block_id, type: String
|
17
|
+
add_field name: :elements, type: SlackBot::Events::Schemas::Type::Element, array_of_types: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/type/item"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
module Schemas
|
11
|
+
module Type
|
12
|
+
class Element < JsonSchematize::Generator
|
13
|
+
schema_default option: :dig_type, value: :string
|
14
|
+
|
15
|
+
add_field name: :type, type: String
|
16
|
+
add_field name: :elements, type: SlackBot::Events::Schemas::Type::Element, array_of_types: true, required: false
|
17
|
+
add_field name: :text, type: String, required: false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
module SlackBot
|
7
|
+
module Events
|
8
|
+
module Schemas
|
9
|
+
module Type
|
10
|
+
class Item < JsonSchematize::Generator
|
11
|
+
schema_default option: :dig_type, value: :string
|
12
|
+
|
13
|
+
add_field name: :type, type: String
|
14
|
+
add_field name: :channel, type: String
|
15
|
+
add_field name: :ts, type: String
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/type/block"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
module Schemas
|
11
|
+
module Type
|
12
|
+
class Message < JsonSchematize::Generator
|
13
|
+
schema_default option: :dig_type, value: :string
|
14
|
+
|
15
|
+
add_field name: :type, type: String
|
16
|
+
add_field name: :user, type: String
|
17
|
+
add_field name: :ts, type: String
|
18
|
+
add_field name: :client_msg_id, type: String
|
19
|
+
add_field name: :text, type: String
|
20
|
+
add_field name: :team, type: String
|
21
|
+
|
22
|
+
add_field name: :blocks, type: SlackBot::Events::Schemas::Type::Block, array_of_types: true
|
23
|
+
|
24
|
+
add_field name: :channel, type: String
|
25
|
+
add_field name: :event_ts, type: String
|
26
|
+
add_field name: :channel_type, type: String
|
27
|
+
|
28
|
+
def tldr
|
29
|
+
"type: #{type}; channel:#{channel}; raw_text:#{text}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json_schematize"
|
4
|
+
require "json_schematize/generator"
|
5
|
+
|
6
|
+
require "slack_bot/events/schemas/type/item"
|
7
|
+
|
8
|
+
module SlackBot
|
9
|
+
module Events
|
10
|
+
module Schemas
|
11
|
+
module Type
|
12
|
+
class ReactionModified < JsonSchematize::Generator
|
13
|
+
schema_default option: :dig_type, value: :string
|
14
|
+
|
15
|
+
add_field name: :type, type: String
|
16
|
+
add_field name: :user, type: String
|
17
|
+
add_field name: :reaction, type: String
|
18
|
+
add_field name: :item, type: SlackBot::Events::Schemas::Type::Item
|
19
|
+
add_field name: :item_user, type: String
|
20
|
+
add_field name: :event_ts, type: String
|
21
|
+
|
22
|
+
def channel
|
23
|
+
item.channel
|
24
|
+
end
|
25
|
+
|
26
|
+
def tldr
|
27
|
+
"type: #{type}; channel:#{channel}; reaction:#{reaction}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "slack_bot/events/configuration"
|
4
|
+
require "slack_bot/events/client"
|
5
|
+
require "slack_bot/events/schemas/socket_payload"
|
6
|
+
|
7
|
+
module SlackBot
|
8
|
+
module Events
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield configuration if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= SlackBot::Events::Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration=(object)
|
24
|
+
if SlackBot::Events::Configuration === obj
|
25
|
+
@configuration = object
|
26
|
+
return @configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
raise Error, "Expected configuration to be a SlackBot::Events::Configuration"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.register_listener(name:, handler:)
|
33
|
+
config.register_listener(name: name, handler: handler)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.remove_listener(name:)
|
37
|
+
config.remove_listener(name: name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
require "slack_bot/events/version"
|
6
|
+
circle_ci_build = ENV['CIRCLECI'] == 'true'
|
7
|
+
pre_release_tag = ENV["CIRCLE_TAG"]&.match?(/^pre-.*/)
|
8
|
+
gets_pre_release_version = circle_ci_build && pre_release_tag
|
9
|
+
|
10
|
+
patch_level = gets_pre_release_version ? ".99.pre.#{ENV.fetch('CIRCLE_BUILD_NUM', '')}" : ""
|
11
|
+
|
12
|
+
Gem::Specification.new do |spec|
|
13
|
+
spec.name = "slack_bot-events"
|
14
|
+
spec.version = SlackBot::Events::VERSION + patch_level
|
15
|
+
spec.authors = ["Matt Taylor"]
|
16
|
+
spec.email = ["mattius.taylor@gmail.com"]
|
17
|
+
|
18
|
+
spec.summary = "Slack Events API is here! Receive events without making a public endpoint. This Gem taps into the Events Websocket Architecture"
|
19
|
+
spec.description = "Describe the gem here"
|
20
|
+
spec.homepage = "https://github.com/matt-taylor/slack_bot-events"
|
21
|
+
|
22
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.2")
|
23
|
+
|
24
|
+
spec.metadata = {
|
25
|
+
"github_repo" => spec.homepage,
|
26
|
+
"homepage_uri" => spec.homepage,
|
27
|
+
"source_code_uri" => spec.homepage,
|
28
|
+
}
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
33
|
+
%x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_dependency "faraday"
|
40
|
+
spec.add_dependency "json_schematize"
|
41
|
+
spec.add_dependency "class_composer", "~> 1.0"
|
42
|
+
spec.add_dependency "faye-websocket"
|
43
|
+
|
44
|
+
spec.add_development_dependency "pry-byebug"
|
45
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
46
|
+
spec.add_development_dependency "simplecov"
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack_bot-events
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Taylor
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json_schematize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: class_composer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faye-websocket
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Describe the gem here
|
112
|
+
email:
|
113
|
+
- mattius.taylor@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".circleci/config.yml"
|
119
|
+
- ".github/CODEOWNERS"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".ruby-version"
|
123
|
+
- Dockerfile
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- Makefile
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- bin/start
|
132
|
+
- docker-compose.yml
|
133
|
+
- lib/slack_bot/events.rb
|
134
|
+
- lib/slack_bot/events/client.rb
|
135
|
+
- lib/slack_bot/events/configuration.rb
|
136
|
+
- lib/slack_bot/events/schemas/authorization.rb
|
137
|
+
- lib/slack_bot/events/schemas/data_payload.rb
|
138
|
+
- lib/slack_bot/events/schemas/socket_payload.rb
|
139
|
+
- lib/slack_bot/events/schemas/type/base.rb
|
140
|
+
- lib/slack_bot/events/schemas/type/block.rb
|
141
|
+
- lib/slack_bot/events/schemas/type/element.rb
|
142
|
+
- lib/slack_bot/events/schemas/type/item.rb
|
143
|
+
- lib/slack_bot/events/schemas/type/message.rb
|
144
|
+
- lib/slack_bot/events/schemas/type/reaction_modified.rb
|
145
|
+
- lib/slack_bot/events/version.rb
|
146
|
+
- slack_bot-events.gemspec
|
147
|
+
homepage: https://github.com/matt-taylor/slack_bot-events
|
148
|
+
licenses: []
|
149
|
+
metadata:
|
150
|
+
github_repo: https://github.com/matt-taylor/slack_bot-events
|
151
|
+
homepage_uri: https://github.com/matt-taylor/slack_bot-events
|
152
|
+
source_code_uri: https://github.com/matt-taylor/slack_bot-events
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '3.2'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubygems_version: 3.5.13
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Slack Events API is here! Receive events without making a public endpoint.
|
172
|
+
This Gem taps into the Events Websocket Architecture
|
173
|
+
test_files: []
|