slack-ruby-socket-mode-bot 0.1.0 → 0.3.0
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 +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +3 -0
- data/lib/bot/bot.rb +3 -4
- data/lib/transport/socket_mode_client.rb +8 -7
- data/lib/transport/websocket.rb +6 -0
- data/lib/version.rb +1 -1
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad18066a5a94aeb5eafd67bd14a67fe3dc0f6220b1efeefbe46b755671205247
|
4
|
+
data.tar.gz: e2aba7056fc4ffe2180a4f3a8941313457adb87e055bd344f97f88a6b64f912c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 044e1076b5f27b68912fc6af4b08ee27edc3e45207c838d2594abe0c9305187d183dfbd96f6d86fb9dd3f0982811cbc256a75bef2c7834ea379d9600a99f7061
|
7
|
+
data.tar.gz: cc151aee374edf16b835f4c8b0167db94d68426f93c5319b731928a0df511b0dc720d06974b41e5de93ba8e8f09febcd4cc3f3eeb52b1a1a5811f13cb40c323d
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# slack-ruby-socket-mode-bot
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/slack-ruby-socket-mode-bot)
|
4
|
+
[](https://github.com/guille/slack-socket-mode-bot/actions/workflows/main.yml)
|
5
|
+
|
3
6
|
This gem allows users to create Slack bots that respond to mentions. This gem only supports events-based [socket mode](https://api.slack.com/apis/socket-mode) bots. The gem allows registering a number of callbacks that will be executed if the registered regular expression matches the mention text.
|
4
7
|
|
5
8
|
See the [examples](https://github.com/guille/slack-socket-mode-bot/blob/master/examples) directory for some ideas on how to use the gem.
|
data/lib/bot/bot.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
module SlackSocketModeBot
|
4
4
|
MentionHandler = Data.define(:match_regex, :callback)
|
5
5
|
|
6
|
+
# Entry class for the gem, allows registering callbacks that will be triggered
|
7
|
+
# when the bot is mentioned
|
6
8
|
class Bot
|
7
9
|
def initialize(bot_token:, app_token:, logger: nil)
|
8
10
|
@bot_token = bot_token
|
@@ -27,10 +29,7 @@ module SlackSocketModeBot
|
|
27
29
|
private
|
28
30
|
|
29
31
|
def slack_web_client
|
30
|
-
client = Slack::Web::Client.new(
|
31
|
-
token: @bot_token,
|
32
|
-
logger: @logger
|
33
|
-
)
|
32
|
+
client = Slack::Web::Client.new(token: @bot_token)
|
34
33
|
auth_response = client.auth_test
|
35
34
|
|
36
35
|
raise auth_response unless auth_response[:ok]
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module SlackSocketModeBot
|
4
4
|
module Transport
|
5
|
+
# Client responsible for instantiating a WebSocket,
|
6
|
+
# as well as providing a connection URL and a callback method
|
5
7
|
class SocketModeClient
|
6
8
|
def initialize(app_token:, callback:, logger: nil)
|
7
9
|
@app_token = app_token
|
@@ -20,9 +22,11 @@ module SlackSocketModeBot
|
|
20
22
|
|
21
23
|
raise response unless response[:ok]
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
if ENV.fetch("ENVIRONMENT", "production").casecmp?("development")
|
26
|
+
"#{response[:url]}&debug_reconnects=true"
|
27
|
+
else
|
28
|
+
response[:url]
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
def callback(*args)
|
@@ -32,10 +36,7 @@ module SlackSocketModeBot
|
|
32
36
|
private
|
33
37
|
|
34
38
|
def slack_web_client
|
35
|
-
client = Slack::Web::Client.new(
|
36
|
-
token: @app_token,
|
37
|
-
logger: @logger
|
38
|
-
)
|
39
|
+
client = Slack::Web::Client.new(token: @app_token)
|
39
40
|
@slack_web_client ||= client
|
40
41
|
end
|
41
42
|
end
|
data/lib/transport/websocket.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
module SlackSocketModeBot
|
4
4
|
module Transport
|
5
|
+
# This class heavily leverages async and async-websocket to keep a connection alive to the
|
6
|
+
# URL provided by the client
|
7
|
+
# It will perform as expected for a Slack Socket Mode client: acknowledge all events and refresh when needed
|
8
|
+
# Moreover it will use the client's callback for processing events
|
5
9
|
class WebSocket
|
6
10
|
attr_reader :client
|
7
11
|
|
@@ -13,6 +17,7 @@ module SlackSocketModeBot
|
|
13
17
|
@ping_id = 1
|
14
18
|
end
|
15
19
|
|
20
|
+
# rubocop:disable Metrics
|
16
21
|
def connect!
|
17
22
|
Async do |task|
|
18
23
|
trap_sigterm(task)
|
@@ -51,6 +56,7 @@ module SlackSocketModeBot
|
|
51
56
|
@ping_task&.stop
|
52
57
|
@socket_task&.stop
|
53
58
|
end
|
59
|
+
# rubocop:enable Metrics
|
54
60
|
|
55
61
|
private
|
56
62
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-socket-mode-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- guille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: async-http
|
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'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: async-websocket
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,10 +66,11 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
description:
|
56
|
-
This gem
|
57
|
-
|
58
|
-
|
69
|
+
description: |
|
70
|
+
This gem allows users to create Slack bots that respond to mentions.
|
71
|
+
This gem only supports events-based socket mode bots.
|
72
|
+
The gem allows registering a number of callbacks that will be executed
|
73
|
+
if the registered regular expression matches the mention text.
|
59
74
|
email:
|
60
75
|
- guille@users.noreply.github.com
|
61
76
|
executables: []
|
@@ -88,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
103
|
requirements:
|
89
104
|
- - ">="
|
90
105
|
- !ruby/object:Gem::Version
|
91
|
-
version: 3.
|
106
|
+
version: 3.2.0
|
92
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
108
|
requirements:
|
94
109
|
- - ">="
|