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

Add types of state.values on modal submission #497

Closed
4 of 9 tasks
dan-kez opened this issue May 14, 2020 · 3 comments · Fixed by #879
Closed
4 of 9 tasks

Add types of state.values on modal submission #497

dan-kez opened this issue May 14, 2020 · 3 comments · Fixed by #879
Labels
enhancement M-T: A feature request for new functionality TypeScript-specific
Milestone

Comments

@dan-kez
Copy link

dan-kez commented May 14, 2020

Description

I am currently working on validating modal submissions from Slack. Somewhat unfortunately all block types carry their value under different keys (e.g. rather than all having a value key there are selected_users, selected_channel, selected_options and more).

So far I have been unable to find documentation about the variety of response type structures that input blocks can have on modal submission.

I noticed there is a TODO comment here:

[actionId: string]: any; // TODO: a union of all the input elements' output payload

I am happy to submit a PR with a union type for this response if someone can point me to docs on what is available from the API. For my own bot, I have had to step through with a debugger to introspect the responses.

As a follow up, it would be amazing if there was a way to get simplified response schema from the slack's response (e.g. get a block_id: value mapping or some relative equivalent that includes the action_id). This would make it much easier to quickly write any schema validation using tools like https://github.com/jquense/yup or https://hapi.dev/module/joi/ without having to massage the data into a flatter form.

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

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.
@seratch seratch added the enhancement M-T: A feature request for new functionality label May 14, 2020
@seratch seratch changed the title Response types on modal submission Add types of state.values on modal submission Jun 2, 2020
@seratch
Copy link
Member

seratch commented Jun 2, 2020

As I mentioned here: #404 (comment), I'm always happy to provide more types for TypeScript users.

@stevengill @aoberoi
Do you have thoughts about this?

@aoberoi
Copy link
Contributor

aoberoi commented Jun 2, 2020

I love it! One suggestion: we could add the type definitions for the outputs of the actions closer to the definitions of the action blocks/elements themselves if they were put in the @slack/types package. That also would make them more reusable outside of Bolt for JS.

@aoberoi
Copy link
Contributor

aoberoi commented Jun 2, 2020

As a follow up, it would be amazing if there was a way to get simplified response schema from the slack's response (e.g. get a block_id: value mapping or some relative equivalent that includes the action_id).

This sounds like a neat idea, but I don't think I completely understand. It sounds like you want to validate the action payload you receive from Slack fits a schema you have in your application, is that right? If so, I'm not sure how this would help in an application, but maybe you can walk me through it.

I can see some value in a simplified mapping that works across all action block/element types. One benefit would be that you could deal with all actions is some generic way, which would allow you to have more code reuse. The biggest challenge I see is modeling the selection values. For example, a 'user_select' element has a single string value (called 'selected_user') and a 'multi_user_selet' element has an array of string values (called 'selected_users'). So would we wrap all values as an array to keep them fitting the same schema? For example: { "my_block_id" : ["U12345"] }. I think reading the value by always indexing [0] on the array would be a little ugly. Any thoughts on how you would do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality TypeScript-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants