Skip to content

Commit b09580b

Browse files
authored
Merge pull request #416 from seratch/issue-415
Fix #415 attachments payload's validity issue
2 parents ff3daea + 9b8999a commit b09580b

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

json-logs/samples/api/im.history.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"ts": ""
2222
}
2323
],
24-
"subscribed": false
24+
"subscribed": false,
25+
"user": "U00000000",
26+
"bot_link": ""
2527
}
2628
],
2729
"has_more": false,

json-logs/samples/api/rtm.start.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@
800800
"url": "",
801801
"is_europe": false,
802802
"accept_tos_url": "https://www.example.com/",
803+
"channels_with_use_case": {},
803804
"error": "",
804805
"needed": "",
805806
"provided": ""

slack-api-client/src/test/java/test_with_remote_apis/methods/chat_Test.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
import java.util.*;
2626
import java.util.concurrent.ExecutionException;
2727

28+
import static com.slack.api.model.Attachments.asAttachments;
29+
import static com.slack.api.model.Attachments.attachment;
30+
import static com.slack.api.model.block.Blocks.asBlocks;
31+
import static com.slack.api.model.block.Blocks.section;
32+
import static com.slack.api.model.block.composition.BlockCompositions.markdownText;
2833
import static org.hamcrest.CoreMatchers.*;
2934
import static org.hamcrest.MatcherAssert.assertThat;
3035
import static org.junit.Assert.assertNull;
@@ -692,4 +697,38 @@ public void scheduleMessages() throws IOException, SlackApiException {
692697
assertTrue(after.getScheduledMessages().size() - before.getScheduledMessages().size() == 2);
693698
}
694699

700+
// https://github.com/slackapi/java-slack-sdk/issues/415
701+
@Test
702+
public void attachmentsWithBlocks_issue_415() throws IOException, SlackApiException {
703+
loadRandomChannelId();
704+
/*
705+
* {
706+
* "attachments": [
707+
* {
708+
* "color": "#00FF00",
709+
* "blocks": [
710+
* {
711+
* "type": "section",
712+
* "text": {
713+
* "type": "mrkdwn",
714+
* "text": "*I would expect this text to show*"
715+
* }
716+
* }
717+
* ]
718+
* }
719+
* ]
720+
* }
721+
*/
722+
List<Attachment> attachments = asAttachments(
723+
attachment(a -> a.color("#00FF00").blocks(asBlocks(
724+
section(s -> s.text(markdownText("*I would expect this text to show*")))
725+
)))
726+
);
727+
ChatPostMessageResponse result = slack.methods(botToken).chatPostMessage(r -> r
728+
.channel(randomChannelId)
729+
.attachments(attachments)
730+
);
731+
assertThat(result.getError(), is(nullValue()));
732+
}
733+
695734
}

slack-api-client/src/test/java/test_with_remote_apis/methods/conversations_Test.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ public void replies() throws IOException, SlackApiException {
416416
List<Message> messages = response.getMessages();
417417
Message firstMessage = messages.get(0);
418418
assertThat(firstMessage.getReplyUsersCount(), is(1));
419-
assertThat(firstMessage.getReplies().size(), is(5));
419+
// NOTE: As of April 2020, this field is no longer available
420+
// assertThat(firstMessage.getReplies().size(), is(5));
421+
assertThat(firstMessage.getReplies(), is(nullValue()));
420422
assertThat(firstMessage.getReplyCount(), is(5));
421423
assertThat(firstMessage.getLatestReply(), is(messages.get(5).getTs()));
422424
}
@@ -433,7 +435,9 @@ public void replies() throws IOException, SlackApiException {
433435
List<Message> messages = response.getMessages();
434436
Message firstMessage = messages.get(0);
435437
assertThat(firstMessage.getReplyUsersCount(), is(1));
436-
assertThat(firstMessage.getReplies().size(), is(5));
438+
// NOTE: As of April 2020, this field is no longer available
439+
// assertThat(firstMessage.getReplies().size(), is(5));
440+
assertThat(firstMessage.getReplies(), is(nullValue()));
437441
assertThat(firstMessage.getReplyCount(), is(5));
438442
assertThat(firstMessage.getLatestReply(), is(messages.get(5).getTs()));
439443
}

slack-api-model/src/main/java/com/slack/api/model/Attachment.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.slack.api.model.block.LayoutBlock;
55
import lombok.*;
66

7-
import java.util.ArrayList;
87
import java.util.List;
98

109
/**
@@ -190,8 +189,7 @@ public void setAppUnfurl(Boolean appUnfurl) {
190189
/**
191190
* Fields are defined as an array, and hashes contained within it will be displayed in a table inside the message attachment.
192191
*/
193-
@Builder.Default
194-
private List<Field> fields = new ArrayList<>();
192+
private List<Field> fields;
195193

196194
/**
197195
* A valid URL to an image file that will be displayed inside a message attachment.
@@ -259,14 +257,12 @@ public void setAppUnfurl(Boolean appUnfurl) {
259257
* in attachments</a> are not formatted. To enable formatting on attachment fields, add the
260258
* name of the field (as defined in the API) in this list.
261259
*/
262-
@Builder.Default
263-
private List<String> mrkdwnIn = new ArrayList<>();
260+
private List<String> mrkdwnIn;
264261

265262
/**
266263
* Actions are defined as an array, and hashes contained within it will be displayed in as buttons in the message attachment.
267264
*/
268-
@Builder.Default
269-
private List<Action> actions = new ArrayList<>();
265+
private List<Action> actions;
270266

271267
private List<LayoutBlock> blocks;
272268

slack-app-backend/src/test/java/test_locally/app_backend/outgoing_webhooks/WebhookResponseTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static org.hamcrest.MatcherAssert.assertThat;
1010
import static org.hamcrest.Matchers.is;
11+
import static org.hamcrest.Matchers.nullValue;
1112
import static org.junit.Assert.assertNull;
1213

1314
public class WebhookResponseTest {
@@ -64,7 +65,7 @@ public void test() {
6465
assertThat(attachmentResponse.getTitle(), is("Slack API Documentation"));
6566
assertThat(attachmentResponse.getTitleLink(), is("https://api.slack.com/"));
6667
assertThat(attachmentResponse.getText(), is("This is an *attachment*."));
67-
assertThat(attachmentResponse.getFields().size(), is(0));
68+
assertThat(attachmentResponse.getFields(), is(nullValue()));
6869
assertNull(attachmentResponse.getImageUrl());
6970
assertNull(attachmentResponse.getImageWidth());
7071
assertNull(attachmentResponse.getImageHeight());
@@ -78,8 +79,8 @@ public void test() {
7879
assertThat(attachmentResponse.getFooter(), is("footer"));
7980
assertNull(attachmentResponse.getFooterIcon());
8081
assertNull(attachmentResponse.getTs());
81-
assertThat(attachmentResponse.getMrkdwnIn().size(), is(0));
82-
assertThat(attachmentResponse.getActions().size(), is(0));
82+
assertThat(attachmentResponse.getMrkdwnIn(), is(nullValue()));
83+
assertThat(attachmentResponse.getActions(), is(nullValue()));
8384
assertNull(attachmentResponse.getBlocks());
8485
assertNull(attachmentResponse.getFilename());
8586
assertNull(attachmentResponse.getSize());

0 commit comments

Comments
 (0)