Socket Mode: ack() with text starting with '{' is never sent (JSONDecodeError)
維護者通常 1 天內回覆
評估
研究方向
The JSON parse happens in send_response in slack_bolt/adapter/socket_mode/internals.py and in send_async_response in async_internals.py, where a body starting with { is passed to json.loads without error handling. Read those two functions, then reproduce with an ack string such as "{curly braces". Done means both paths fall back to sending the text as a plain string instead of raising. A fix already exists in open PR #1593, so check that thread before starting new work.
由索引模型根據 Issue 內容生成。
描述
Reproducible in:
The slack_bolt version
slack_bolt==1.30.0
slack_sdk==3.45.0
Python runtime version
Python 3.12.5
OS info
macOS 27.0
Steps to reproduce:
In Socket Mode, call ack() with a plain text string that starts with { but is not valid JSON.
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
app = App(token=os.environ["SLACK_BOT_TOKEN"])
@app.command("/hello")
def hello(ack):
ack("{curly braces are fun}")
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
- Start the app in Socket Mode.
- Run
/helloin Slack.
Expected result:
Slack receives the ack and shows the text {curly braces are fun} as the response.
Actual result:
The ack is never sent. Slack shows "failed with the error operation_timeout" and the app logs a json.JSONDecodeError.
The cause is in slack_bolt/adapter/socket_mode/internals.py (send_response) and async_internals.py (send_async_response). They decide the ack body is JSON by checking whether the text starts with {, and then call json.loads() on it without handling a parse failure:
if content_type.startswith("application/json"):
payload = json.loads(bolt_resp.body)
BoltResponse sets Content-Type: application/json for any string body that starts with {, so the same problem happens with ack("{", ...), ack("{foo"), or any text that happens to begin with that character. The non-Socket-Mode HTTP path does not have this issue because the body is sent through as-is.
I have a fix ready in #1593 that falls back to sending the string as {"text": body} whenever it cannot be parsed as a JSON object. Opening this issue at the maintainers' request so it can be tracked.
Requirements
I have read the Contributing guidelines and Code of Conduct.
- 主要語言
- Python
- 星號
- 1.3k
- 分支
- 300
- 平均合併
- 19 小時 33 分鐘
- 30 天內合併 PR
- 25
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
slackapi/bolt-python 的其他 Issue
-
`extract_team_id` crashes with `TypeError when payload["user"]` is a string (e.g. `member_joined_channel` events)可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉auto-triage-skip bug security semver:major
難度 2/5 1-3 小時 新手友好度 72/100
slackapi/bolt-python#1447 · 9 則留言 ·
維護者通常 1 天內回覆
-
auto-triage-stale
難度 5/5 一週以上 新手友好度 35/100
slackapi/bolt-python#1599 · 1 則留言 ·
維護者通常 1 天內回覆
-
Error handlers that take args: Args crash with a missing 'next' argument可能已有人在做 @sahiljagtap08 於 42 天前認領。 未關閉auto-triage-stale
難度 3/5 1-2 天 新手友好度 25/100
slackapi/bolt-python#1598 · 1 則留言 ·
維護者通常 1 天內回覆
-
Assistant listener middleware crashes when given a plain function可能已有人在做 @sahiljagtap08 於 42 天前認領。 未關閉auto-triage-stale
難度 2/5 1-3 小時 新手友好度 30/100
slackapi/bolt-python#1597 · 1 則留言 ·
維護者通常 1 天內回覆
-
AsyncOAuthFlow raises UnboundLocalError on org-wide install without a bot token可能已有人在做 @sahiljagtap08 於 42 天前認領。 未關閉auto-triage-stale
難度 2/5 1-3 小時 新手友好度 35/100
slackapi/bolt-python#1596 · 1 則留言 ·
維護者通常 1 天內回覆
查看 slackapi/bolt-python 的全部 Issue
相似的 Issue
-
documentation
難度 1/5 1 小時以內 新手友好度 74/100
BrainLesion/BraTS#200 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
OpenHands/extensions#970 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
rl-institut/enetra#91 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
huggingface/datasets#9100 ·
維護者通常 1 天內回覆
-
needs-triage
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 2 天內回覆