Search code examples
slackslack-api

How can i disable the close icon on attachments?


I am trying to post messages to slack https://api.slack.com/methods/chat.postMessage/test

i am adding attachment [{"pretext": "pre-hello", "text": "text-world"}]

but in slack channel UI i am seeing close icon, if i click close icon i can able to remove attachment

enter image description here

How can i disable close icon, so that no one can't delete attachments?


Solution

  • There is a workaround if you remove "text" node, attachments can't be deleted. So you can put "pretext" on first attachment to have same behavior.

    Here you can delete attachements (Sample)

    {
        "text": "Hello",
        "attachments": [
            {
                "text": "Hello World"
            },
            {
                "text": "Hello World"
            }
        ]
    }
    

    Here, you have the same message but without close icons this time (Sample)

    {
        "attachments": [
            {
                "pretext": "Hello",
                "text": "Hello World"
            },
            {
                "text": "Hello World"
            }
        ]
    }