diff --git a/slack-api-client/src/main/java/com/slack/api/methods/RequestFormBuilder.java b/slack-api-client/src/main/java/com/slack/api/methods/RequestFormBuilder.java index 30b45a1dd..51c310ff4 100644 --- a/slack-api-client/src/main/java/com/slack/api/methods/RequestFormBuilder.java +++ b/slack-api-client/src/main/java/com/slack/api/methods/RequestFormBuilder.java @@ -2086,7 +2086,11 @@ public static FormBody.Builder toForm(FilesCompleteUploadExternalRequest req) { if (req.getFiles() != null) { setIfNotNull("files", GSON.toJson(req.getFiles()), form); } - setIfNotNull("channel_id", req.getChannelId(), form); + if (req.getChannels() != null) { + setIfNotNull("channels", req.getChannels().stream().collect(joining(",")), form); + } else { + setIfNotNull("channel_id", req.getChannelId(), form); + } setIfNotNull("initial_comment", req.getInitialComment(), form); setIfNotNull("thread_ts", req.getThreadTs(), form); return form; diff --git a/slack-api-client/src/main/java/com/slack/api/methods/impl/FilesUploadV2Helper.java b/slack-api-client/src/main/java/com/slack/api/methods/impl/FilesUploadV2Helper.java index 65bf5dbce..46f3f0b42 100644 --- a/slack-api-client/src/main/java/com/slack/api/methods/impl/FilesUploadV2Helper.java +++ b/slack-api-client/src/main/java/com/slack/api/methods/impl/FilesUploadV2Helper.java @@ -94,6 +94,7 @@ public FilesUploadV2Response completeUploads( .token(v2Request.getToken()) .files(files) .channelId(v2Request.getChannel()) + .channels(v2Request.getChannels()) .initialComment(v2Request.getInitialComment()) .threadTs(v2Request.getThreadTs()) ); diff --git a/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesCompleteUploadExternalRequest.java b/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesCompleteUploadExternalRequest.java index 2affe7cec..5b89c1d39 100644 --- a/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesCompleteUploadExternalRequest.java +++ b/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesCompleteUploadExternalRequest.java @@ -30,6 +30,11 @@ public class FilesCompleteUploadExternalRequest implements SlackApiRequest { */ private String channelId; + /** + * Comma-separated string of channel IDs where the file will be shared. + */ + private List channels; + /** * The message text introducing the file in specified channels. */ diff --git a/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesUploadV2Request.java b/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesUploadV2Request.java index 586e0a456..f7ba130cd 100644 --- a/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesUploadV2Request.java +++ b/slack-api-client/src/main/java/com/slack/api/methods/request/files/FilesUploadV2Request.java @@ -130,6 +130,11 @@ public static class UploadFile { */ private String channel; + /** + * Comma-separated string of channel IDs where the file will be shared. + */ + private List channels; + /** * Provide another message's ts value to upload this file as a reply. * Never use a reply's ts value; use its parent instead. diff --git a/slack-api-client/src/test/java/test_with_remote_apis/methods/files_Test.java b/slack-api-client/src/test/java/test_with_remote_apis/methods/files_Test.java index 95d019de7..0967236fb 100644 --- a/slack-api-client/src/test/java/test_with_remote_apis/methods/files_Test.java +++ b/slack-api-client/src/test/java/test_with_remote_apis/methods/files_Test.java @@ -46,6 +46,7 @@ @Slf4j public class files_Test { + private String generalChannelId = null; private String randomChannelId = null; void loadRandomChannelId() throws IOException, SlackApiException { @@ -62,6 +63,20 @@ void loadRandomChannelId() throws IOException, SlackApiException { } } + void loadGeneralChannelId() throws IOException, SlackApiException { + if (generalChannelId == null) { + ConversationsListResponse channelsListResponse = + slack.methods().conversationsList(r -> r.token(botToken).excludeArchived(true).limit(100)); + assertThat(channelsListResponse.getError(), is(nullValue())); + for (Conversation channel : channelsListResponse.getChannels()) { + if (channel.getName().equals("general")) { + generalChannelId = channel.getId(); + break; + } + } + } + } + static SlackTestConfig testConfig = SlackTestConfig.getInstance(); static Slack slack = Slack.getInstance(testConfig.getConfig()); @@ -1254,4 +1269,52 @@ public void issue1345_filesUploadV2_multiple_no_filename_no_title() throws IOExc // title defaults to filename, which is (as this is defaulted on the client side) "Uploaded file" assertThat(response.getFiles().get(0).getTitle(), is("Uploaded file")); } + + @Test + public void filesUploadV2_channels() throws Exception { + loadRandomChannelId(); + loadGeneralChannelId(); + MethodsClient client = slack.methods(botToken); + + File file1 = new File("src/test/resources/sample.txt"); + FilesUploadV2Response response = client.filesUploadV2(r -> r + .file(file1) + .title("sample.txt") + .filename("sample.txt") + .snippetType("text") + .channels(Arrays.asList(generalChannelId, randomChannelId)) + .initialComment("Here you are :wave:") + ); + assertThat(response.getError(), is(nullValue())); + + List expectedFileIds = response.getFiles().stream() + .map(a -> a.getId()).collect(Collectors.toList()); + + int count = 0; + ConversationsHistoryResponse history = null; + List actualFileIds = null; + while (count < 10) { + count++; + history = client.conversationsHistory(r -> r + .channel(randomChannelId) + .limit(1) + ); + if (history.getMessages().get(0).getFiles() != null) { + actualFileIds = history.getMessages().get(0).getFiles().stream() + .map(a -> a.getId()).sorted().collect(Collectors.toList()); + if (actualFileIds.stream().collect(Collectors.joining(",")) + .equals(expectedFileIds.stream().collect(Collectors.joining(",")))) { + break; + } + } + Thread.sleep(3000L); + } + assertThat(history.getError(), is(nullValue())); + assertThat(history.getMessages().get(0).getFiles(), is(notNullValue())); + assertThat(actualFileIds, is(expectedFileIds)); + + FilesInfoResponse file1info = client.filesInfo(r -> r.file(response.getFile().getId())); + assertThat(file1info.getFile().getShares().getPublicChannels().get(randomChannelId), is(notNullValue())); + } + }