slackapi / node-slack-sdk

Slack Developer Kit for Node.js
https://slack.dev/node-slack-sdk
MIT License
3.26k stars 656 forks source link

socket-mode: Type event payloads #1768

Open slifty opened 3 months ago

slifty commented 3 months ago

I'm using @slack/socket-mode in a TypeScript project and would love to be able to benefit from type definitions when defining event handlers -- e.g. when I invoke something along the lines of

socketModeClient.on(
  'reaction_added',
  async (event) => {
    ...
  }
);

I'd like event to not be of the any type but instead to reflect the expected type for the event in question.

It looks like there are libraries that might support this, for your consideration.

Packages:

Select all that apply:

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 3 months ago

I agree this would be a fantastic enhancement. The issue is that perfect typing for Slack payload events is challenging, as the payloads can be quite contextual. For example, depending on the Slack workspace type (enterprise vs. standalone), the payloads might differ. Additionally, some payloads may or may not contain properties depending on the context, for example a block_actions payload contains a container property, which might be a View object or might be a containing message.

That said, at least some baseline form of event typing should be doable. I will leave this as an enhancement issue open but can make no promises on a delivery timeline.