Search code examples
asp.net-core.net-coreslackslack-api

Netcore server respond to slack interactive message


I am trying to build Slack application with asp net core server. Currently, I have added Slash command which makes a request to my local server through ngrok. Once my server receives that request, it makes a post request to configured slack webhook to display interactive message which looks like pic from attachment. enter image description here

I want user to be able to select yes or no and receive the result in my controller, but I can't realize how to tell Slack where should it make a post request. I attach the code of this message which is posted through weebhook into Slack:

{
"blocks": [
    {
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "This is a section block with a button."
    }
    },
    {
        "type": "actions",
        "block_id": "actionblock789",
        "elements": [
            {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "Yes"
                },
                "style": "primary",
                "value": "yes"
            },
            {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "No"
                },
                "value": "no"
            }
        ]
    }
]
}

What I have in netcore is TestController with route /api/test which I suppose should receive from Slack a payload where information about selected button is set, but I couldn't find a way where specify a url in this json code.


Solution

  • You can not configure a URL in the JSON code. That is not how it works with the Slack API.

    Slack will send all responses to interactive message - like when someone clicks on a button - to the configured request URL of your Slack app. Check out this link how to find that parameter: documentation