slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://tools.slack.dev/bolt-js/
MIT License
2.75k stars 395 forks source link

Better typing for block actions payload #2122

Open sota1235 opened 5 months ago

sota1235 commented 5 months ago

I wish some block action body will have more correct typing.

For example, when I use InteractiveMessage type when I want to handle event for clicking button on message, that's type does not contain container payload. But actually it exists. I think it's intentional type, here is an official document. https://api.slack.com/reference/interaction-payloads/block-actions#examples

Is there any blocker to implement this type? If not, I have a motivation to pull request.

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

filmaj commented 5 months ago

I 100% agree with you and we definitely want to improve this!

Some of the underlying node packages that Bolt-JS relies on will need to tackle this feature, first, though. If you are curious, take a look at all the issues in the slackapi/node-slack-sdk repo tagged with the typescript label. Essentially, these payloads would need proper typing and would live in, I think, the @slack/types repo (which lives within the slackapi/node-slack-sdk repo). Specifically, I think https://github.com/slackapi/node-slack-sdk/issues/1395 is the issue tracking adding properly typed payloads to @slack/types.

I am itching to address this but work in this area has taken a backseat to other priorities.

I will leave this issue open until we can add support to the underlying @slack/types package. Once https://github.com/slackapi/node-slack-sdk/issues/1395 is resolved, we can look at leveraging and exposing those in Bolt-JS.

That would be a breaking change, though, I think, so I will also tag this as a major version issue and assign it to the 4.0 bolt milestone.

seratch commented 5 months ago

I agree there are a few areas for improvement in this repo for TypeScript users: https://github.com/slackapi/bolt-js/issues?q=is%3Aissue+is%3Aopen+label%3ATypeScript-specific

Nonetheless, specifically talking about the issue mentioned here, it seems there is some misinterpretation. The interactive message payload is the one for interactions within an attachment, not a block. Block action payload data is defined at https://github.com/slackapi/bolt-js/blob/main/src/types/actions/block-action.ts, and it correctly has all available properties, though its details can be improved. Hope this clarifies.

filmaj commented 5 months ago

Ahhh thank you @seratch for the clarification! My apologies, I missed that detail. Though, @sota1235 uses the Interactive Message as only an example; I read the implication in their original message as "this is just one area that is lacking in typing."

We could certainly improve the Interactive Message type; the Block Action base payload used in Bolt does have the container property (though that property's type itself could be better, but that is for a future enhancement).

I feel like there's some way we could have InteractiveMessage extend/reuse BlockAction as there is a lot of duplication between the two; team, enterprise, user, channel, token, response_url and trigger_id seem to be the same across the two.