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 @@ -1500,6 +1500,7 @@ public static FormBody.Builder toForm(ChatScheduleMessageRequest req) {
warnIfEitherTextOrAttachmentFallbackIsMissing(
"chat.scheduleMessage",
req.getText(),
req.getMarkdownText(),
req.getAttachments(),
req.getAttachmentsAsString());
FormBody.Builder form = new FormBody.Builder();
Expand Down Expand Up @@ -1531,6 +1532,7 @@ public static FormBody.Builder toForm(ChatScheduleMessageRequest req) {
form.add("attachments", json);
}
setIfNotNull("link_names", req.isLinkNames(), form);
setIfNotNull("markdown_text", req.getMarkdownText(), form);
setIfNotNull("parse", req.getParse(), form);
setIfNotNull("reply_broadcast", req.isReplyBroadcast(), form);
setIfNotNull("thread_ts", req.getThreadTs(), form);
Expand All @@ -1554,6 +1556,7 @@ public static FormBody.Builder toForm(ChatPostEphemeralRequest req) {
warnIfEitherTextOrAttachmentFallbackIsMissing(
"chat.postEphemeral",
req.getText(),
req.getMarkdownText(),
req.getAttachments(),
req.getAttachmentsAsString());
FormBody.Builder form = new FormBody.Builder();
Expand Down Expand Up @@ -1583,6 +1586,7 @@ public static FormBody.Builder toForm(ChatPostEphemeralRequest req) {
setIfNotNull("icon_url", req.getIconUrl(), form);
setIfNotNull("username", req.getUsername(), form);
setIfNotNull("link_names", req.isLinkNames(), form);
setIfNotNull("markdown_text", req.getMarkdownText(), form);
setIfNotNull("parse", req.getParse(), form);
return form;
}
Expand All @@ -1591,6 +1595,7 @@ public static FormBody.Builder toForm(ChatPostMessageRequest req) {
warnIfEitherTextOrAttachmentFallbackIsMissing(
"chat.postMessage",
req.getText(),
req.getMarkdownText(),
req.getAttachments(),
req.getAttachmentsAsString());
FormBody.Builder form = new FormBody.Builder();
Expand All @@ -1599,6 +1604,7 @@ public static FormBody.Builder toForm(ChatPostMessageRequest req) {
setIfNotNull("text", req.getText(), form);
setIfNotNull("parse", req.getParse(), form);
setIfNotNull("link_names", req.isLinkNames(), form);
setIfNotNull("markdown_text", req.getMarkdownText(), form);
setIfNotNull("mrkdwn", req.isMrkdwn(), form);

if (req.getMetadataAsString() != null) {
Expand Down Expand Up @@ -1702,11 +1708,13 @@ public static FormBody.Builder toForm(ChatUpdateRequest req) {
warnIfEitherTextOrAttachmentFallbackIsMissing(
"chat.update",
req.getText(),
req.getMarkdownText(),
req.getAttachments(),
req.getAttachmentsAsString());
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("ts", req.getTs(), form);
setIfNotNull("channel", req.getChannel(), form);
setIfNotNull("markdown_text", req.getMarkdownText(), form);
setIfNotNull("text", req.getText(), form);
setIfNotNull("parse", req.getParse(), form);
setIfNotNull("link_names", req.isLinkNames(), form);
Expand Down Expand Up @@ -3153,6 +3161,7 @@ private static void warnIfAttachmentWithoutFallbackDetected(String endpointName,
private static void warnIfEitherTextOrAttachmentFallbackIsMissing(
String endpointName,
String text,
String markdownText,
List<Attachment> attachments,
String attachmentsAsString) {

Expand All @@ -3165,8 +3174,8 @@ private static void warnIfEitherTextOrAttachmentFallbackIsMissing(
endpointName,
Arrays.asList(GSON.fromJson(attachmentsAsString, Attachment[].class)));
} else {
// when attachments do not exist, the top-level text is always required
if (text == null || text.trim().isEmpty()) {
// when attachments do not exist, the top-level text or markdown_text is always required
if ((text == null || text.trim().isEmpty()) && (markdownText == null || markdownText.trim().isEmpty())) {
log.warn(TEXT_WARN_MESSAGE_TEMPLATE, endpointName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ public void setAsUser(Boolean asUser) {
*/
private boolean linkNames;

/**
* Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.
*/
private String markdownText;

/**
* Change how messages are treated. Defaults to `none`. See [below](#formatting).
*/
private String parse;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class ChatPostMessageRequest implements SlackApiRequest {
*/
private boolean linkNames;

/**
* Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.
*/
private String markdownText;

/**
* JSON object with event_type and event_payload fields, presented as a URL-encoded string.
* Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void setAsUser(Boolean asUser) {
*/
private boolean linkNames;

/**
* Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.
*/
private String markdownText;

/**
* Change how messages are treated. Defaults to none. See below.
*/
Expand Down Expand Up @@ -118,4 +123,4 @@ public void setAsUser(Boolean asUser) {
*/
private boolean unfurlMedia;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public void setAsUser(Boolean asUser) {
this.asUser = asUser;
}

/**
* Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.
*/
private String markdownText;

/**
* JSON object with event_type and event_payload fields, presented as a URL-encoded string.
* Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
Expand Down Expand Up @@ -124,4 +129,4 @@ public void setAsUser(Boolean asUser) {
*/
private String parse;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public void postMessage_user() throws Exception {
assertThat(scopes, is(notNullValue()));
}

@Test
public void postMessage_markdownText() throws Exception {
loadRandomChannelId();
ChatPostMessageResponse response = slack.methods(botToken).chatPostMessage(req -> req
.channel(randomChannelId)
.markdownText("**bold**"));
assertThat(response.getError(), is(nullValue()));
assertThat(response.getMessage().getText(), is("*bold*"));
}

// https://github.com/slackapi/java-slack-sdk/issues/157
@Test
public void postMessage_blocksInAttachment_do_not_work_bot() throws Exception {
Expand Down Expand Up @@ -781,6 +791,19 @@ public void unfurl_issue_399_flickr_example() throws Exception {
assertThat(unfurlResponse.getError(), is(nullValue()));
}

@Test
public void chatUpdate_markdownText() throws IOException, SlackApiException {
loadRandomChannelId();
ChatPostMessageResponse creation = slack.methods(botToken)
.chatPostMessage(r -> r.channel(randomChannelId).text("plain"));
assertThat(creation.getError(), is(nullValue()));
assertThat(creation.getMessage().getText(), is("plain"));
ChatUpdateResponse modified = slack.methods(botToken)
.chatUpdate(r -> r.channel(randomChannelId).markdownText("**bold**").ts(creation.getTs()));
assertThat(modified.getError(), is(nullValue()));
assertThat(modified.getMessage().getText(), is("*bold*"));
}

@Test
public void chatUpdateWithBotToken_issue_372() throws IOException, SlackApiException {
loadRandomChannelId();
Expand Down Expand Up @@ -988,6 +1011,17 @@ public void postEphemeral_authorship() throws Exception {
assertThat(response.getError(), is(nullValue()));
}

@Test
public void postEphemeral_markdownText() throws Exception {
loadRandomChannelId();
String userId = findUser();
ChatPostEphemeralResponse response = slack.methods(botToken).chatPostEphemeral(r -> r
.user(userId)
.channel(randomChannelId)
.markdownText("**bold**"));
assertThat(response.getError(), is(nullValue()));
}

private String findUser() throws IOException, SlackApiException {

String userId = null;
Expand Down Expand Up @@ -1043,10 +1077,15 @@ public void scheduleMessages() throws IOException, SlackApiException {
.blocks(blocks));
assertNull(message3.getError());

ChatScheduleMessageResponse message4 = slack.methods(botToken)
.chatScheduleMessage(r -> r.channel(randomChannelId).postAt(postAt)
.markdownText("**bold**"));
assertNull(message4.getError());

ChatScheduledMessagesListResponse after = slack.methods(botToken)
.chatScheduledMessagesList(r -> r.limit(100));
assertNull(after.getError());
assertTrue(after.getScheduledMessages().size() - before.getScheduledMessages().size() == 2);
assertTrue(after.getScheduledMessages().size() - before.getScheduledMessages().size() == 3);
}

@Test
Expand Down