File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from slack_sdk .models .blocks import RichTextBlock , TaskCardBlock
2+ from slack_sdk .models .blocks .block_elements import (
3+ RichTextElementParts ,
4+ RichTextSectionElement ,
5+ UrlSourceElement ,
6+ )
7+
8+
9+ def example01 () -> TaskCardBlock :
10+ """
11+ Displays a single task which represents a single action.
12+ This is an experimental block type that requires a toggle to preview.
13+ https://docs.slack.dev/reference/block-kit/blocks/task-card-block/
14+
15+ A task card with output and sources.
16+ """
17+ block = TaskCardBlock (
18+ task_id = "task_1" ,
19+ title = "Fetching weather data" ,
20+ status = "pending" ,
21+ output = RichTextBlock (
22+ elements = [
23+ RichTextSectionElement (
24+ elements = [
25+ RichTextElementParts .Text (
26+ text = "Found weather data for Chicago from 2 sources"
27+ )
28+ ]
29+ )
30+ ]
31+ ),
32+ sources = [
33+ UrlSourceElement (
34+ url = "https://weather.com/" ,
35+ text = "weather.com" ,
36+ ),
37+ UrlSourceElement (
38+ url = "https://www.accuweather.com/" ,
39+ text = "accuweather.com" ,
40+ ),
41+ ],
42+ )
43+ return block
Original file line number Diff line number Diff line change 1+ import json
2+
3+ from src .blocks import task_card
4+
5+
6+ def test_example01 ():
7+ block = task_card .example01 ()
8+ actual = block .to_dict ()
9+ expected = {
10+ "type" : "task_card" ,
11+ "task_id" : "task_1" ,
12+ "title" : "Fetching weather data" ,
13+ "status" : "pending" ,
14+ "output" : {
15+ "type" : "rich_text" ,
16+ "elements" : [
17+ {
18+ "type" : "rich_text_section" ,
19+ "elements" : [
20+ {
21+ "type" : "text" ,
22+ "text" : "Found weather data for Chicago from 2 sources" ,
23+ }
24+ ],
25+ }
26+ ],
27+ },
28+ "sources" : [
29+ {
30+ "type" : "url" ,
31+ "url" : "https://weather.com/" ,
32+ "text" : "weather.com" ,
33+ },
34+ {
35+ "type" : "url" ,
36+ "url" : "https://www.accuweather.com/" ,
37+ "text" : "accuweather.com" ,
38+ },
39+ ],
40+ }
41+ assert json .dumps (actual , sort_keys = True ) == json .dumps (expected , sort_keys = True )
You can’t perform that action at this time.
0 commit comments