Skip to content

Unable to change ephemeral messages with response_url (with slash commands) #1268

@olavfla

Description

@olavfla

I'm trying to edit an ephemeral message generated by the respond command in a slack command response, but it just posts it as a new message. Not sure if I'm misreading the docs, but this makes it seem like it can be done.

Reproducible in:

pip freeze | grep slack
python --version
sw_vers && uname -v # or `ver`

The slack_bolt version

slack_bolt==1.22.0
slack_sdk==3.34.0

Python runtime version

Python 3.12.2

OS info

Microsoft Windows [Version 10.0.26100.3194]

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., setup.py))

  1. Source snippet
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))

# Slash command: /play [url or search term]
# Places the requested socng at the end of the queue
@app.command("/play")
def play_command(ack, respond, command):
    ack()
    text = command.get("text", "").strip()
    if not text:
        respond("Please provide a YouTube URL or search query to play next.")
        return
    try:
        respond({"text":f"Queued: *{text}*", "replace_original":"true"}) #search
        #This function takes some time, so i want to send an acknowledgement to the user in the meantime.
        pcm_path, title, pipe, cancel_callback = (None, "Title", None, None)#download_and_convert(text)
    except Exception as e:
        respond(f"Failed to extract stream URL: {e}")
        return
    # with queue_lock:
    #     url_queue.append((title, pcm_path, cancel_callback))
    #Update with the title from the search result when it's available
    respond({"text":f"Replaced: *{text}*", "replace_original":"true"}) #queued
    # accountability(command["user_id"], title)
    # print(f"Queued {title} as next ({pcm_path})")
    # pipe.join()
    # print(f"Joined {title}")

if __name__ == "__main__":
    handler = SocketModeHandler(app, os.environ.get("SLACK_APP_TOKEN"))
    handler.start()
  1. run /play

Expected result:

I expected the first ephemeral message to be replaced by the second one

Actual result:

The second response just posts a new message instead of overwriting the other one.

Image

I have checked the logs to see if the "replace_original" attribute is being included, and it seems like it is. The request body looks like it does in the example for response_urls

DEBUG:slack_sdk.webhook.client:Sending a request - url: https://hooks.slack.com/commands/T071EE57DU2/8570366692821/feHDoUEdcjCTr6UdjDWZDbb5, body: {"text": "Queued: *Polyphia | Look But Don't Touch (feat. Lewis Grant)*", "replace_original": "true"}, headers: {'Content-Type': 'application/json;charset=utf-8', 'User-Agent': 'Python/3.12.2 slackclient/3.34.0 Windows/11'}
DEBUG:slack_sdk.webhook.client:Received the following response - status: 200, headers: {'date': 'Sat, 08 Mar 2025 23:33:03 GMT', 'server': 'Apache', 'vary': 'Accept-Encoding', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'referrer-policy': 'no-referrer', 'x-slack-unique-id': 'Z8zTrwMpbeGNVSj2mVukFgAAEDw', 'x-slack-backend': 'r', 'access-control-allow-origin': '*', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'text/html', 'content-length': '2', 'via': '1.1 slack-prod.tinyspeck.com, envoy-www-iad-nvnhelnz,envoy-edge-dub-uyzuznti', 'x-envoy-attempt-count': '1', 'x-envoy-upstream-service-time': '115', 'x-backend': 'main_normal main_canary_with_overflow main_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-ddkc', 'x-slack-shared-secret-outcome': 'no-match', 'x-edge-backend': 'envoy-www', 'x-slack-edge-shared-secret-outcome': 'no-match', 'connection': 'close'}, body: ok

DEBUG:slack_sdk.webhook.client:Sending a request - url: https://hooks.slack.com/commands/T071EE57DU2/8570366692821/feHDoUEdcjCTr6UdjDWZDbb5, body: {"text": "Replaced: *Polyphia | Look But Don't Touch (feat. Lewis Grant)*", "replace_original": "true"}, headers: {'Content-Type': 'application/json;charset=utf-8', 'User-Agent': 'Python/3.12.2 slackclient/3.34.0 Windows/11'}
DEBUG:slack_sdk.webhook.client:Received the following response - status: 200, headers: {'date': 'Sat, 08 Mar 2025 23:33:06 GMT', 'server': 'Apache', 'vary': 'Accept-Encoding', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'referrer-policy': 'no-referrer', 'x-slack-unique-id': 'Z8zTsg8I65vyheCsBHeCeAAAgDI', 'x-slack-backend': 'r', 'access-control-allow-origin': '*', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'text/html', 'content-length': '2', 'via': '1.1 slack-prod.tinyspeck.com, envoy-www-iad-vqcbouzg,envoy-edge-dub-szbrifor', 'x-envoy-attempt-count': '1', 'x-envoy-upstream-service-time': '105', 'x-backend': 'main_normal main_canary_with_overflow main_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-pxxc', 'x-slack-shared-secret-outcome': 'no-match', 'x-edge-backend': 'envoy-www', 'x-slack-edge-shared-secret-outcome': 'no-match', 'connection': 'close'}, body: ok

Please let me know if this is just me misreading the docs, or if I'm doing something wrong 😊

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions