Skip to content

version 1.43.0

Compare
Choose a tag to compare
@seratch seratch released this 17 Sep 00:03
· 10 commits to main since this release

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