slack_bot-events 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 653594899c76b05d93054ceb20520d84a487a38451ecee7d561ab5b9e6590bf7
4
- data.tar.gz: 3f722375d06dce4ca2a3f4151ed221948b9e1d5e6d87842cf966ff067c54c31b
3
+ metadata.gz: 26e9e0a0edd93455cbc0cff5043f9a5e9a93a1bdb1a6ace9107df71cabd01856
4
+ data.tar.gz: 4eb9d15cc14f868f8e1f8bab0ccaaca876e256899a84d2b53cf5939df2496205
5
5
  SHA512:
6
- metadata.gz: eb0fb66fded40a580f042bd45e9ba139cf3753d2960461265d07394a5c182a35c9f35d33105e7ca5536b6e279c44335baf6b8ba645e531186ffbf3c4d9790dcc
7
- data.tar.gz: 02f478db61cabfce5f8e66b7303f47f9ed548d08dafded39d364e579f68ebf448f17ddf851e9717bfea0e755ab41e0821d450ab4b4e3353823a3b161e9ad0dea
6
+ metadata.gz: 44891a0644cd45f3b8c22a8256f48e509933b7a35a4504f9ac046d8b761fcd5a8bee09d2ecefa89d85616953e7a70e18b7fc84a1a5435a97f4d5dc4eb2fbcef2
7
+ data.tar.gz: 8af558314cab90d174ac1555f590eaeaab3bd87530928da99eea571486c962ef2926f41d82ff030107fc4ad4d615a7835030579b5497970bfd65a3653ec8991d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack_bot-events (0.4.0)
4
+ slack_bot-events (0.4.2)
5
5
  class_composer (~> 1.0)
6
6
  faraday
7
7
  faye-websocket
@@ -20,7 +20,7 @@ module SlackBot
20
20
  process_message(socket_event: socket_event) do |listener:, parsed_data:, schema: nil|
21
21
  case parsed_data["type"]
22
22
  when "events_api"
23
- events_api(handler: listener[:handler], schema: schema, parsed_data: parsed_data)
23
+ events_api(handler: listener&.dig(:handler), schema: schema, parsed_data: parsed_data)
24
24
  end
25
25
  end
26
26
  end
@@ -52,7 +52,7 @@ module SlackBot
52
52
  end
53
53
 
54
54
  def events_api(handler:, schema:, parsed_data:)
55
- return if listener.nil?
55
+ return if handler.nil?
56
56
 
57
57
  Events.logger.info { schema.tldr } if Events.config.print_tldr
58
58
 
@@ -15,11 +15,7 @@ module SlackBot
15
15
  :on_receive,
16
16
  ]
17
17
 
18
- add_composer :client_id, allowed: String, default: ENV["SLACK_CLIENT_ID"]
19
- add_composer :client_secret, allowed: String, default: ENV["SLACK_CLIENT_SECRET"]
20
- add_composer :client_signing_secret, allowed: String, default: ENV["SLACK_SIGNING_SECRET"]
21
18
  add_composer :client_socket_token, allowed: String, default: ENV["SLACK_SOCKET_TOKEN"]
22
- add_composer :client_verification_token, allowed: String, default: ENV["SLACK_VERIFICATION_TOKEN"]
23
19
  add_composer :print_tldr, allowed: [true.class, false.class], default: true
24
20
  add_composer :message_middleware, allowed: Middleware::Chain, default: Middleware::Chain.new(type: :message)
25
21
  add_composer :open_middleware, allowed: Middleware::Chain, default: Middleware::Chain.new(type: :open)
@@ -19,9 +19,12 @@ module SlackBot
19
19
  attr_reader :type
20
20
 
21
21
  DEFAULT_ENTRIES = {
22
- message: [Middleware::EventTracer, Middleware::MessageHandler],
23
- open: [Middleware::EventTracer],
24
- close: [Middleware::EventTracer],
22
+ message: {
23
+ base: [Middleware::EventTracer, Middleware::MessageHandler],
24
+ immutable: [Middleware::MessageHandler]
25
+ },
26
+ open: { base: [Middleware::EventTracer] },
27
+ close: { base: [Middleware::EventTracer] },
25
28
  }
26
29
 
27
30
  def initialize(type:)
@@ -29,7 +32,7 @@ module SlackBot
29
32
  end
30
33
 
31
34
  def self.default_entry(type)
32
- DEFAULT_ENTRIES[type].map { Entry.new(_1) }
35
+ DEFAULT_ENTRIES[type][:base].map { Entry.new(_1) }
33
36
  end
34
37
 
35
38
  def entries
@@ -37,7 +40,7 @@ module SlackBot
37
40
  end
38
41
 
39
42
  def remove(klass)
40
- raise ArgumentError, "Unable to remove default Middleware #{klass}" if self.class.default_entry.map(:klass).include?(klass)
43
+ raise ArgumentError, "Unable to remove default Middleware #{klass}" if Array(DEFAULT_ENTRIES[@type][:immutable]).include?(klass)
41
44
 
42
45
  entries.delete_if { |entry| entry.klass == klass }
43
46
  end
@@ -11,21 +11,23 @@ module SlackBot
11
11
  when :close
12
12
  additional_info = "code: #{socket_event.code} reason:#{socket_event.reason}"
13
13
  when :message
14
- accurate_type = parsed_data.dig("payload","event","subtype") || parsed_data.dig("payload","event","type")
15
- p_type = [
16
- parsed_data.dig("type"),
17
- accurate_type
18
- ].compact.join(":")
19
- case p_type
14
+
15
+ case parsed_data.dig("type")
20
16
  when "app_rate_limited"
21
17
  # https://api.slack.com/apis/rate-limits#events
22
18
  # Total allowed workspace events are 30,000 per hour
23
19
  # This message type is received once you have gone beyond that
24
- temp_type += ":#{p_type}"
20
+ temp_type += ":#{parsed_data.dig("type")}"
25
21
  additional_info = "minute_rate_limited:#{parsed_data["minute_rate_limited"]} " \
26
22
  "team_id:#{parsed_data["team_id"]} " \
27
23
  "api_app_id:#{parsed_data["api_app_id"]}"
28
24
  else
25
+ accurate_type = parsed_data.dig("payload","event","subtype") || parsed_data.dig("payload","event","type")
26
+ p_type = [
27
+ parsed_data.dig("type"),
28
+ accurate_type
29
+ ].compact.join(":")
30
+
29
31
  # Expected other types are `events_api` and `hello`
30
32
  temp_type += ":#{p_type}"
31
33
  end
@@ -17,8 +17,6 @@ module SlackBot
17
17
  acknowledge!(websocket: websocket, schema: schema)
18
18
  end
19
19
  rescue StandardError => error
20
- puts error.message
21
- puts error.backtrace
22
20
  Events.logger.error do
23
21
  "#{listener[:handler]} returned #{error.class} => #{error.message}. #{error.backtrace[0...10]}"
24
22
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SlackBot
4
4
  module Events
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.2"
6
6
  end
7
7
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pry"
4
-
5
3
  require "slack_bot/events/configuration"
6
4
  require "slack_bot/events/client"
7
5
  require "slack_bot/events/middleware/chain"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_bot-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Taylor