0

I use ASP.NET Core 2.1 to build integration with Slack Here is my modal in json format.

{
  "type": "modal",
  "callback_id": "send_sms",
  "title": {
    "type": "plain_text",
    "text": "Send SMS",
    "emoji": false
  },
  "submit": {
    "type": "plain_text",
    "text": "Submit"
  },
  "close": {
    "type": "plain_text",
    "text": "Cancel"
  },
  "blocks": [
    {
      "type": "divider"
    },
    {
      "type": "input",
      "block_id": "phone_number",
      "label": {
        "type": "plain_text",
        "text": "Enter phone number",
        "emoji": false
      },
      "element": {
        "type": "plain_text_input",
        "placeholder": {
          "type": "plain_text",
          "text": "Phone number",
          "emoji": false
        },
        "action_id": "action_phone_number"
      }
    },
    {
      "type": "input",
      "block_id": "message",
      "label": {
        "type": "plain_text",
        "text": "Enter message",
        "emoji": false
      },
      "element": {
        "placeholder": {
          "type": "plain_text",
          "text": "Message",
          "emoji": false
        },
        "action_id": "message",
        "type": "plain_text_input",
        "multiline": true
      }
    }
  ]
}

So when user submit form, my .net core application recieves an view_submission event and if phone number has invalid format I want to response to this event with error. Slack docs says that I should response with such json object:

`{
  "response_action": "errors",
  "errors": {
    "phone_number": "Invalid phone number format"
  }
}`

During debugging I found out that my app actually DO load json from file and DO respond with a string that contains this json. But a still get this error on my modal enter image description here

controller method returns Task> object but I'm not sure that it's correct So my question is: Does anybody know how I should response to this slack event using .net core? As far as I understand even if I have validation error in my .net core app and I want to return error object to slack, I should respond with status 200 OK

1 Answers1

1

Finnaly this question is resolved by returning

Content('json_string', "application/json");
  • While the question is for ASP.NET but If you are using Django and came here for the answer then you can use: return JsonResponse({ "response_action": "errors", "errors": { "phone_number": "Invalid phone number format" } }) don't forget to import: from django.http import JsonResponse – Irfan Alam Jun 17 '20 at 18:57