Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

custom response #22

Closed
vallard opened this issue Feb 9, 2022 · 2 comments
Closed

custom response #22

vallard opened this issue Feb 9, 2022 · 2 comments

Comments

@vallard
Copy link

vallard commented Feb 9, 2022

Thanks for this great library! I was able to process actions but I'm having issues with custom responses. I have my code that looks as follows:

@actions.on("block_actions:approve_workflow")
def handle_workflow_unpause_action(payload):
    log.info("Action started.")
    log.debug(payload)
    print("action: ", payload)


@responder("block_actions:approve_workflow")
def respond_to_workflow_unpause_action(payload):
    log.info("Response.")
    log.debug(payload)
    print("response: ", payload)
    user = payload["user"]["username"]
    return JSONResponse(
        {
            "replace_original": "true",
            "text": f"Workflow approved by @{user}",
        }
    )

The issue is I'm expecting the original block_action to be replaced by the message Workflow approved by {user}. But this doesn't seem to be happening. Is there something I'm missing? Thanks for your help and providing this library!

@uhavin
Copy link
Owner

uhavin commented Feb 9, 2022

Hi @vallard, thanks for your kind words. I am glad you enjoy the library.

While it is technically possible to use both an event handler and a custom response for the same action, it will yield unexpected results. This is because once an event is received on @actions, it will immediately return an HTTP 200 response to Slack. Your custom response will also be returned, but the request has already been responded to, so it falls on deaf ears.

The solution is to use only one kind of response to a unique action, you have to choose between responder and actions.on. That said, it is possible to make subsequent requests related to the action after responding to slack with 200. There should be an API endpoint to which you can send the action id and the action blocks. Please refer to the Slack developer documentation for further details on that.

@uhavin
Copy link
Owner

uhavin commented Feb 12, 2022

I'll close this issue for now, but feel free to reopen if you have further questions.

@uhavin uhavin closed this as completed Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants