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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d9b476cbef5846c666a7ab994c514f998f870d2004b1d2b0f3ff6c053e4c8f0
4
- data.tar.gz: 46d7af96360646c78325592dcf4e5d4ba26ec5f6f776948e387f1d907eb0b96b
3
+ metadata.gz: ad18066a5a94aeb5eafd67bd14a67fe3dc0f6220b1efeefbe46b755671205247
4
+ data.tar.gz: e2aba7056fc4ffe2180a4f3a8941313457adb87e055bd344f97f88a6b64f912c
5
5
  SHA512:
6
- metadata.gz: c696e7a8826e208174474dbcdfa03a242e8828a9de4b50e1add4ee3604180bc5080dc0ed45058f7978a2dcf494c7ac96d031f32c65aba702c4d283c5b2aad3e4
7
- data.tar.gz: a60f162cf935ede9f7f08474ec8a3401b3493843207855611acf60b46965f886ec0cb2fb169206a17daa7f6ba353af131a72a3eaf3f1353ee6bfde5bd3c5cf30
6
+ metadata.gz: 044e1076b5f27b68912fc6af4b08ee27edc3e45207c838d2594abe0c9305187d183dfbd96f6d86fb9dd3f0982811cbc256a75bef2c7834ea379d9600a99f7061
7
+ data.tar.gz: cc151aee374edf16b835f4c8b0167db94d68426f93c5319b731928a0df511b0dc720d06974b41e5de93ba8e8f09febcd4cc3f3eeb52b1a1a5811f13cb40c323d
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.3
2
+ TargetRubyVersion: 3.2
3
3
 
4
4
  Style/StringLiterals:
5
5
  EnforcedStyle: double_quotes
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # slack-ruby-socket-mode-bot
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/slack-ruby-socket-mode-bot.svg)](https://badge.fury.io/rb/slack-ruby-socket-mode-bot)
4
+ [![Tests](https://github.com/guille/slack-socket-mode-bot/actions/workflows/main.yml/badge.svg)](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
- response[:url]
24
- # debug only:
25
- "#{response[:url]}&debug_reconnects=true"
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlackSocketModeBot
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.1.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-26 00:00:00.000000000 Z
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: This gem allows users to create Slack bots that respond to mentions.
56
- This gem only supports events-based socket mode bots. The gem allows registering
57
- a number of callbacks that will be executed if the registered regular expression
58
- matches the mention text.
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.0.0
106
+ version: 3.2.0
92
107
  required_rubygems_version: !ruby/object:Gem::Requirement
93
108
  requirements:
94
109
  - - ">="