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
11 changes: 11 additions & 0 deletions block-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
### Blocks

- **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py).
- **[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).
- **[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).
- **[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).
- **[File](https://docs.slack.dev/reference/block-kit/blocks/file-block)**: Displays info about remote files. [Implementation](./src/blocks/file.py).
- **[Header](https://docs.slack.dev/reference/block-kit/blocks/header-block)**: Displays a larger-sized text. [Implementation](./src/blocks/header.py).
- **[Image](https://docs.slack.dev/reference/block-kit/blocks/image-block)**: Displays an image. [Implementation](./src/blocks/image.py).
- **[Input](https://docs.slack.dev/reference/block-kit/blocks/input-block)**: Collects information from users via elements. [Implementation](./src/blocks/input.py).
- **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/blocks/markdown.py).
- **[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).
- **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/blocks/section.py).
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.py).
20 changes: 20 additions & 0 deletions block-kit/src/blocks/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from slack_sdk.models.blocks import ContextBlock, ImageElement, MarkdownTextObject


def example01() -> ContextBlock:
"""
Provides contextual info, which can include both images and text.
https://docs.slack.dev/reference/block-kit/blocks/context-block/

A context block with an image and text.
"""
block = ContextBlock(
elements=[
ImageElement(
image_url="https://image.freepik.com/free-photo/red-drawing-pin_1156-445.jpg",
alt_text="images",
),
MarkdownTextObject(text="Location: **Dogpatch**"),
]
)
return block
51 changes: 51 additions & 0 deletions block-kit/src/blocks/context_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from slack_sdk.models.blocks import ContextActionsBlock
from slack_sdk.models.blocks.basic_components import (
FeedbackButtonObject,
PlainTextObject,
)
from slack_sdk.models.blocks.block_elements import (
FeedbackButtonsElement,
IconButtonElement,
)


def example01() -> ContextActionsBlock:
"""
Holds interactive elements like feedback buttons and icon buttons.
https://docs.slack.dev/reference/block-kit/blocks/context-actions-block/

Context actions block with feedback buttons.
"""
block = ContextActionsBlock(
elements=[
FeedbackButtonsElement(
action_id="feedback_buttons_1",
positive_button=FeedbackButtonObject(
text=PlainTextObject(text="👍"),
value="positive_feedback",
),
negative_button=FeedbackButtonObject(
text=PlainTextObject(text="👎"),
value="negative_feedback",
),
),
],
)
return block


def example02() -> ContextActionsBlock:
"""
Context actions block with an icon button.
"""
block = ContextActionsBlock(
elements=[
IconButtonElement(
icon="trash",
text=PlainTextObject(text="Delete"),
action_id="delete_button_1",
value="delete_item",
),
],
)
return block
12 changes: 12 additions & 0 deletions block-kit/src/blocks/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from slack_sdk.models.blocks import DividerBlock


def example01() -> DividerBlock:
"""
Visually separates pieces of info inside of a message.
https://docs.slack.dev/reference/block-kit/blocks/divider-block/

A simple divider block.
"""
block = DividerBlock()
return block
12 changes: 12 additions & 0 deletions block-kit/src/blocks/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from slack_sdk.models.blocks import FileBlock


def example01() -> FileBlock:
"""
Displays info about remote files.
https://docs.slack.dev/reference/block-kit/blocks/file-block/

A file block for a remote file.
"""
block = FileBlock(external_id="ABCD1", source="remote")
return block
13 changes: 13 additions & 0 deletions block-kit/src/blocks/header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from slack_sdk.models.blocks import HeaderBlock
from slack_sdk.models.blocks.basic_components import PlainTextObject


def example01() -> HeaderBlock:
"""
Displays a larger-sized text.
https://docs.slack.dev/reference/block-kit/blocks/header-block/

A simple header block.
"""
block = HeaderBlock(text=PlainTextObject(text="A Heartfelt Header"))
return block
46 changes: 46 additions & 0 deletions block-kit/src/blocks/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from slack_sdk.models.blocks import ImageBlock
from slack_sdk.models.blocks.basic_components import PlainTextObject, SlackFile


def example01() -> ImageBlock:
"""
Displays an image.
https://docs.slack.dev/reference/block-kit/blocks/image-block/

An image block using image_url.
"""
block = ImageBlock(
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
block_id="image4",
image_url="http://placekitten.com/500/500",
alt_text="An incredibly cute kitten.",
)
return block


def example02() -> ImageBlock:
"""
An image block using slack_file with a url.
"""
block = ImageBlock(
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
block_id="image4",
slack_file=SlackFile(
url="https://files.slack.com/files-pri/T0123456-F0123456/xyz.png"
),
alt_text="An incredibly cute kitten.",
)
return block


def example03() -> ImageBlock:
"""
An image block using slack_file with an id.
"""
block = ImageBlock(
title=PlainTextObject(text="Please enjoy this photo of a kitten"),
block_id="image4",
slack_file=SlackFile(id="F0123456"),
alt_text="An incredibly cute kitten.",
)
return block
17 changes: 17 additions & 0 deletions block-kit/src/blocks/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from slack_sdk.models.blocks import InputBlock
from slack_sdk.models.blocks.basic_components import PlainTextObject
from slack_sdk.models.blocks.block_elements import PlainTextInputElement


def example01() -> InputBlock:
"""
Collects information from users via elements.
https://docs.slack.dev/reference/block-kit/blocks/input-block/

An input block containing a plain-text input element.
"""
block = InputBlock(
element=PlainTextInputElement(),
label=PlainTextObject(text="Label", emoji=True),
)
return block
12 changes: 12 additions & 0 deletions block-kit/src/blocks/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from slack_sdk.models.blocks import MarkdownBlock


def example01() -> MarkdownBlock:
"""
Displays formatted markdown.
https://docs.slack.dev/reference/block-kit/blocks/markdown-block/

A markdown block.
"""
block = MarkdownBlock(text="**Lots of information here!!**")
return block
Loading