Skip to content

Commit 3c99b96

Browse files
zimegClaude
andauthored
feat(methods): add chat.appendStream, chat.startStream and chat.stopStream method examples (#56)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent 55aee4f commit 3c99b96

4 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎methods/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ $ mvn compile exec:java -Dexec.mainClass=chat.ChatPostMessage # Make the reques
5151

5252
### chat
5353

54+
- **[chat.appendStream](https://docs.slack.dev/reference/methods/chat.appendStream)**: Appends text to an existing streaming conversation. [Implementation](./src/main/java/chat/ChatAppendStream.java).
5455
- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/main/java/chat/ChatPostMessage.java).
56+
- **[chat.startStream](https://docs.slack.dev/reference/methods/chat.startStream)**: Starts a new streaming conversation. [Implementation](./src/main/java/chat/ChatStartStream.java).
57+
- **[chat.stopStream](https://docs.slack.dev/reference/methods/chat.stopStream)**: Stops a streaming conversation. [Implementation](./src/main/java/chat/ChatStopStream.java).
5558

5659
### slackbot
5760

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package chat;
2+
3+
import com.slack.api.Slack;
4+
import com.slack.api.methods.MethodsClient;
5+
import com.slack.api.methods.SlackApiException;
6+
import com.slack.api.methods.request.chat.ChatAppendStreamRequest;
7+
import com.slack.api.methods.response.chat.ChatAppendStreamResponse;
8+
import java.io.IOException;
9+
10+
public class ChatAppendStream {
11+
12+
public static void main(String[] args) throws IOException, SlackApiException {
13+
// Read a token from an environment variable
14+
String token = System.getenv("SLACK_TOKEN");
15+
16+
// Initialize
17+
MethodsClient methods = Slack.getInstance().methods(token);
18+
19+
// Call the chat.appendStream method
20+
ChatAppendStreamRequest request = ChatAppendStreamRequest.builder()
21+
.channel("C123ABC456")
22+
.ts("1234567890.123456")
23+
.markdownText("**This is bold text**")
24+
.build();
25+
ChatAppendStreamResponse response = methods.chatAppendStream(request);
26+
27+
// Inspect the response
28+
System.out.println(response);
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package chat;
2+
3+
import com.slack.api.Slack;
4+
import com.slack.api.methods.MethodsClient;
5+
import com.slack.api.methods.SlackApiException;
6+
import com.slack.api.methods.request.chat.ChatStartStreamRequest;
7+
import com.slack.api.methods.response.chat.ChatStartStreamResponse;
8+
import java.io.IOException;
9+
10+
public class ChatStartStream {
11+
12+
public static void main(String[] args) throws IOException, SlackApiException {
13+
// Read a token from an environment variable
14+
String token = System.getenv("SLACK_TOKEN");
15+
16+
// Initialize
17+
MethodsClient methods = Slack.getInstance().methods(token);
18+
19+
// Call the chat.startStream method
20+
ChatStartStreamRequest request = ChatStartStreamRequest.builder()
21+
.channel("C123ABC456")
22+
.markdownText("**This is bold text**")
23+
.threadTs("1721609600.123456")
24+
.recipientUserId("U0123456789")
25+
.recipientTeamId("T0123456789")
26+
.build();
27+
ChatStartStreamResponse response = methods.chatStartStream(request);
28+
29+
// Inspect the response
30+
System.out.println(response);
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package chat;
2+
3+
import com.slack.api.Slack;
4+
import com.slack.api.methods.MethodsClient;
5+
import com.slack.api.methods.SlackApiException;
6+
import com.slack.api.methods.request.chat.ChatStopStreamRequest;
7+
import com.slack.api.methods.response.chat.ChatStopStreamResponse;
8+
import java.io.IOException;
9+
10+
public class ChatStopStream {
11+
12+
public static void main(String[] args) throws IOException, SlackApiException {
13+
// Read a token from an environment variable
14+
String token = System.getenv("SLACK_TOKEN");
15+
16+
// Initialize
17+
MethodsClient methods = Slack.getInstance().methods(token);
18+
19+
// Call the chat.stopStream method
20+
ChatStopStreamRequest request = ChatStopStreamRequest.builder()
21+
.channel("C123ABC456")
22+
.ts("1234567890.123456")
23+
.build();
24+
ChatStopStreamResponse response = methods.chatStopStream(request);
25+
26+
// Inspect the response
27+
System.out.println(response);
28+
}
29+
}

0 commit comments

Comments
 (0)