Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jakarta EE compatible Socket Mode client ref: #919 #1352

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

seratch
Copy link
Member

@seratch seratch commented Aug 22, 2024

This pull request adds two new optional modules:

  • slack-jakarta-socket-mode-client
  • bolt-jakarta-socket-mode

The currently available Socket Mode client's default implementation uses tyrus-standalone-client 1.x, which is compatible with javax.websocket-api APIs. The Jakarta EE version of this interface is the jakarta.websocket-client-api APIs, and tyrus-standalone-client 2.x is compatible with it. Since it's not feasible to have both tyrus-standalone-client 1.x and 2.x in the same module's dependencies, I have added a new module named slack-jakarta-socket-mode-client. See #919 for more details.

Developers can initialize the Jakarta-compatible SocketModeClient this way:

import com.slack.api.Slack;
import com.slack.api.jakarta_socket_mode.JakartaSocketModeClientFactory;

public class Example {
  public static void main(String[] args) throws Exception {
    var appToken = System.getenv("SLACK_APP_TOKEN");
    var slack = Slack.getInstance();
    // Java EE compatible Socket Mode client
    slack.socketMode(appToken).connect();
    // Jakarta EE compatible Socket Mode client
    JakartaSocketModeClientFactory.create(slack, appToken).connect();
  }
}

In the same way, I’ve added a new Jakarta-compatible module, which is equivalent to bolt-socket-mode. Here is the demo code. As you can see, just replace the dependency and imports in the code:

import com.slack.api.bolt.App;
import com.slack.api.bolt.jakarta_socket_mode.SocketModeApp;

public class Example {
  public static void main(String[] args) throws Exception {
    var app = new App();
    app.command("/hi", (req, ctx) -> {
      ctx.say("Hi there!");
      return ctx.ack();
    });
    var appToken = System.getenv("SLACK_APP_TOKEN");
    // Switch from com.slack.api.bolt.socket_mode to com.slack.api.bolt.jakarta_socket_mode
    new SocketModeApp(appToken, app).start();
  }
}

The reason behind this enhancement is that many Java-focused companies are planning to eliminate the legacy javax.* dependencies from their project settings. I don't think the short-term risk of having a javax.websocket dependency is significant, but it seems it's about time to provide an option for migration on the developers' side.

Category (place an x in each of the [ ])

  • bolt (Bolt for Java)
  • bolt-{sub modules} (Bolt for Java - optional modules)
  • slack-api-client (Slack API Clients)
  • slack-api-model (Slack API Data Models)
  • slack-api-*-kotlin-extension (Kotlin Extensions for Slack API Clients)
  • slack-app-backend (The primitive layer of Bolt for Java)

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you agree to those rules.

@seratch seratch added enhancement M-T: A feature request for new functionality project:bolt project:slack-api-client project:slack-api-client dependencies Pull requests that update a dependency file labels Aug 22, 2024
@seratch seratch self-assigned this Aug 22, 2024
@seratch seratch added this to the 1.42.0 milestone Aug 22, 2024
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 68.43854% with 95 lines in your changes missing coverage. Please review.

Project coverage is 74.82%. Comparing base (e542f29) to head (a76768d).
Report is 1 commits behind head on main.

Files Patch % Lines
...et_mode/impl/JakartaSocketModeClientTyrusImpl.java 71.09% 39 Missing and 11 partials ⚠️
...ck/api/bolt/jakarta_socket_mode/SocketModeApp.java 62.50% 28 Missing and 5 partials ⚠️
...ta_socket_mode/JakartaSocketModeClientFactory.java 25.00% 11 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1352      +/-   ##
============================================
- Coverage     74.99%   74.82%   -0.18%     
- Complexity     4203     4274      +71     
============================================
  Files           453      457       +4     
  Lines         12975    13276     +301     
  Branches       1342     1369      +27     
============================================
+ Hits           9731     9934     +203     
- Misses         2462     2544      +82     
- Partials        782      798      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 💯 the changes seem to be mainly be a copy of existing code 👍

I'm assuming this code has been stable for a while, maintaining this type of duplication should not be a problem

@@ -0,0 +1,435 @@
package com.slack.api.jakarta_socket_mode.impl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is almost an exact copy of SocketModeClientTyrusImpl.java, which is production worthy 🧠

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right!

…akarta_socket_mode/impl/JakartaSocketModeClientTyrusImpl.java

Co-authored-by: William Bergamin <william.bergamin.coen@gmail.com>
@seratch seratch merged commit 9cb6946 into slackapi:main Aug 23, 2024
8 checks passed
@seratch seratch deleted the jakarta-socket-mode branch August 23, 2024 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement M-T: A feature request for new functionality project:bolt project:slack-api-client project:slack-api-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants