Skip to content

Commit 9927cad

Browse files
authored
feat(block-kit): add examples of released blocks (#4)
1 parent 1ec94f4 commit 9927cad

24 files changed

+1338
-7
lines changed

block-kit/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
99
### Blocks
1010

1111
- **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py).
12+
- **[Context actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Holds interactive elements like feedback buttons and icon buttons. [Implementation](./src/blocks/context_actions.py).
13+
- **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/blocks/context.py).
14+
- **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/blocks/divider.py).
15+
- **[File](https://docs.slack.dev/reference/block-kit/blocks/file-block)**: Displays info about remote files. [Implementation](./src/blocks/file.py).
16+
- **[Header](https://docs.slack.dev/reference/block-kit/blocks/header-block)**: Displays a larger-sized text. [Implementation](./src/blocks/header.py).
17+
- **[Image](https://docs.slack.dev/reference/block-kit/blocks/image-block)**: Displays an image. [Implementation](./src/blocks/image.py).
18+
- **[Input](https://docs.slack.dev/reference/block-kit/blocks/input-block)**: Collects information from users via elements. [Implementation](./src/blocks/input.py).
19+
- **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/blocks/markdown.py).
20+
- **[Rich text](https://docs.slack.dev/reference/block-kit/blocks/rich-text-block)**: Displays formatted, structured representation of text. [Implementation](./src/blocks/rich_text.py).
21+
- **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/blocks/section.py).
22+
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.py).

block-kit/src/blocks/context.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from slack_sdk.models.blocks import ContextBlock, ImageElement, MarkdownTextObject
2+
3+
4+
def example01() -> ContextBlock:
5+
"""
6+
Provides contextual info, which can include both images and text.
7+
https://docs.slack.dev/reference/block-kit/blocks/context-block/
8+
9+
A context block with an image and text.
10+
"""
11+
block = ContextBlock(
12+
elements=[
13+
ImageElement(
14+
image_url="https://image.freepik.com/free-photo/red-drawing-pin_1156-445.jpg",
15+
alt_text="images",
16+
),
17+
MarkdownTextObject(text="Location: **Dogpatch**"),
18+
]
19+
)
20+
return block
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from slack_sdk.models.blocks import ContextActionsBlock
2+
from slack_sdk.models.blocks.basic_components import (
3+
FeedbackButtonObject,
4+
PlainTextObject,
5+
)
6+
from slack_sdk.models.blocks.block_elements import (
7+
FeedbackButtonsElement,
8+
IconButtonElement,
9+
)
10+
11+
12+
def example01() -> ContextActionsBlock:
13+
"""
14+
Holds interactive elements like feedback buttons and icon buttons.
15+
https://docs.slack.dev/reference/block-kit/blocks/context-actions-block/
16+
17+
Context actions block with feedback buttons.
18+
"""
19+
block = ContextActionsBlock(
20+
elements=[
21+
FeedbackButtonsElement(
22+
action_id="feedback_buttons_1",
23+
positive_button=FeedbackButtonObject(
24+
text=PlainTextObject(text="👍"),
25+
value="positive_feedback",
26+
),
27+
negative_button=FeedbackButtonObject(
28+
text=PlainTextObject(text="👎"),
29+
value="negative_feedback",
30+
),
31+
),
32+
],
33+
)
34+
return block
35+
36+
37+
def example02() -> ContextActionsBlock:
38+
"""
39+
Context actions block with an icon button.
40+
"""
41+
block = ContextActionsBlock(
42+
elements=[
43+
IconButtonElement(
44+
icon="trash",
45+
text=PlainTextObject(text="Delete"),
46+
action_id="delete_button_1",
47+
value="delete_item",
48+
),
49+
],
50+
)
51+
return block

block-kit/src/blocks/divider.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from slack_sdk.models.blocks import DividerBlock
2+
3+
4+
def example01() -> DividerBlock:
5+
"""
6+
Visually separates pieces of info inside of a message.
7+
https://docs.slack.dev/reference/block-kit/blocks/divider-block/
8+
9+
A simple divider block.
10+
"""
11+
block = DividerBlock()
12+
return block

block-kit/src/blocks/file.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from slack_sdk.models.blocks import FileBlock
2+
3+
4+
def example01() -> FileBlock:
5+
"""
6+
Displays info about remote files.
7+
https://docs.slack.dev/reference/block-kit/blocks/file-block/
8+
9+
A file block for a remote file.
10+
"""
11+
block = FileBlock(external_id="ABCD1", source="remote")
12+
return block

block-kit/src/blocks/header.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from slack_sdk.models.blocks import HeaderBlock
2+
from slack_sdk.models.blocks.basic_components import PlainTextObject
3+
4+
5+
def example01() -> HeaderBlock:
6+
"""
7+
Displays a larger-sized text.
8+
https://docs.slack.dev/reference/block-kit/blocks/header-block/
9+
10+
A simple header block.
11+
"""
12+
block = HeaderBlock(text=PlainTextObject(text="A Heartfelt Header"))
13+
return block

block-kit/src/blocks/image.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from slack_sdk.models.blocks import ImageBlock
2+
from slack_sdk.models.blocks.basic_components import PlainTextObject, SlackFile
3+
4+
5+
def example01() -> ImageBlock:
6+
"""
7+
Displays an image.
8+
https://docs.slack.dev/reference/block-kit/blocks/image-block/
9+
10+
An image block using image_url.
11+
"""
12+
block = ImageBlock(
13+
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
14+
block_id="image4",
15+
image_url="http://placekitten.com/500/500",
16+
alt_text="An incredibly cute kitten.",
17+
)
18+
return block
19+
20+
21+
def example02() -> ImageBlock:
22+
"""
23+
An image block using slack_file with a url.
24+
"""
25+
block = ImageBlock(
26+
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
27+
block_id="image4",
28+
slack_file=SlackFile(
29+
url="https://files.slack.com/files-pri/T0123456-F0123456/xyz.png"
30+
),
31+
alt_text="An incredibly cute kitten.",
32+
)
33+
return block
34+
35+
36+
def example03() -> ImageBlock:
37+
"""
38+
An image block using slack_file with an id.
39+
"""
40+
block = ImageBlock(
41+
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
42+
block_id="image4",
43+
slack_file=SlackFile(id="F0123456"),
44+
alt_text="An incredibly cute kitten.",
45+
)
46+
return block

block-kit/src/blocks/input.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from slack_sdk.models.blocks import InputBlock
2+
from slack_sdk.models.blocks.basic_components import PlainTextObject
3+
from slack_sdk.models.blocks.block_elements import PlainTextInputElement
4+
5+
6+
def example01() -> InputBlock:
7+
"""
8+
Collects information from users via elements.
9+
https://docs.slack.dev/reference/block-kit/blocks/input-block/
10+
11+
An input block containing a plain-text input element.
12+
"""
13+
block = InputBlock(
14+
element=PlainTextInputElement(),
15+
label=PlainTextObject(text="Label", emoji=True),
16+
)
17+
return block

block-kit/src/blocks/markdown.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from slack_sdk.models.blocks import MarkdownBlock
2+
3+
4+
def example01() -> MarkdownBlock:
5+
"""
6+
Displays formatted markdown.
7+
https://docs.slack.dev/reference/block-kit/blocks/markdown-block/
8+
9+
A markdown block.
10+
"""
11+
block = MarkdownBlock(text="**Lots of information here!!**")
12+
return block

0 commit comments

Comments
 (0)