Remove part of a Slack message after button click

Hey, I have a scenario running that ends in a Slack message, including blocks with buttons. Then, I have a second scenario, started by a webhook, triggered by the button click in the Slack message. That e.g. then triggers an e-mail. I’d like to avoid multiple clicks on the same button, so I would like to update the Slack message after the button click.

In general, updating the Slack message works and I can remove everything and replace it with a new text.

What I try to achieve now is: The Slack message contains multiple blocks. I’d like to remove only the block with the buttons. I do neither find a way to re-use the blocks in a new message nor any way to edit only a part of that message.

Any suggestions?

My blocks e.g. look like this. I would be fine with always removing all blocks with the type “actions”. But right now, I do not find at all a way to re-use blocks in a new/updated slack message.

"blocks": [
    {
        "type": "section",
        "block_id": "+qXt4",
        "text": {
            "type": "mrkdwn",
            "text": "Yay, we got a new lead! :tada:",
            "verbatim": false
        }
    },
    {
        "type": "divider",
        "block_id": "LvvqY"
    },
    {
        "type": "header",
        "block_id": "7yQT+",
        "text": {
            "type": "plain_text",
            "text": "Company",
            "emoji": true
        }
    },
    {
        "type": "section",
        "block_id": "W6GCX",
        "fields": [
            {
                "type": "mrkdwn",
                "text": "*Type:*\nGastro",
                "verbatim": false
            },
            {
                "type": "mrkdwn",
                "text": "*Contact:*\nMax Mustermann",
                "verbatim": false
            }
        ]
    },
    {
        "type": "section",
        "block_id": "XXwgx",
        "fields": [
            {
                "type": "mrkdwn",
                "text": "*E-Mail:*\n<mailto:e@mail.com|e@mail.com>",
                "verbatim": false
            },
            {
                "type": "mrkdwn",
                "text": "*VAT:*\nDE123456789",
                "verbatim": false
            }
        ]
    },
    {
        "type": "divider",
        "block_id": "SBl0N"
    },
    {
        "type": "context",
        "block_id": "JlCZI",
        "elements": [
            {
                "type": "mrkdwn",
                "text": "Request ID: 1234567899",
                "verbatim": false
            }
        ]
    },
    {
        "type": "actions",
        "block_id": "EWHBO",
        "elements": [
            {
                "type": "button",
                "action_id": "send-price-mail",
                "text": {
                    "type": "plain_text",
                    "text": "Send Price-List E-Mail",
                    "emoji": true
                },
                "style": "primary",
                "value": "1234567899"
            },
            {
                "type": "button",
                "action_id": "ignore",
                "text": {
                    "type": "plain_text",
                    "text": "Ignore",
                    "emoji": true
                },
                "value": "1234567899"
            }
        ]
    }
]

Hey!!

I made a few tests, and I managed to remove the button and still keep the other blocks!
In fact, according to the Slack API Documentation here: Handling user interaction in your Slack apps | Slack, you can respond with another message.

So what I did is, once I parsed the JSON I receive in the webhook, I slice message.blocks (it contains the full blocks that were shown to the user). I did a slice(message.blocks;0;7) leveraging the example you provided (it has 8 blocks).

And then, I recomposed a Json payload transforming the result in a json string and adding the blocks element

And I use this to reply to the user

Here is the result:

Buttons are removed but the user can still see the information.

I hope it helps

Of course I let you optimize and not use all these Set Variables :sweat_smile:

Benjamin

3 Likes

Wow @Benjamin_from_Make, thank you so much for the efforts you put in! That worked super well for me! :muscle:t3: Couldn’t have figured that out without your help. Merci!

3 Likes

Avec plaisir!!!
Thanks for your feedback :star_struck:

1 Like

Just as a follow-up here: I extended the solution a bit to not only remove the blocks, but also document what block was clicked. (Probably there is a cleaner solution, but I only managed to make it work wit the Parse JSON and the Array aggregator.)

I create one additional block with the action text.

Then I slice the existing blocks as suggested (always removing the last block) and adding the new block at the end.
Screenshot 2024-06-07 no 001692

It helps clarifying to users what has been triggered:
Screenshot 2024-06-07 no 001693

1 Like