Socket Mode: ack() with text starting with '{' is never sent (JSONDecodeError)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 1.3k
- Fork
- 300
- Merge medio
- 19h 33m
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di slackapi/bolt-python
-
`extract_team_id` crashes with `TypeError when payload["user"]` is a string (e.g. `member_joined_channel` events)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaauto-triage-skip bug security semver:major
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
slackapi/bolt-python#1447 · 9 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
auto-triage-stale
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
slackapi/bolt-python#1599 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Error handlers that take args: Args crash with a missing 'next' argumentForse già presa @sahiljagtap08 l’ha presa 42 giorni fa. Apertaauto-triage-stale
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
slackapi/bolt-python#1598 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Assistant listener middleware crashes when given a plain functionForse già presa @sahiljagtap08 l’ha presa 42 giorni fa. Apertaauto-triage-stale
Difficoltà 2/5 1-3 ore Idoneità per principianti 30/100
slackapi/bolt-python#1597 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
AsyncOAuthFlow raises UnboundLocalError on org-wide install without a bot tokenForse già presa @sahiljagtap08 l’ha presa 42 giorni fa. Apertaauto-triage-stale
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
slackapi/bolt-python#1596 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di slackapi/bolt-python
Issue simili
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
BrainLesion/BraTS#200 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
OpenHands/extensions#970 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
rl-institut/enetra#91 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
huggingface/datasets#9100 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
NVIDIA/garak#2486 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni