Skip to content
Draft
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
12 changes: 12 additions & 0 deletions block-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
- **[Table](https://docs.slack.dev/reference/block-kit/blocks/table-block)**: Displays structured information in a table. [Implementation](./src/blocks/table.py).
- **[Task card](https://docs.slack.dev/reference/block-kit/blocks/task-card-block)**: Displays a single task, representing a single action. [Implementation](./src/blocks/task_card.py).
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.py).

### Composition objects

- **[Confirmation dialog](https://docs.slack.dev/reference/block-kit/composition-objects/confirmation-dialog-object)**: Defines a dialog that adds a confirmation step to interactive elements. [Implementation](./src/composition_objects/confirmation_dialog.py).
- **[Conversation filter](https://docs.slack.dev/reference/block-kit/composition-objects/conversation-filter-object)**: Defines a filter for the list of options in a conversation selector menu. [Implementation](./src/composition_objects/conversation_filter.py).
- **[Dispatch action configuration](https://docs.slack.dev/reference/block-kit/composition-objects/dispatch-action-configuration-object)**: Defines when a plain-text input element will return a block_actions interaction payload. [Implementation](./src/composition_objects/dispatch_action_configuration.py).
- **[Option](https://docs.slack.dev/reference/block-kit/composition-objects/option-object)**: Defines a single item in a number of item selection elements. [Implementation](./src/composition_objects/option.py).
- **[Option group](https://docs.slack.dev/reference/block-kit/composition-objects/option-group-object)**: Defines a way to group options in a menu. [Implementation](./src/composition_objects/option_group.py).
- **[Slack file](https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object)**: Defines an object containing Slack file information to be used in an image block or image element. [Implementation](./src/composition_objects/slack_file.py).
- **[Text](https://docs.slack.dev/reference/block-kit/composition-objects/text-object)**: Defines an object containing some text. [Implementation](./src/composition_objects/text.py).
- **[Trigger](https://docs.slack.dev/reference/block-kit/composition-objects/trigger-object)**: Defines an object containing trigger information. [Implementation](./src/composition_objects/trigger.py).
- **[Workflow](https://docs.slack.dev/reference/block-kit/composition-objects/workflow-object)**: Defines an object containing workflow information. [Implementation](./src/composition_objects/workflow.py).
Empty file.
39 changes: 39 additions & 0 deletions block-kit/src/composition_objects/confirmation_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from slack_sdk.models.blocks import ActionsBlock
from slack_sdk.models.blocks.basic_components import (
ConfirmObject,
MarkdownTextObject,
PlainTextObject,
)
from slack_sdk.models.blocks.block_elements import ButtonElement


def example01() -> ActionsBlock:
"""
Defines a dialog that adds a confirmation step to interactive elements.
https://docs.slack.dev/reference/block-kit/composition-objects/confirmation-dialog-object/

An actions block with a button that opens a confirmation dialog.
"""
block = ActionsBlock(
elements=[
ButtonElement(
text=PlainTextObject(text="Approve", emoji=True),
confirm=ConfirmObject(
title=PlainTextObject(text="Are you sure?"),
text=MarkdownTextObject(
text="Would you not prefer a good game of _chess_?"
),
confirm=PlainTextObject(text="Do it"),
deny=PlainTextObject(text="Stop, I changed my mind!"),
),
style="primary",
value="click_me_123",
),
ButtonElement(
text=PlainTextObject(text="Deny", emoji=True),
style="danger",
value="click_me_123",
),
],
)
return block
40 changes: 40 additions & 0 deletions block-kit/src/composition_objects/conversation_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from slack_sdk.models.blocks import InputBlock
from slack_sdk.models.blocks.basic_components import PlainTextObject
from slack_sdk.models.blocks.block_elements import (
ConversationFilter,
ConversationSelectElement,
)
from slack_sdk.models.views import View


def example01() -> View:
"""
Defines a filter for the list of options in a conversation selector menu.
https://docs.slack.dev/reference/block-kit/composition-objects/conversation-filter-object/

A modal view whose conversations select filters the listed conversations.
"""
view = View(
type="modal",
title=PlainTextObject(text="My App", emoji=True),
submit=PlainTextObject(text="Submit", emoji=True),
close=PlainTextObject(text="Cancel", emoji=True),
blocks=[
InputBlock(
element=ConversationSelectElement(
placeholder=PlainTextObject(
text="Select a conversation", emoji=True
),
filter=ConversationFilter(
include=["public", "mpim"],
exclude_bot_users=True,
),
),
label=PlainTextObject(
text="Choose the conversation to publish your result to:",
emoji=True,
),
),
],
)
return view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from slack_sdk.models.blocks import InputBlock
from slack_sdk.models.blocks.basic_components import (
DispatchActionConfig,
PlainTextObject,
)
from slack_sdk.models.blocks.block_elements import PlainTextInputElement


def example01() -> InputBlock:
"""
Defines when a plain-text input element will return a block_actions interaction payload.
https://docs.slack.dev/reference/block-kit/composition-objects/dispatch-action-configuration-object/

An input block whose plain-text input dispatches actions on character entry.
"""
block = InputBlock(
dispatch_action=True,
element=PlainTextInputElement(
multiline=True,
dispatch_action_config=DispatchActionConfig(
trigger_actions_on=["on_character_entered"],
),
),
label=PlainTextObject(text="This is a multiline plain-text input", emoji=True),
)
return block
56 changes: 56 additions & 0 deletions block-kit/src/composition_objects/option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from slack_sdk.models.blocks import Block, DividerBlock, SectionBlock
from slack_sdk.models.blocks.basic_components import (
MarkdownTextObject,
Option,
PlainTextObject,
)
from slack_sdk.models.blocks.block_elements import StaticSelectElement


def example01() -> Option:
"""
Defines a single item in a number of item selection elements.
https://docs.slack.dev/reference/block-kit/composition-objects/option-object/

A single option object.
"""
option = Option(
text=PlainTextObject(text="Save it", emoji=True),
value="value-2",
)
return option


def example02() -> list[Block]:
"""
Options used within a select menu accessory on a section block.
"""
blocks: list[Block] = [
SectionBlock(
text=MarkdownTextObject(text=":mag: Search results for *Cata*"),
),
DividerBlock(),
SectionBlock(
text=MarkdownTextObject(
text="*<fakeLink.toYourApp.com|Use Case Catalogue>*\nUse Case Catalogue for the following departments/roles..."
),
accessory=StaticSelectElement(
placeholder=PlainTextObject(text="Manage", emoji=True),
options=[
Option(
text=PlainTextObject(text="Edit it", emoji=True),
value="value-0",
),
Option(
text=PlainTextObject(text="Read it", emoji=True),
value="value-1",
),
Option(
text=PlainTextObject(text="Save it", emoji=True),
value="value-2",
),
],
),
),
]
return blocks
60 changes: 60 additions & 0 deletions block-kit/src/composition_objects/option_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from slack_sdk.models.blocks import Block, DividerBlock, SectionBlock
from slack_sdk.models.blocks.basic_components import (
MarkdownTextObject,
Option,
OptionGroup,
PlainTextObject,
)
from slack_sdk.models.blocks.block_elements import StaticSelectElement


def example01() -> list[Block]:
"""
Defines a way to group options in a menu.
https://docs.slack.dev/reference/block-kit/composition-objects/option-group-object/

Option groups used within a select menu accessory on a section block.
"""
blocks: list[Block] = [
SectionBlock(
text=MarkdownTextObject(text=":mag: Search results for *Cata*"),
),
DividerBlock(),
SectionBlock(
text=MarkdownTextObject(
text="*<fakeLink.toYourApp.com|Use Case Catalogue>*\nUse Case Catalogue for the following departments/roles..."
),
accessory=StaticSelectElement(
placeholder=PlainTextObject(text="Manage", emoji=True),
option_groups=[
OptionGroup(
label=PlainTextObject(text="Group 1"),
options=[
Option(
text=PlainTextObject(text="*this is plain_text text*"),
value="value-0",
),
Option(
text=PlainTextObject(text="*this is plain_text text*"),
value="value-1",
),
Option(
text=PlainTextObject(text="*this is plain_text text*"),
value="value-2",
),
],
),
OptionGroup(
label=PlainTextObject(text="Group 2"),
options=[
Option(
text=PlainTextObject(text="*this is plain_text text*"),
value="value-3",
),
],
),
],
),
),
]
return blocks
33 changes: 33 additions & 0 deletions block-kit/src/composition_objects/slack_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from slack_sdk.models.blocks import ImageBlock
from slack_sdk.models.blocks.basic_components import PlainTextObject, SlackFile


def example01() -> ImageBlock:
"""
Defines an object containing Slack file information to be used in an image block or image element.
https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object/

An image block referencing a Slack file by 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 example02() -> ImageBlock:
"""
An image block referencing a Slack file by 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/composition_objects/text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from slack_sdk.models.blocks import SectionBlock
from slack_sdk.models.blocks.basic_components import MarkdownTextObject


def example01() -> SectionBlock:
"""
Defines an object containing some text.
https://docs.slack.dev/reference/block-kit/composition-objects/text-object/

A section block containing an mrkdwn text object.
"""
block = SectionBlock(
text=MarkdownTextObject(
text="A message *with some bold text* and _some italicized text_."
)
)
return block
42 changes: 42 additions & 0 deletions block-kit/src/composition_objects/trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from slack_sdk.models.blocks import SectionBlock
from slack_sdk.models.blocks.basic_components import (
MarkdownTextObject,
PlainTextObject,
Workflow,
WorkflowTrigger,
)
from slack_sdk.models.blocks.block_elements import WorkflowButtonElement


def example01() -> SectionBlock:
"""
Defines an object containing trigger information.
https://docs.slack.dev/reference/block-kit/composition-objects/trigger-object/

A workflow button whose trigger carries a URL and customizable inputs.
"""
block = SectionBlock(
text=MarkdownTextObject(
text="A message *with some bold text* and _some italicized text_."
),
accessory=WorkflowButtonElement(
text=PlainTextObject(text="Run Workflow"),
action_id="workflowbutton123",
workflow=Workflow(
trigger=WorkflowTrigger(
url="https://slack.com/shortcuts/Ft0123ABC456/xyz...zyx",
customizable_input_parameters=[
{
"name": "input_parameter_a",
"value": "Value for input param A",
},
{
"name": "input_parameter_b",
"value": "Value for input param B",
},
],
),
),
),
)
return block
42 changes: 42 additions & 0 deletions block-kit/src/composition_objects/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from slack_sdk.models.blocks import SectionBlock
from slack_sdk.models.blocks.basic_components import (
MarkdownTextObject,
PlainTextObject,
Workflow,
WorkflowTrigger,
)
from slack_sdk.models.blocks.block_elements import WorkflowButtonElement


def example01() -> SectionBlock:
"""
Defines an object containing workflow information.
https://docs.slack.dev/reference/block-kit/composition-objects/workflow-object/

A workflow button whose workflow references a configured trigger.
"""
block = SectionBlock(
text=MarkdownTextObject(
text="A message *with some bold text* and _some italicized text_."
),
accessory=WorkflowButtonElement(
text=PlainTextObject(text="Run Workflow"),
action_id="workflowbutton123",
workflow=Workflow(
trigger=WorkflowTrigger(
url="https://slack.com/shortcuts/Ft0123ABC456/xyz...zyx",
customizable_input_parameters=[
{
"name": "input_parameter_a",
"value": "Value for input param A",
},
{
"name": "input_parameter_b",
"value": "Value for input param B",
},
],
),
),
),
)
return block
Loading