Skip to content

feat(model): add TaskCardBlock and UrlSourceElement - #1638

Merged
srtaalej merged 4 commits into
mainfrom
feat/block-kit-task-card
Sep 1, 2026
Merged

feat(model): add TaskCardBlock and UrlSourceElement#1638
srtaalej merged 4 commits into
mainfrom
feat/block-kit-task-card

Conversation

@srtaalej

@srtaalej srtaalej commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds TaskCardBlock layout block (task_card type) with all fields from docs
  • Adds UrlSourceElement for the sources field
  • Registers in GsonLayoutBlockFactory, adds Blocks.taskCard() helper
  • Includes parse and build tests in BlockKitTest and BlocksTest

Fields

Field Type Required
type "task_card" yes
task_id String yes
title String yes
status String (in_progress, complete, error) yes
details RichTextBlock no
output RichTextBlock no
sources List<UrlSourceElement> no
block_id String no
icon SlackIconObject no
hide_title Boolean no

Note: The docs example uses "pending" as a status value, but the API rejects it with invalid_blocks. Only in_progress, complete, and error are accepted.

Example usage

import static com.slack.api.model.block.Blocks.*;

var blocks = asBlocks(
    taskCard(t -> t
        .taskId("task_1")
        .title("Fetching weather data")
        .status("complete")
        .output(RichTextBlock.builder()
            .elements(Arrays.asList(
                RichTextSectionElement.builder()
                    .elements(Arrays.asList(
                        RichTextSectionElement.Text.builder()
                            .text("Found weather data for Chicago from 2 sources")
                            .build()
                    ))
                    .build()
            ))
            .build())
        .sources(Arrays.asList(
            UrlSourceElement.builder().url("https://weather.com/").text("weather.com").build(),
            UrlSourceElement.builder().url("https://www.accuweather.com/").text("accuweather.com").build()
        ))
    ),
    taskCard(t -> t
        .taskId("task_2")
        .title("Analyzing results")
        .status("in_progress")
    ),
    taskCard(t -> t
        .taskId("task_3")
        .title("Send notification")
        .status("error")
        .hideTitle(true)
        .output(RichTextBlock.builder()
            .elements(Arrays.asList(
                RichTextSectionElement.builder()
                    .elements(Arrays.asList(
                        RichTextSectionElement.Text.builder()
                            .text("Failed to reach notification service")
                            .build()
                    ))
                    .build()
            ))
            .build())
    )
);

Test plan

  • parseTaskCardBlock — deserializes JSON from docs example
  • buildTaskCardBlock — constructs via Blocks.taskCard() helper
  • testTaskCard — static helper test in BlocksTest
  • Tested in Slack UI via Socket Mode app with chatPostMessage

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.84%. Comparing base (e30ba9d) to head (f6aad3a).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...om/slack/api/util/json/GsonLayoutBlockFactory.java 75.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1638   +/-   ##
=========================================
  Coverage     72.84%   72.84%           
- Complexity     4533     4535    +2     
=========================================
  Files           482      482           
  Lines         14423    14425    +2     
  Branches       1512     1512           
=========================================
+ Hits          10506    10508    +2     
  Misses         3022     3022           
  Partials        895      895           
Flag Coverage Δ
jdk-14 72.84% <76.92%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@srtaalej srtaalej self-assigned this Aug 28, 2026
@srtaalej srtaalej added enhancement M-T: A feature request for new functionality project:slack-api-model project:slack-api-model semver:minor labels Aug 28, 2026
@srtaalej
srtaalej marked this pull request as ready for review August 28, 2026 20:54
@srtaalej
srtaalej requested a review from a team as a code owner August 28, 2026 20:54

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@srtaalej LGTM 🌞 Before merging it'd be nice to compile against a changeset in slack-samples/bolt-java-examples to exercise publishing steps onward! I suggest this to build confidence against odd edges that a packaged version sometimes bring. 🎁

🧮 Other comments I leave are around unordered entries but this isn't introduced in this PR so please feel free to ignore rambles.

Comment on lines +120 to +123
@Test
public void testTaskCard() {
assertThat(taskCard(t -> t.taskId("task_1").title("Do thing").status("complete")), is(notNullValue()));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🧮 suggestion: Can we move this toward alphabetical order? A follow up change can reorganize the file but I hope to steer this toward a standard now!

Comment on lines +70 to +71
case TaskCardBlock.TYPE:
return TaskCardBlock.class;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🎲 note: Similar suggestion to alphabetical ordering but no blocker if this is a significant change!

Comment on lines +26 to +27
private RichTextBlock details;
private RichTextBlock output;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💸 praise: Nice!

Comment thread slack-api-model/src/test/java/test_locally/api/model/block/BlockKitTest.java Outdated
@srtaalej

srtaalej commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

update ⏰ ! changes have been validated against bolt-java-examples and work 😸 merging now 🚀

@srtaalej
srtaalej merged commit db74fe5 into main Sep 1, 2026
7 checks passed
@srtaalej
srtaalej deleted the feat/block-kit-task-card branch September 1, 2026 19:08
@zimeg zimeg added this to the 1.51.1 milestone Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality project:slack-api-model project:slack-api-model semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants