|
| 1 | +package entity; |
| 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.entity.EntityPresentCommentsRequest; |
| 7 | +import com.slack.api.methods.response.entity.EntityPresentCommentsResponse; |
| 8 | +import com.slack.api.model.EntityComment; |
| 9 | +import com.slack.api.model.EntityMetadata; |
| 10 | +import com.slack.api.model.block.RichTextBlock; |
| 11 | +import com.slack.api.model.block.element.RichTextSectionElement; |
| 12 | +import java.io.IOException; |
| 13 | +import java.util.Arrays; |
| 14 | + |
| 15 | +public class EntityPresentComments { |
| 16 | + |
| 17 | + public static void main(String[] args) throws IOException, SlackApiException { |
| 18 | + // Read a token from an environment variable |
| 19 | + String token = System.getenv("SLACK_TOKEN"); |
| 20 | + |
| 21 | + // Initialize |
| 22 | + MethodsClient methods = Slack.getInstance().methods(token); |
| 23 | + |
| 24 | + // Call the entity.presentComments method |
| 25 | + EntityPresentCommentsRequest request = EntityPresentCommentsRequest.builder() |
| 26 | + .comments(Arrays.asList( |
| 27 | + EntityComment.builder() |
| 28 | + .sender(EntityMetadata.EntityPayload.User.builder() |
| 29 | + .userId("U123456789") |
| 30 | + .build()) |
| 31 | + .timestamp(1741164235) |
| 32 | + .id("comment-unique-identifier-001") |
| 33 | + .url("your.app/item/1/comment/1") |
| 34 | + .canEdit(true) |
| 35 | + .canDelete(true) |
| 36 | + .canReply(true) |
| 37 | + .replyCount(2) |
| 38 | + .replyUsers(Arrays.asList( |
| 39 | + EntityMetadata.EntityPayload.User.builder() |
| 40 | + .userId("U234567890") |
| 41 | + .build(), |
| 42 | + EntityMetadata.EntityPayload.User.builder() |
| 43 | + .text("External User") |
| 44 | + .icon(EntityMetadata.EntityPayload.Icon.builder() |
| 45 | + .url("...") |
| 46 | + .build()) |
| 47 | + .build())) |
| 48 | + .latestReplyTs(1741165000) |
| 49 | + .lastEditTs(1741164300) |
| 50 | + .comment(EntityComment.Content.builder() |
| 51 | + .blocks(RichTextBlock.builder() |
| 52 | + .elements(Arrays.asList(RichTextSectionElement.builder() |
| 53 | + .elements(Arrays.asList(RichTextSectionElement.Text.builder() |
| 54 | + .text( |
| 55 | + "Check out these different block types with paragraph breaks between them:\n\n") |
| 56 | + .build())) |
| 57 | + .build())) |
| 58 | + .build()) |
| 59 | + .build()) |
| 60 | + .build(), |
| 61 | + EntityComment.builder() |
| 62 | + .sender(EntityMetadata.EntityPayload.User.builder() |
| 63 | + .text("UserFirstName UserLastName") |
| 64 | + .icon(EntityMetadata.EntityPayload.Icon.builder() |
| 65 | + .altText("Summary of image's content") |
| 66 | + .url("...") |
| 67 | + .build()) |
| 68 | + .url("your.app/user/userId") |
| 69 | + .email("firstname.lastname@domain.com") |
| 70 | + .build()) |
| 71 | + .timestamp(1741164358) |
| 72 | + .id("comment-unique-identifier-002") |
| 73 | + .url("your.app/item/1/comment/2") |
| 74 | + .threadRootId("comment-unique-identifier-001") |
| 75 | + .comment(EntityComment.Content.builder() |
| 76 | + .value("Plain text comment") |
| 77 | + .format("markdown") |
| 78 | + .build()) |
| 79 | + .build())) |
| 80 | + .triggerId("1234567890123.1234567890123.abcdef01234567890abcdef012345689") |
| 81 | + .canPostComment(true) |
| 82 | + .deleteActionId("your-delete-action-id") |
| 83 | + .build(); |
| 84 | + EntityPresentCommentsResponse response = methods.entityPresentComments(request); |
| 85 | + |
| 86 | + // Inspect the response |
| 87 | + System.out.println(response); |
| 88 | + } |
| 89 | +} |
0 commit comments