Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.hubspot.immutables.style.HubSpotStyle;
import java.util.Optional;
import org.immutables.value.Value.Check;
Expand All @@ -25,6 +26,13 @@ public interface ChatUpdateMessageParamsIF extends MessageParams {

String getTs();

/**
* IDs of already-uploaded files to attach to the message. Upload them without a channel
* (files.completeUploadExternal with no channel_id) so Slack doesn't post a separate file
* message. Slack replaces the message's blocks on update, so re-send the existing blocks too.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: check() still requires text/attachments/blocks even when only file_ids is set, but Slack doesn鈥檛 require that for file_ids alone. Probably fine in practice since callers already have to re-send blocks (per the javadoc above), just flagging in case a file_ids-only update is a valid use case you want to support.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good flag. I left it as is on purpose. When I tested chat.update with just text + file_ids, Slack replaced the message's blocks with a plain rich_text block (buttons and context gone), so a files-only update would wipe the rest of the message. Keeping the check nudges callers to re-send blocks, which the Javadoc says is required. I haven't tried a file_ids-only update with no text, but it isn't a use case we need. Happy to relax it if you think it's worth supporting.

ImmutableList<String> getFileIds();

@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonProperty("as_user")
Optional<Boolean> getAsUser();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.hubspot.slack.client.methods.params.chat;

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.slack.client.jackson.ObjectMapperUtils;
import org.junit.Test;

public class ChatUpdateMessageParamsSerializationTest {

private static final ObjectMapper OBJECT_MAPPER = ObjectMapperUtils.mapper();

@Test
public void itSerializesFileIdsAsJsonArray() {
ChatUpdateMessageParams params = ChatUpdateMessageParams
.builder()
.setChannelId("C123")
.setTs("1790587670.603089")
.setText("testText")
.addFileIds("F0C4SK2P1EZ", "F0C4SK0RGGM")
.build();

JsonNode json = OBJECT_MAPPER.valueToTree(params);

assertThat(json.get("file_ids").isArray()).isTrue();
assertThat(json.get("file_ids"))
.extracting(JsonNode::asText)
.containsExactly("F0C4SK2P1EZ", "F0C4SK0RGGM");
}

@Test
public void itOmitsFileIdsWhenEmpty() {
ChatUpdateMessageParams params = ChatUpdateMessageParams
.builder()
.setChannelId("C123")
.setTs("1790587670.603089")
.setText("testText")
.build();

JsonNode json = OBJECT_MAPPER.valueToTree(params);

assertThat(json.has("file_ids")).isFalse();
}
}
Loading