slack_socket_mode_bot 0.9.0 → 0.9.1

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: ea84a2e36d8b349ef867322ad4e932703dc5fa7eea1397f693268977aecfb001
4
- data.tar.gz: 1802e47527f56357fa5a3d564f61f91a6a3f3741bb107227dad18be8beedb08f
3
+ metadata.gz: 47ada769275576b47617b518f5edfe68f9e868b5542bf54a6aff1b8c61cf7f12
4
+ data.tar.gz: d746a2d083f4b3aab6e249a564f83f36810c2c3db44f9e43531cb880a67ea905
5
5
  SHA512:
6
- metadata.gz: 4b5cbb57859b8f34a2d45c8869d2f197ef84f24d7554c12027e331a783edc510357dd6d7cd1b199db98870b17abb2a27e2ca1f70fc4fce0151fa82392db4456a
7
- data.tar.gz: e84f97c7a0dbe89e249315f5142b7c275de3b7cfb4f90127727d7d9e943f14c1eb493994a56554d8af22c7a2248e9e5a9c873a2a08e3f21bd7614265d5fa383b
6
+ metadata.gz: 2fccbca8913960ce106189139af617f904f02038cb15a4575e81a3a7dd02c8e95cd613d90527286f437a9d73cbc85aebdbea3096386580deaeb118ca72b666bf
7
+ data.tar.gz: d756bea2c709da78cde7ec431cb0fe58cf05c9e06d25523e20fc99f9f01e71765a0c4adf90882eef1fc1056c3bc1fecce2567ec97a91337517b25c117aaaaae8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Yusuke Endoh
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.
data/README.md CHANGED
@@ -94,6 +94,9 @@ Connects to Slack with Socket Mode.
94
94
  * `logger`: A Logger instance (optional)
95
95
  * block: Handles events received from Slack
96
96
 
97
+ Note: The block must return as soon as possible. Otherwise, the Slack server will re-send the event.
98
+ If you want to do a time-consuming process, it is recommended that you do it in a sub thread.
99
+
97
100
  ### `SlackSocketModeBot#call(method, data, token:)`
98
101
 
99
102
  Calls Slack's [Web API](https://api.slack.com/methods), such as [chat.postMessage](https://api.slack.com/methods/chat.postMessage).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SlackSocketModeBot
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.1"
5
5
  end
@@ -19,6 +19,7 @@ class SlackSocketModeBot
19
19
  @conns = []
20
20
  @debug = debug
21
21
  @logger = logger
22
+ @events = {}
22
23
  num_of_connections.times { add_connection(callback) } if app_token
23
24
  end
24
25
 
@@ -65,25 +66,42 @@ class SlackSocketModeBot
65
66
 
66
67
  if @logger
67
68
  @logger.debug("[ws:#{ ws.object_id }] slack message: #{ JSON.generate(json) }")
68
- msg = "slack #{ json[:type] }"
69
- payload_type = json.dig(:payload, :type)
70
- msg += " (#{ payload_type })" if payload_type
71
- @logger.info("[ws:#{ ws.object_id }] " + msg)
72
69
  end
73
70
 
74
71
  case json[:type]
75
72
  when "hello"
76
- @logger.info("[ws:#{ ws.object_id }] active connection count: #{ @conns.size }") if @logger
73
+ @logger.info("[ws:#{ ws.object_id }] hello (active connections: #{ @conns.size })") if @logger
77
74
  when "disconnect"
78
75
  ws.close
76
+ @logger.info("[ws:#{ ws.object_id }] disconnect (active connections: #{ @conns.size })") if @logger
79
77
  else
80
- response = { envelope_id: json[:envelope_id] }
81
- if json[:accepts_response_payload]
82
- response[:payload] = callback.call(json)
78
+ payload = json[:payload]
79
+ if @logger
80
+ msg = "[ws:#{ ws.object_id }] #{ json[:type] } [##{ json[:retry_attempt] + 1 }] (#{
81
+ {
82
+ event_id: payload[:event_id],
83
+ event_time: Time.at(payload[:event_time]).strftime("%FT%T"),
84
+ type: payload[:type],
85
+ }.map {|k, v| "#{ k }: #{ v }" }.join(", ")
86
+ })"
87
+ @logger.info(msg)
88
+ end
89
+ expired = Time.now.to_i - 600
90
+ @events.reject! {|_, timestamp| timestamp < expired }
91
+
92
+ if @events[json[:payload][:event_id]]
93
+ # ignore
83
94
  else
84
- callback.call(json)
95
+ @events[json[:payload][:event_id]] = json[:payload][:event_time]
96
+
97
+ response = { envelope_id: json[:envelope_id] }
98
+ if json[:accepts_response_payload]
99
+ response[:payload] = callback.call(json)
100
+ else
101
+ callback.call(json)
102
+ end
103
+ ws.send(JSON.generate(response))
85
104
  end
86
- ws.send(JSON.generate(response))
87
105
  end
88
106
  end
89
107
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_socket_mode_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Endoh
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-06-21 00:00:00.000000000 Z
10
+ date: 2024-06-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: websocket
@@ -29,6 +29,7 @@ executables: []
29
29
  extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
+ - LICENSE
32
33
  - README.md
33
34
  - Rakefile
34
35
  - lib/slack_socket_mode_bot.rb
@@ -36,7 +37,8 @@ files:
36
37
  - lib/slack_socket_mode_bot/version.rb
37
38
  - sig/slack_socket_mode.rbs
38
39
  homepage: https://github.com/mame/slack_socket_mode_bot
39
- licenses: []
40
+ licenses:
41
+ - MIT
40
42
  metadata:
41
43
  homepage_uri: https://github.com/mame/slack_socket_mode_bot
42
44
  source_code_uri: https://github.com/mame/slack_socket_mode_bot