Skip to content

Commit 5d1ebb5

Browse files
Merge branch 'main' into fix-test-warnings
2 parents 8b3b8cf + 39385a7 commit 5d1ebb5

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

docs/english/web.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ You can have your app's messages stream in to replicate conventional AI chatbot
6161
* [`chat_appendStream`](/reference/methods/chat.appendStream)
6262
* [`chat_stopStream`](/reference/methods/chat.stopStream)
6363

64-
:::tip[The Python Slack SDK provides a [`chat_stream()`](https://docs.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods.]
6564

66-
See the [_Streaming messages_](/tools/bolt-python/concepts/message-sending#streaming-messages) section of the Bolt for Python docs for implementation instructions.
67-
68-
:::
65+
You can streamline calling these methods by using the [`chat_stream()`](#chat_stream) helper.
6966

7067
#### Starting the message stream {#starting-stream}
7168

@@ -161,6 +158,30 @@ def handle_message(message, client):
161158

162159
See [Formatting messages with Block Kit](#block-kit) below for more details on using Block Kit with messages.
163160

161+
#### Using the `chat_stream()` helper {#chat_stream}
162+
163+
The Python Slack SDK provides a [`chat_stream()`](https://docs.slack.dev/tools/python-slack-sdk/reference/web/client.html#slack_sdk.web.client.WebClient.chat_stream) helper utility to streamline calling these methods. Here's an excerpt from our [Assistant template app](https://github.com/slack-samples/bolt-python-assistant-template):
164+
165+
```python
166+
streamer = client.chat_stream(
167+
channel=channel_id,
168+
recipient_team_id=team_id,
169+
recipient_user_id=user_id,
170+
thread_ts=thread_ts,
171+
)
172+
173+
# Loop over OpenAI response stream
174+
# https://platform.openai.com/docs/api-reference/responses/create
175+
for event in returned_message:
176+
if event.type == "response.output_text.delta":
177+
streamer.append(markdown_text=f"{event.delta}")
178+
else:
179+
continue
180+
181+
feedback_block = create_feedback_block()
182+
streamer.stop(blocks=feedback_block)
183+
```
184+
164185
## Formatting messages with Block Kit {#block-kit}
165186

166187
Messages posted from apps can contain more than just text; they can also include full user interfaces composed of blocks using [Block Kit](/block-kit).

docs/reference/models/blocks/blocks.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ <h3>Inherited members</h3>
16011601
else:
16021602
field_objects.append(PlainTextObject(**d)) # type: ignore[arg-type]
16031603
else:
1604-
self.logger.warning(f&#34;Unsupported filed detected and skipped {f}&#34;)
1604+
self.logger.warning(f&#34;Unsupported field detected and skipped {f}&#34;)
16051605
self.fields = field_objects
16061606
self.accessory = BlockElement.parse(accessory) # type: ignore[arg-type]
16071607
self.expand = expand

docs/reference/models/blocks/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6592,7 +6592,7 @@ <h3>Inherited members</h3>
65926592
else:
65936593
field_objects.append(PlainTextObject(**d)) # type: ignore[arg-type]
65946594
else:
6595-
self.logger.warning(f&#34;Unsupported filed detected and skipped {f}&#34;)
6595+
self.logger.warning(f&#34;Unsupported field detected and skipped {f}&#34;)
65966596
self.fields = field_objects
65976597
self.accessory = BlockElement.parse(accessory) # type: ignore[arg-type]
65986598
self.expand = expand

slack_sdk/models/blocks/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __init__(
179179
else:
180180
field_objects.append(PlainTextObject(**d)) # type: ignore[arg-type]
181181
else:
182-
self.logger.warning(f"Unsupported filed detected and skipped {f}")
182+
self.logger.warning(f"Unsupported field detected and skipped: {f}")
183183
self.fields = field_objects
184184
self.accessory = BlockElement.parse(accessory) # type: ignore[arg-type]
185185
self.expand = expand

slack_sdk/signature/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import hashlib
44
import hmac
55
from time import time
6-
from typing import Dict, Optional, Union
6+
from typing import Dict, Optional, Union, TYPE_CHECKING
7+
8+
# Fallback to Dict for Python 3.7/3.8 compatibility (safe to remove once these versions are no longer supported)
9+
if TYPE_CHECKING:
10+
from collections.abc import Mapping
11+
else:
12+
Mapping = Dict
713

814

915
class Clock:
@@ -26,23 +32,23 @@ def __init__(self, signing_secret: str, clock: Clock = Clock()):
2632
def is_valid_request(
2733
self,
2834
body: Union[str, bytes],
29-
headers: Dict[str, str],
35+
headers: Mapping[str, str],
3036
) -> bool:
3137
"""Verifies if the given signature is valid"""
3238
if headers is None:
3339
return False
3440
normalized_headers = {k.lower(): v for k, v in headers.items()}
3541
return self.is_valid(
3642
body=body,
37-
timestamp=normalized_headers.get("x-slack-request-timestamp", None), # type: ignore[arg-type]
38-
signature=normalized_headers.get("x-slack-signature", None), # type: ignore[arg-type]
43+
timestamp=normalized_headers.get("x-slack-request-timestamp", None),
44+
signature=normalized_headers.get("x-slack-signature", None),
3945
)
4046

4147
def is_valid(
4248
self,
4349
body: Union[str, bytes],
44-
timestamp: str,
45-
signature: str,
50+
timestamp: Optional[str],
51+
signature: Optional[str],
4652
) -> bool:
4753
"""Verifies if the given signature is valid"""
4854
if timestamp is None or signature is None:

0 commit comments

Comments
 (0)