Skip to content

Commit d842398

Browse files
committed
feat: add loading messages to assistant threads set status
1 parent 1317675 commit d842398

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

bolt-socket-mode/src/test/java/samples/AssistantEventListenerApp.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.slack.api.model.event.*;
88

99
import java.util.Collections;
10+
import java.util.List;
1011

1112
public class AssistantEventListenerApp {
1213

@@ -96,13 +97,14 @@ public static void main(String[] args) throws Exception {
9697
ctx.client().assistantThreadsSetStatus(r -> r
9798
.channelId(channelId)
9899
.threadTs(threadTs)
99-
.status("is analyzing the files...")
100+
.status("is downloading the files...")
100101
);
101102
Thread.sleep(500L);
102103
ctx.client().assistantThreadsSetStatus(r -> r
103104
.channelId(channelId)
104105
.threadTs(threadTs)
105-
.status("is still checking the files...")
106+
.status("is analyzing the files...")
107+
.loadingMessages(List.of("Reading bytes...", "Confirming hashes..."))
106108
);
107109
Thread.sleep(500L);
108110
ctx.client().chatPostMessage(r -> r

bolt-socket-mode/src/test/java/samples/AssistantInteractionApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void main(String[] args) throws Exception {
3535
ctx.say(r -> r
3636
.text("Hi, how can I help you today?")
3737
.blocks(Arrays.asList(
38-
section(s -> s.text(plainText("Hi, how I can I help you today?"))),
38+
section(s -> s.text(plainText("Hi, how can I help you today?"))),
3939
actions(a -> a.elements(Collections.singletonList(
4040
button(b -> b.actionId("assistant-generate-numbers").text(plainText("Generate numbers")))
4141
)))
@@ -105,7 +105,7 @@ public static void main(String[] args) throws Exception {
105105
});
106106

107107
app.event(AppMentionEvent.class, (req, ctx) -> {
108-
ctx.say("You can help you at our 1:1 DM!");
108+
ctx.say("I can help you at our 1:1 DM!");
109109
return ctx.ack();
110110
});
111111

bolt-socket-mode/src/test/java/samples/AssistantSimpleApp.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.slack.api.model.event.MessageEvent;
1010

1111
import java.util.Collections;
12+
import java.util.List;
1213

1314
public class AssistantSimpleApp {
1415

@@ -37,9 +38,9 @@ public static void main(String[] args) throws Exception {
3738
// ctx.setStatus(r -> r.status("is typing...")); works too
3839
ctx.setStatus("is typing...");
3940
Thread.sleep(500L);
40-
if (ctx.getThreadContext() != null) {
41+
if (ctx.getThreadContext() != null && ctx.getThreadContext().getChannelId() != null) {
4142
String contextChannel = ctx.getThreadContext().getChannelId();
42-
ctx.say("I am ware of the channel context: <#" + contextChannel + ">");
43+
ctx.say("I am aware of the channel context: <#" + contextChannel + ">");
4344
} else {
4445
ctx.say("Here you are!");
4546
}
@@ -55,9 +56,9 @@ public static void main(String[] args) throws Exception {
5556

5657
assistant.userMessageWithFiles((req, ctx) -> {
5758
try {
58-
ctx.setStatus("is analyzing the files...");
59+
ctx.setStatus("is downloading the files...");
5960
Thread.sleep(500L);
60-
ctx.setStatus("is still checking the files...");
61+
ctx.setStatus("is analyzing the files...", List.of("Reading bytes...", "Confirming hashes..."));
6162
Thread.sleep(500L);
6263
ctx.say("Your files do not have any issues!");
6364
} catch (Exception e) {
@@ -77,7 +78,7 @@ public static void main(String[] args) throws Exception {
7778
});
7879

7980
app.event(AppMentionEvent.class, (req, ctx) -> {
80-
ctx.say("You can help you at our 1:1 DM!");
81+
ctx.say("I can help you at our 1:1 DM!");
8182
return ctx.ack();
8283
});
8384

bolt/src/main/java/com/slack/api/bolt/context/builtin/EventContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ public AssistantThreadsSetStatusResponse setStatus(String status) throws IOExcep
116116
}
117117
}
118118

119+
public AssistantThreadsSetStatusResponse setStatus(String status, List<String> loadingMessages) throws IOException, SlackApiException {
120+
if (isAssistantThreadEvent()) {
121+
return this.client().assistantThreadsSetStatus(r -> r
122+
.channelId(this.getChannelId())
123+
.threadTs(this.getThreadTs())
124+
.status(status)
125+
.loadingMessages(loadingMessages)
126+
);
127+
} else {
128+
throw new IllegalStateException("This utility is only available for Assistant feature enabled app!");
129+
}
130+
}
131+
119132
public AssistantThreadsSetStatusResponse setStatus(RequestConfigurator<AssistantThreadsSetStatusRequest.AssistantThreadsSetStatusRequestBuilder> req) throws IOException, SlackApiException {
120133
if (isAssistantThreadEvent()) {
121134
return this.client().assistantThreadsSetStatus(req.configure(AssistantThreadsSetStatusRequest.builder()

bolt/src/test/java/test_locally/app/EventAssistantTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public void test() throws Exception {
5656
ctx.setTitle("title");
5757
ctx.setTitle(r -> r.title("title"));
5858
ctx.setStatus("is typing...");
59+
ctx.setStatus(
60+
"is typing...",
61+
List.of("Teaching hamsters...", "Untangling cables...")
62+
);
5963
ctx.setStatus(r -> r.status("is typing..."));
6064
ctx.setSuggestedPrompts(new ArrayList<>());
6165
ctx.setSuggestedPrompts(r -> r.prompts(new ArrayList<>()));

slack-api-client/src/main/java/com/slack/api/methods/RequestFormBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ public static FormBody.Builder toForm(AssistantThreadsSetStatusRequest req) {
11331133
setIfNotNull("channel_id", req.getChannelId(), form);
11341134
setIfNotNull("thread_ts", req.getThreadTs(), form);
11351135
setIfNotNull("status", req.getStatus(), form);
1136+
if (req.getLoadingMessages() != null) {
1137+
setIfNotNull("loading_messages", req.getLoadingMessages().stream().collect(joining(",")), form);
1138+
}
11361139
return form;
11371140
}
11381141

slack-api-client/src/main/java/com/slack/api/methods/request/assistant/threads/AssistantThreadsSetStatusRequest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import lombok.Builder;
55
import lombok.Data;
66

7+
import java.util.List;
8+
79
/**
810
* https://docs.slack.dev/reference/methods/assistant.threads.setStatus
911
*/
@@ -27,4 +29,9 @@ public class AssistantThreadsSetStatusRequest implements SlackApiRequest {
2729
* Status of the specified bot user, e.g. 'is thinking...'
2830
*/
2931
private String status;
30-
}
32+
33+
/**
34+
* The list of messages to rotate through as a loading indicator.
35+
*/
36+
private List<String> loadingMessages;
37+
}

0 commit comments

Comments
 (0)