slack_bot-events 0.1.0 → 0.2.0

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: 88a291f8028f19bacd30f4c7cd8fbcbb56fdfa3463dc916289fbf6f8447df94c
4
- data.tar.gz: 68aa571fdf8b0b682551621601e1cfc37128823584596aa99a9ef5130d996c6c
3
+ metadata.gz: e221d5ba2b7822f18b4079b73bc35005488510570b1c6bf1121b29ae3a38a85f
4
+ data.tar.gz: 7c6fd667337ad3eaefc080abac2d53295b6226c41570dcebc118eb321e218a0b
5
5
  SHA512:
6
- metadata.gz: 5488211f2ebbbdc4c5960fa03d49d859e41fce30432fb42438951ab90f6f9ccb1b410cae8fcec3dcbe86d4c2c17e5ea520eb2ec7f73eebf95192ef5092572463
7
- data.tar.gz: 34d761af5cbc44e718dd44cd5ed9612e7270bbbb7f92ea88df68aceab85e23352df83fecd3b8f227155cb3e03127354dcf7bc387a2339b057890f6aab245b2f8
6
+ metadata.gz: 9545811f097ea137483b27bfd4b93cfb9d64040487051fd9f906de4d67e09503768fa4341faad9eed36348edf644ad33be7f9109f3c5a9d5741d59fc9c8ca17b
7
+ data.tar.gz: 2afc096dd076de82f0f3443a7ac437be405f6b8613db994072a94cb05623797cc631b178e163c756ddfbd7f2c29e337bbb42db5fe71e42aed0b5b148c3bfd5ea
@@ -22,7 +22,17 @@ module SlackBot
22
22
  case parsed_data["type"]
23
23
  when "events_api"
24
24
  events_api(parsed_data)
25
- else "hello"
25
+ when "app_rate_limited"
26
+ # https://api.slack.com/apis/rate-limits#events
27
+ # Total allowed workspace events are 30,000 per hour
28
+ # This message type is received once you have gone beyond that
29
+ params = {
30
+ minute_rate_limited: parsed_data["minute_rate_limited"],
31
+ team_id: parsed_data["team_id"],
32
+ api_app_id: parsed_data["api_app_id"],
33
+ }
34
+ event_tracer("message:app_rate_limited", **params)
35
+ when "hello"
26
36
  params = {
27
37
  num_connections: parsed_data["num_connections"],
28
38
  debug_info_host: parsed_data["debug_info"]["host"],
@@ -57,7 +67,7 @@ module SlackBot
57
67
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
58
68
  yield
59
69
  elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
60
- Events.logger.info "[Event completed] [#{elapsed_time.round(2)}s] #{type} #{stringify}"
70
+ Events.logger.info "[Event completed] [#{elapsed_time.round(3)}s] #{type} #{stringify}"
61
71
  end
62
72
  end
63
73
 
@@ -0,0 +1,23 @@
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 BotProfile < JsonSchematize::Generator
11
+ schema_default option: :dig_type, value: :string
12
+
13
+ add_field name: :id, type: String
14
+ add_field name: :app_id, type: String
15
+ add_field name: :name, type: String
16
+ add_field name: :deleted, type: JsonSchematize::Boolean
17
+ add_field name: :updated, type: String
18
+ add_field name: :team_id, type: String
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,6 +4,7 @@ require "json_schematize"
4
4
  require "json_schematize/generator"
5
5
 
6
6
  require "slack_bot/events/schemas/type/block"
7
+ require "slack_bot/events/schemas/type/bot_profile"
7
8
 
8
9
  module SlackBot
9
10
  module Events
@@ -20,6 +21,7 @@ module SlackBot
20
21
  add_field name: :team, type: String
21
22
 
22
23
  add_field name: :blocks, type: SlackBot::Events::Schemas::Type::Block, array_of_types: true
24
+ add_field name: :bot_profile, type: SlackBot::Events::Schemas::Type::BotProfile, required: false
23
25
 
24
26
  add_field name: :thread_ts, type: String, required: false
25
27
  add_field name: :parent_user_id, type: String, required: false
@@ -28,6 +30,14 @@ module SlackBot
28
30
  add_field name: :event_ts, type: String
29
31
  add_field name: :channel_type, type: String
30
32
 
33
+ def made_from_user?
34
+ bot_profile.nil? || JsonSchematize::EmptyValue === bot_profile
35
+ end
36
+
37
+ def made_from_bot?
38
+ !made_from_user?
39
+ end
40
+
31
41
  def tldr
32
42
  "type: #{type}; channel:#{channel}; raw_text:#{text}"
33
43
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SlackBot
4
4
  module Events
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Taylor
@@ -139,6 +139,7 @@ files:
139
139
  - lib/slack_bot/events/schemas/socket_payload.rb
140
140
  - lib/slack_bot/events/schemas/type/base.rb
141
141
  - lib/slack_bot/events/schemas/type/block.rb
142
+ - lib/slack_bot/events/schemas/type/bot_profile.rb
142
143
  - lib/slack_bot/events/schemas/type/element.rb
143
144
  - lib/slack_bot/events/schemas/type/item.rb
144
145
  - lib/slack_bot/events/schemas/type/message.rb