Skip to content

Commit 636cbc0

Browse files
committed
Add fallback argument in BlockAttachment
1 parent 0ac8a0b commit 636cbc0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

slack_sdk/models/attachments/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,33 @@ def to_dict(self) -> dict: # skipcq: PYL-W0221
433433

434434

435435
class BlockAttachment(Attachment):
436-
attributes = {"color"}
437436
blocks: List[Block]
438437

439-
def __init__(self, *, blocks: Sequence[Block], color: Optional[str] = None):
438+
@property
439+
def attributes(self):
440+
return super().attributes.union({"blocks", "color"})
441+
442+
def __init__(
443+
self,
444+
*,
445+
blocks: Sequence[Block],
446+
color: Optional[str] = None,
447+
fallback: Optional[str] = None,
448+
):
440449
"""
441-
A bridge between legacy attachments and blockkit formatting - pass a list of
450+
A bridge between legacy attachments and Block Kit formatting - pass a list of
442451
Block objects directly to this attachment.
443452
444453
https://api.slack.com/reference/messaging/attachments#fields
445454
446455
Args:
447456
blocks: a sequence of Block objects
448-
449457
color: Changes the color of the border on the left side of this
450458
attachment from the default gray. Can either be one of "good" (green),
451459
"warning" (yellow), "danger" (red), or any hex color code (eg. #439FE0)
460+
fallback: fallback text
452461
"""
453-
super().__init__(text="", color=color)
462+
super().__init__(text="", fallback=fallback, color=color)
454463
self.blocks = list(blocks)
455464

456465
@JsonValidator("fields attribute cannot be populated on BlockAttachment")

tests/web/classes/test_attachments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,6 @@ def test_basic_json(self):
218218
]
219219

220220
self.assertDictEqual(
221-
BlockAttachment(blocks=blocks).to_dict(),
222-
{"blocks": [b.to_dict() for b in blocks]},
221+
BlockAttachment(fallback="foo", blocks=blocks).to_dict(),
222+
{"fallback": "foo", "blocks": [b.to_dict() for b in blocks]},
223223
)

0 commit comments

Comments
 (0)