Socket Mode: ack() with text starting with '{' is never sent (JSONDecodeError)

未關閉
#1,594 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@sahiljagtap08 已經在處理了。

開始於 2026年10月8日。

  • #1593 來自 @sahiljagtap08 —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
backend

研究方向

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 內容生成。

描述

auto-triage-stale
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()
  1. Start the app in Socket Mode.
  2. Run /hello in 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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

slackapi/bolt-python 的其他 Issue

查看 slackapi/bolt-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。