Socket Mode: ack() with text starting with '{' is never sent (JSONDecodeError)
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 1.3k
- Forks
- 300
- Merge médio
- 19h 33min
- PRs com merge (30d)
- 25
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de slackapi/bolt-python
-
`extract_team_id` crashes with `TypeError when payload["user"]` is a string (e.g. `member_joined_channel` events)Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertaauto-triage-skip bug security semver:major
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
slackapi/bolt-python#1447 · 9 comentários ·
Mantenedores costumam responder em até 1 dia
-
auto-triage-stale
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
slackapi/bolt-python#1599 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Error handlers that take args: Args crash with a missing 'next' argumentTalvez já em andamento @sahiljagtap08 assumiu há 42 dias. Abertaauto-triage-stale
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 25/100
slackapi/bolt-python#1598 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Assistant listener middleware crashes when given a plain functionTalvez já em andamento @sahiljagtap08 assumiu há 42 dias. Abertaauto-triage-stale
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 30/100
slackapi/bolt-python#1597 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
AsyncOAuthFlow raises UnboundLocalError on org-wide install without a bot tokenTalvez já em andamento @sahiljagtap08 assumiu há 42 dias. Abertaauto-triage-stale
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
slackapi/bolt-python#1596 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de slackapi/bolt-python
Issues semelhantes
-
documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 74/100
BrainLesion/BraTS#200 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
OpenHands/extensions#970 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
rl-institut/enetra#91 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
huggingface/datasets#9100 ·
Mantenedores costumam responder em até 1 dia
-
needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
NVIDIA/garak#2486 · 1 comentário ·
Mantenedores costumam responder em até 2 dias