-
Notifications
You must be signed in to change notification settings - Fork 1
release: 0.4.27.1 — backport Slack files_upload_v2 confirmation fix #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3389,10 +3389,16 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) -> | |
| try: | ||
| client = self._get_client() | ||
|
|
||
| # Check for files to upload | ||
| # Check for files to upload. ``files_upload_v2`` returns the | ||
| # Slack-confirmed file IDs; we surface them on ``RawMessage.raw`` | ||
| # so consumers can gate on actual delivery (parity with | ||
| # discord/telegram, which upload inline and expose the platform | ||
| # response naturally). ``None`` means no upload happened; an empty | ||
| # list means Slack confirmed zero attachments (a real signal). | ||
| uploaded_file_ids: list[str] | None = None | ||
| files = extract_files(message) | ||
| if files: | ||
| await self._upload_files(files, channel, thread_ts or None) | ||
| uploaded_file_ids = await self._upload_files(files, channel, thread_ts or None) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this new return value is used, successful real Slack uploads will usually surface Useful? React with 👍 / 👎. |
||
| has_text = ( | ||
| isinstance(message, str) | ||
| or (hasattr(message, "raw") and getattr(message, "raw", None)) | ||
|
|
@@ -3404,7 +3410,7 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) -> | |
| return RawMessage( | ||
| id=f"file-{int(time.time() * 1000)}", | ||
| thread_id=thread_id, | ||
| raw={"files": files}, | ||
| raw=self._augment_raw_with_uploads({"files": files}, uploaded_file_ids), | ||
| ) | ||
|
|
||
| card = extract_card(message) | ||
|
|
@@ -3426,7 +3432,10 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) -> | |
| return RawMessage( | ||
| id=result.get("ts", ""), | ||
| thread_id=thread_id, | ||
| raw=result.data if hasattr(result, "data") else result, | ||
| raw=self._augment_raw_with_uploads( | ||
| result.data if hasattr(result, "data") else result, | ||
| uploaded_file_ids, | ||
| ), | ||
| ) | ||
|
|
||
| # Table blocks | ||
|
|
@@ -3443,7 +3452,10 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) -> | |
| return RawMessage( | ||
| id=result.get("ts", ""), | ||
| thread_id=thread_id, | ||
| raw=result.data if hasattr(result, "data") else result, | ||
| raw=self._augment_raw_with_uploads( | ||
| result.data if hasattr(result, "data") else result, | ||
| uploaded_file_ids, | ||
| ), | ||
| ) | ||
|
|
||
| # Regular text | ||
|
|
@@ -3462,11 +3474,29 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) -> | |
| return RawMessage( | ||
| id=result.get("ts", ""), | ||
| thread_id=thread_id, | ||
| raw=result.data if hasattr(result, "data") else result, | ||
| raw=self._augment_raw_with_uploads( | ||
| result.data if hasattr(result, "data") else result, | ||
| uploaded_file_ids, | ||
| ), | ||
| ) | ||
| except Exception as error: | ||
| self._handle_slack_error(error) | ||
|
|
||
| @staticmethod | ||
| def _augment_raw_with_uploads(raw: Any, uploaded_file_ids: list[str] | None) -> Any: | ||
| """Add Slack-confirmed file IDs to a ``RawMessage.raw`` payload. | ||
|
|
||
| Returns ``raw`` unchanged when no upload occurred (``uploaded_file_ids`` | ||
| is ``None``). Otherwise returns a NEW dict that merges the existing raw | ||
| (Slack never returns an ``uploaded_file_ids`` key, so this is additive | ||
| and non-breaking) with the confirmed IDs. An empty list is preserved — | ||
| it signals that Slack confirmed zero attachments. | ||
| """ | ||
| if uploaded_file_ids is None: | ||
| return raw | ||
| base = raw if isinstance(raw, dict) else {} | ||
| return {**base, "uploaded_file_ids": uploaded_file_ids} | ||
|
|
||
| async def edit_message( | ||
| self, | ||
| thread_id: str, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When defining a versioning scheme that embeds an upstream version (such as
0.4.27.1for a local patch on0.4.27), there is a potential for collision if the upstream project releases a patch version (e.g.,4.27.1). If upstream patch releases are handled by bumping to the next minor version in this SDK, please ensure this behavior is explicitly documented (for example, in the README or a dedicated versioning document) to clarify that the fourth digit/local patch slot is strictly reserved for local, Python-only fixes.References