Skip to content

Commit e6079cd

Browse files
authored
Fix #346 Allow unfurl_media / unfurl_links in ack / respond (#363)
1 parent 3622b68 commit e6079cd

File tree

15 files changed

+97
-0
lines changed

15 files changed

+97
-0
lines changed

slack_bolt/context/ack/ack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def __call__(
1919
text: Union[str, dict] = "", # text: str or whole_response: dict
2020
blocks: Optional[Sequence[Union[dict, Block]]] = None,
2121
attachments: Optional[Sequence[Union[dict, Attachment]]] = None,
22+
unfurl_links: Optional[bool] = None,
23+
unfurl_media: Optional[bool] = None,
2224
response_type: Optional[str] = None, # in_channel / ephemeral
2325
# block_suggestion / dialog_suggestion
2426
options: Optional[Sequence[Union[dict, Option]]] = None,
@@ -33,6 +35,8 @@ def __call__(
3335
text_or_whole_response=text,
3436
blocks=blocks,
3537
attachments=attachments,
38+
unfurl_links=unfurl_links,
39+
unfurl_media=unfurl_media,
3640
response_type=response_type,
3741
options=options,
3842
option_groups=option_groups,

slack_bolt/context/ack/async_ack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ async def __call__(
1919
text: Union[str, dict] = "", # text: str or whole_response: dict
2020
blocks: Optional[Sequence[Union[dict, Block]]] = None,
2121
attachments: Optional[Sequence[Union[dict, Attachment]]] = None,
22+
unfurl_links: Optional[bool] = None,
23+
unfurl_media: Optional[bool] = None,
2224
response_type: Optional[str] = None, # in_channel / ephemeral
2325
# block_suggestion / dialog_suggestion
2426
options: Optional[Sequence[Union[dict, Option]]] = None,
@@ -33,6 +35,8 @@ async def __call__(
3335
text_or_whole_response=text,
3436
blocks=blocks,
3537
attachments=attachments,
38+
unfurl_links=unfurl_links,
39+
unfurl_media=unfurl_media,
3640
response_type=response_type,
3741
options=options,
3842
option_groups=option_groups,

slack_bolt/context/ack/internals.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def _set_response(
1414
text_or_whole_response: Union[str, dict] = "",
1515
blocks: Optional[Sequence[Union[dict, Block]]] = None,
1616
attachments: Optional[Sequence[Union[dict, Attachment]]] = None,
17+
unfurl_links: Optional[bool] = None,
18+
unfurl_media: Optional[bool] = None,
1719
response_type: Optional[str] = None, # in_channel / ephemeral
1820
# block_suggestion / dialog_suggestion
1921
options: Optional[Sequence[Union[dict, Option]]] = None,
@@ -28,6 +30,10 @@ def _set_response(
2830
body = {"text": text}
2931
if response_type:
3032
body["response_type"] = response_type
33+
if unfurl_links is not None:
34+
body["unfurl_links"] = unfurl_links
35+
if unfurl_media is not None:
36+
body["unfurl_media"] = unfurl_media
3137
if attachments and len(attachments) > 0:
3238
body.update(
3339
{"text": text, "attachments": convert_to_dict_list(attachments)}

slack_bolt/context/respond/async_respond.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ async def __call__(
2121
response_type: Optional[str] = None,
2222
replace_original: Optional[bool] = None,
2323
delete_original: Optional[bool] = None,
24+
unfurl_links: Optional[bool] = None,
25+
unfurl_media: Optional[bool] = None,
2426
) -> WebhookResponse:
2527
if self.response_url is not None:
2628
client = AsyncWebhookClient(self.response_url)
@@ -33,6 +35,8 @@ async def __call__(
3335
response_type=response_type,
3436
replace_original=replace_original,
3537
delete_original=delete_original,
38+
unfurl_links=unfurl_links,
39+
unfurl_media=unfurl_media,
3640
)
3741
return await client.send_dict(message)
3842
elif isinstance(text_or_whole_response, dict):

slack_bolt/context/respond/internals.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def _build_message(
1313
response_type: Optional[str] = None,
1414
replace_original: Optional[bool] = None,
1515
delete_original: Optional[bool] = None,
16+
unfurl_links: Optional[bool] = None,
17+
unfurl_media: Optional[bool] = None,
1618
) -> Dict[str, Any]:
1719
message = {"text": text}
1820
if blocks is not None and len(blocks) > 0:
@@ -25,4 +27,8 @@ def _build_message(
2527
message["replace_original"] = replace_original
2628
if delete_original is not None:
2729
message["delete_original"] = delete_original
30+
if unfurl_links is not None:
31+
message["unfurl_links"] = unfurl_links
32+
if unfurl_media is not None:
33+
message["unfurl_media"] = unfurl_media
2834
return message

slack_bolt/context/respond/respond.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def __call__(
2121
response_type: Optional[str] = None,
2222
replace_original: Optional[bool] = None,
2323
delete_original: Optional[bool] = None,
24+
unfurl_links: Optional[bool] = None,
25+
unfurl_media: Optional[bool] = None,
2426
) -> WebhookResponse:
2527
if self.response_url is not None:
2628
client = WebhookClient(self.response_url)
@@ -34,6 +36,8 @@ def __call__(
3436
response_type=response_type,
3537
replace_original=replace_original,
3638
delete_original=delete_original,
39+
unfurl_links=unfurl_links,
40+
unfurl_media=unfurl_media,
3741
)
3842
return client.send_dict(message)
3943
elif isinstance(text_or_whole_response, dict):

slack_bolt/context/say/async_say.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ async def __call__(
2626
attachments: Optional[Sequence[Union[Dict, Attachment]]] = None,
2727
channel: Optional[str] = None,
2828
thread_ts: Optional[str] = None,
29+
unfurl_links: Optional[bool] = None,
30+
unfurl_media: Optional[bool] = None,
2931
**kwargs,
3032
) -> AsyncSlackResponse:
3133
if _can_say(self, channel):
@@ -38,6 +40,8 @@ async def __call__(
3840
blocks=blocks,
3941
attachments=attachments,
4042
thread_ts=thread_ts,
43+
unfurl_links=unfurl_links,
44+
unfurl_media=unfurl_media,
4145
**kwargs,
4246
)
4347
elif isinstance(text_or_whole_response, dict):

slack_bolt/context/say/say.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __call__(
2727
attachments: Optional[Sequence[Union[Dict, Attachment]]] = None,
2828
channel: Optional[str] = None,
2929
thread_ts: Optional[str] = None,
30+
unfurl_links: Optional[bool] = None,
31+
unfurl_media: Optional[bool] = None,
3032
**kwargs,
3133
) -> SlackResponse:
3234
if _can_say(self, channel):
@@ -39,6 +41,8 @@ def __call__(
3941
blocks=blocks,
4042
attachments=attachments,
4143
thread_ts=thread_ts,
44+
unfurl_links=unfurl_links,
45+
unfurl_media=unfurl_media,
4246
**kwargs,
4347
)
4448
elif isinstance(text_or_whole_response, dict):

tests/slack_bolt/context/test_ack.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ def test_blocks(self):
5454
'{"text": "foo", "blocks": [{"type": "divider"}]}',
5555
)
5656

57+
def test_unfurl_options(self):
58+
ack = Ack()
59+
response: BoltResponse = ack(
60+
text="foo",
61+
blocks=[{"type": "divider"}],
62+
unfurl_links=True,
63+
unfurl_media=True,
64+
)
65+
assert (response.status, response.body) == (
66+
200,
67+
'{"text": "foo", "unfurl_links": true, "unfurl_media": true, "blocks": [{"type": "divider"}]}',
68+
)
69+
5770
sample_options = [{"text": {"type": "plain_text", "text": "Maru"}, "value": "maru"}]
5871

5972
def test_options(self):

tests/slack_bolt/context/test_respond.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ def test_respond2(self):
2323
respond = Respond(response_url=response_url)
2424
response = respond({"text": "Hi there!"})
2525
assert response.status_code == 200
26+
27+
def test_unfurl_options(self):
28+
response_url = "http://localhost:8888"
29+
respond = Respond(response_url=response_url)
30+
response = respond(text="Hi there!", unfurl_media=True, unfurl_links=True)
31+
assert response.status_code == 200

0 commit comments

Comments
 (0)