Skip to content

Releases: slackapi/java-slack-sdk

version 1.44.1

22 Oct 06:21
Compare
Choose a tag to compare

Changes

  • [bolt] #1389 Fix a bug where parsing assistant thread message event fails for beta feature enabled apps - Thanks @seratch

version 1.44.0

17 Oct 05:13
Compare
Choose a tag to compare

New Features

Agents & Assistants

A better Agents & Assistants support in Bolt is now available!

While you already can implement your agents using app.event(...) listeners for assistant_thread_started, assistant_thread_context_changed, and message events, Bolt offers a simpler approach. You just need to create an Assistant instance, attach the needed event handlers to it, and then add the assistant to your App instance.

App app = new App();
Assistant assistant = new Assistant(app.executorService());

assistant.threadStarted((req, ctx) -> {
  try {
    ctx.say(r -> r.text("Hi, how can I help you today?"));
    ctx.setSuggestedPrompts(Collections.singletonList(
      SuggestedPrompt.create("What does SLACK stand for?")
    ));
  } catch (Exception e) {
    ctx.logger.error("Failed to handle assistant thread started event: {e}", e);
  }
});

assistant.userMessage((req, ctx) -> {
  try {
    ctx.setStatus("is typing...");
    Thread.sleep(500L);
    if (ctx.getThreadContext() != null) {
      String contextChannel = ctx.getThreadContext().getChannelId();
      ctx.say(r -> r.text("I am ware of the channel context: <#" + contextChannel + ">"));
    } else {
      ctx.say(r -> r.text("Here you are!"));
    }
  } catch (Exception e) {
    ctx.logger.error("Failed to handle assistant thread started event: {e}", e);
    try {
      ctx.say(r -> r.text(":warning: Sorry, something went wrong during processing your request!"));
    } catch (Exception ee) {
      ctx.logger.error("Failed to inform the error to the end-user: {ee}", ee);
    }
  }
});

app.assistant(assistant);

Please refer to https://tools.slack.dev/java-slack-sdk/guides/assistants for more details.

Changes

  • [bolt] #1372 #1383 Add Agents & Assistants document page - Thanks @seratch
  • [bolt] #1388 Fix #1348 channel_convert_to_public message events - Thanks @seratch @mgroth0
  • [bolt] #1380 Remove extra double quotes from the "Add to Slack" OAuth image alt text - Thanks @zimeg
  • [slack-api-client] #1382 Add conversations.requestSharedInvite.list API support - Thanks @seratch
  • [slack-api-client] #1376 Add RichTextBlock support to Block Kit Kotlin DSL builder - Thanks @KENNYSOFT

version 1.43.1

20 Sep 00:11
Compare
Choose a tag to compare

Changes

  • [bolt] #1375 Fix #1147 Improve the logic to extract the requestUserId for context objects - Thanks @seratch
  • [slack-api-client] #1374 Fix #1373 LogsResponse in AuditClient returns "ok: false" when request was a success - Thanks @Dunkhell @seratch
  • [slack-api-client] Add missing properties in web API responses - Thanks @seratch

Additionaly, while #1377 is not a change for the main code, @KENNYSOFT significantly improved the test execution time by the PR. Thank you so much for the wonderful contribution!


version 1.43.0

17 Sep 00:03
Compare
Choose a tag to compare

Announcements

Assistant Apps in Bolt

This version includes the folllowing APIs and Events API payloads:

We're planning to add a more convenient way to develop AI assistant apps in the near future, but we can already develop such with the following primitive code:

app.event(AssistantThreadStartedEvent.class, (req, ctx) -> {
  String channelId = req.getEvent().getAssistantThread().getChannelId();
  String threadTs = req.getEvent().getAssistantThread().getThreadTs();
  app.executorService().submit(() -> {
    try {
      ctx.client().assistantThreadsSetTitle(r -> r.channelId(channelId).threadTs(threadTs).title("New chat"));
      ctx.client().chatPostMessage(r -> r.channel(channelId).threadTs(threadTs).text("Hi, how can I help you today?"));
      ctx.client().assistantThreadsSetSuggestedPrompts(r -> r.channelId(channelId).threadTs(threadTs).title("How are you?")
        .prompts(Collections.singletonList(new SuggestedPrompt("What does SLACK stand for?")))
      );
    } catch (Exception e) {
      ctx.logger.error("Failed to handle assistant thread started event: {e}", e);
    }
  });
  return ctx.ack();
});

app.event(AssistantThreadContextChangedEvent.class, (req, ctx) -> {
  app.executorService().submit(() -> {
    String channelId = req.getEvent().getAssistantThread().getChannelId();
    String threadTs = req.getEvent().getAssistantThread().getThreadTs();
    // TODO: Store req.getEvent().getAssistantThread() for the following conversation
  });
  return ctx.ack();
});

app.event(MessageEvent.class, (req, ctx) -> {
  if (req.getEvent().getChannelType().equals("im") && req.getEvent().getThreadTs() != null) {
    String channelId = req.getEvent().getChannel();
    String threadTs = req.getEvent().getThreadTs();
    app.executorService().submit(() -> {
      try {
        ctx.client().assistantThreadsSetStatus(r -> r.channelId(channelId).threadTs(threadTs).status("is typing..."));
        Thread.sleep(500L);
        ctx.client().chatPostMessage(r -> r.channel(channelId).threadTs(threadTs).text("Here you are!"));
      } catch (Exception e) {
        ctx.logger.error("Failed to handle assistant thread started event: {e}", e);
        try {
          ctx.client().chatPostMessage(r -> r.channel(channelId).threadTs(threadTs).text(":warning: Sorry, something went wrong during processing your request!"));
        } catch (Exception ee) {
          ctx.logger.error("Failed to inform the error to the end-user: {ee}", ee);
        }
      }
    });
  }
  return ctx.ack();
});

Changes

  • [slack-api-client] #1371 Add assistant.threads.* APIs and related event payloads - Thanks @seratch
  • [slack-api-client] Add missing properties in web API responses - Thanks @seratch

version 1.42.1

14 Sep 00:35
Compare
Choose a tag to compare

Changes

  • [slack-api-client] #1365 Add conversations.requestSharedInvite.approve/deny APIs - Thanks @seratch
  • [slack-api-client] #1362 Add interactivity_pointer to views.open/push API params - Thanks @seratch
  • [slack-api-client] Add missing properties in web API responses - Thanks @seratch
  • [slack-api-model] #1364 Fix #1363 Wrong element type for timestamp in RichTextSectionElement.Date - Thanks @jed204
  • [bolt] #1355 Updating app_requested payload to include new field - Thanks @gugutagli

version 1.42.0

23 Aug 01:24
Compare
Choose a tag to compare

Announcements

Jakarta EE compatible Socket Mode

Since this version, developers can migrate to the newer Jakarta EE compatible WebSocket interface for Socket Mode modules. To enable this, the following two optional modules are added:

  • com.slack.api:slack-jakarta-socket-mode-client
  • com.slack.api:bolt-jakarata-socket-mode

The 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-house 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.

Changes

  • [slack-api-client][bot] #1352 Add Jakarta EE compatible Socket Mode client ref: #919 - Thanks @seratch
  • [slack-api-client] Add missing properties in web API responses - Thanks @seratch

version 1.41.0

20 Aug 07:58
Compare
Choose a tag to compare

Announcements

Support for custom steps

Bolt for Java now supoports the way to build custom steps in Workflow Builder. Here is a quick example demonstrating how it works:

app.function("sample_function", (req, ctx) -> {
  app.executorService().submit(() -> {
    try {
      var userId = req.getEvent().getInputs().get("user_id").asString();
      var response = ctx.client().chatPostMessage(r -> r
        .channel(userId) // sending a DM
        .text("Hi! Thank you for submitting the request! We'll let you know once the processing completes.")
      );
      var outputs = new HashMap<String, Object>();
      outputs.put("channel_id", response.getChannel());
      outputs.put("ts", response.getTs());
      ctx.complete(outputs);
    } catch (Exception e) {
      ctx.logger.error(e.getMessage(), e);
      try {
        ctx.fail("Failed to handle 'sample_function' custom step execution (error: " + e.getMessage() + ")");
      } catch (Exception ex) {
        ctx.logger.error(e.getMessage(), e);
      }
    }
  });
  return ctx.ack();
});

The App Manifest for the custom step would be something like this:

"functions": {
    "sample_function": {
        "title": "Send a request",
        "description": "Send some request to the backend",
        "input_parameters": {
            "user_id": {
                "type": "slack#/types/user_id",
                "title": "User",
                "description": "Who to send it",
                "is_required": true,
                "hint": "Select a user in the workspace",
                "name": "user_id"
            }
        },
        "output_parameters": {
            "channel_id": {
                "type": "slack#/types/channel_id",
                "title": "DM ID",
                "description": "The DM ID",
                "is_required": true,
                "name": "channel_id"
            },
            "ts": {
                "type": "string",
                "title": "Message timestamp",
                "description": "Sent message timestamp",
                "is_required": true,
                "name": "ts"
            }
        }
    }
}

Please refer to https://api.slack.com/automation/functions/custom-bolt for more details!

Changes

  • [bolt] #1241 Add custom function support - Thanks @seratch
  • [bolt][slack-app-backend] #1351 #1343 block_suggestion response does not support description in an option - Thanks @ESteanes @seratch
  • [slack-api-client] #1346 Fix a bug where filename & title getting improperly defaulted in filesUploadV2 - Thanks @Cheos137
  • [slack-api-client] Add missing properties in web API responses - Thanks @seratch

version 1.40.3

16 Jul 23:35
Compare
Choose a tag to compare

Changes

  • [slack-api-client] #1337 Fix #1336 missing and invalid properties in rich text block elements - Thanks @seratch @Falit
  • [slack-api-client] Add new properties to Web API responses - Thanks @seratch
  • [bolt] Add missing properties in app_mention event payload - Thanks @seratch

version 1.40.2

03 Jul 01:53
Compare
Choose a tag to compare

Changes

  • [slack-api-client] #1330 Add conversations.externalInvitePermissions.set API support - Thanks @seratch
  • [slack-api-client] #1331 Add team.externalTeams.disconnect API - Thanks @seratch
  • [bolt] #1332 Add a few missing event data types - Thanks @seratch
  • [slack-api-client] Add new properties to Web API responses - Thanks @seratch

version 1.40.1

19 Jun 03:12
Compare
Choose a tag to compare

Changes

  • [slack-api-client] #1327 Add team.externalTeams.list API support - Thanks @seratch
  • [slack-api-client] Add new properties to Web API responses - Thanks @seratch