Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ack() on view submission does not accept response_action arguments #305

Closed
3 tasks done
aoberoi opened this issue Oct 30, 2019 · 7 comments · Fixed by #404
Closed
3 tasks done

ack() on view submission does not accept response_action arguments #305

aoberoi opened this issue Oct 30, 2019 · 7 comments · Fixed by #404
Assignees
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented TypeScript-specific

Comments

@aoberoi
Copy link
Contributor

aoberoi commented Oct 30, 2019

Description

The ack() function should accept any value that is acceptable to respond to an incoming HTTP request. In the context of view submissions, there are a few response_actions that are acceptable, but currently do not work because the ack utility is incorrectly typed to take RespondArguments.

The solution is likely to use the AckFn<T> type to describe the additional response_action payloads:

  • update
  • push
  • clear
  • errors

https://api.slack.com/surfaces/modals/using#modifying

https://api.slack.com/surfaces/modals/using#displaying_errors

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: 1.4.1

node version: all

OS version(s): all

Steps to reproduce:

  1. Open a modal
  2. Add a listener for view submission of that modal
  3. Call ack({ response_action: "clear" }) in the listener.

Expected result:

The TypeScript typechecker is happy.

Actual result:

The TypeScript typechecker is sad.

@aoberoi aoberoi added the bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented label Oct 30, 2019
@jacklein
Copy link

jacklein commented Dec 9, 2019

Has this been fixed? How am I supposed to send an error message to a modal upon submission using bolt?

@seratch
Copy link
Member

seratch commented Dec 9, 2019

@jacklein Unfortunately, it hasn't been fixed yet.

... I know this is not a preferable workaround but the only thing TypeScript users can do as a workaround is cast the response to any until it has been fixed in future versions.

app.view('callback_id', ({ ack }) => {
    ack({
        response_action: 'errors',
        errors: []
    } as any /* Tentative workaround for https://github.com/slackapi/bolt/issues/305 */);
});

I will take look at this issue. I'm also a big fan of TS.

@seratch seratch self-assigned this Dec 9, 2019
@jacklein
Copy link

jacklein commented Dec 9, 2019

@seratch I'm using node.js not typescript (I'm not at all familiar with typescript), is there any workaround for plain javascript?

@seratch
Copy link
Member

seratch commented Dec 9, 2019

@jacklein In JavaScript, there is no obstacle. You can give respond_action and errors like this:
https://github.com/seratch/bolt-starter/blob/5e1e4e49279856d70a7d4b8824a24d0056b33206/index.js#L143-L146

  const errors = {};
  if (title.length <= 5) {
    errors['input-title'] = 'Title must be longer than 5 characters'
  }
  if (Object.entries(errors).length > 0) {
    ack({
      response_action: 'errors',
      errors: errors
    });
  } else {
    ack(); // close this modal - or also possible to set `response_action: 'clear'`
  }

@jacklein
Copy link

jacklein commented Dec 9, 2019

@seratch You really saved my life with that example code. Thank you, I really appreciate the help.

One potential bug I would like to point out is I had a group of date pickers that looks like:

{
  "type": "actions",
  "block_id": "date_select",
  "elements": [
    {
      "type": "datepicker",
      "action_id": "departure_date",
      "placeholder": {
        "type": "plain_text",
        "text": "Departure date"
      },
    },
    {
      "type": "datepicker",
      "action_id": "return_date",
      "placeholder": {
        "type": "plain_text",
        "text": "Return date"
      },
    },
  ]
}

and the error message wasn't working for date_select. Is this to be expected since it's an action type?

@seratch
Copy link
Member

seratch commented Dec 9, 2019

@jacklein

An actions block cannot be a part of view_submission data. Use input blocks instead:

{
    "type": "input",
    "block_id": "departure_date",
    "element": {
        "type": "datepicker",
        "action_id": "input",
        "placeholder": {
            "type": "plain_text",
            "text": "Departure date"
        },
    },
    "label": {
        "type": "plain_text",
        "text": "Departure date",
        "emoji": true
    }
},
{
    "type": "input",
    "block_id": "return_date",
    "element": {
        "type": "datepicker",
        "action_id": "input",
        "placeholder": {
            "type": "plain_text",
            "text": "Return date"
        },
    },
    "label": {
        "type": "plain_text",
        "text": "Return date",
        "emoji": true
    }
}

@jacklein
Copy link

jacklein commented Dec 9, 2019

@seratch Awesome! Thanks again, really appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented TypeScript-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants