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
19 changes: 14 additions & 5 deletions slack_sdk/models/attachments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,33 @@ def to_dict(self) -> dict: # skipcq: PYL-W0221


class BlockAttachment(Attachment):
attributes = {"color"}
blocks: List[Block]

def __init__(self, *, blocks: Sequence[Block], color: Optional[str] = None):
@property
def attributes(self):
return super().attributes.union({"blocks", "color"})

def __init__(
self,
*,
blocks: Sequence[Block],
color: Optional[str] = None,
fallback: Optional[str] = None,
):
"""
A bridge between legacy attachments and blockkit formatting - pass a list of
A bridge between legacy attachments and Block Kit formatting - pass a list of
Block objects directly to this attachment.

https://api.slack.com/reference/messaging/attachments#fields

Args:
blocks: a sequence of Block objects

color: Changes the color of the border on the left side of this
attachment from the default gray. Can either be one of "good" (green),
"warning" (yellow), "danger" (red), or any hex color code (eg. #439FE0)
fallback: fallback text
"""
super().__init__(text="", color=color)
super().__init__(text="", fallback=fallback, color=color)
self.blocks = list(blocks)

@JsonValidator("fields attribute cannot be populated on BlockAttachment")
Expand Down
4 changes: 2 additions & 2 deletions tests/web/classes/test_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,6 @@ def test_basic_json(self):
]

self.assertDictEqual(
BlockAttachment(blocks=blocks).to_dict(),
{"blocks": [b.to_dict() for b in blocks]},
BlockAttachment(fallback="foo", blocks=blocks).to_dict(),
{"fallback": "foo", "blocks": [b.to_dict() for b in blocks]},
)