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

socket-mode: Type event payloads #1768

Open
1 of 7 tasks
slifty opened this issue Apr 2, 2024 · 2 comments
Open
1 of 7 tasks

socket-mode: Type event payloads #1768

slifty opened this issue Apr 2, 2024 · 2 comments
Assignees
Labels
area:typescript issues that specifically impact using the package from typescript projects auto-triage-skip enhancement M-T: A feature request for new functionality pkg:socket-mode applies to `@slack/socket-mode` semver:major

Comments

@slifty
Copy link
Contributor

slifty commented Apr 2, 2024

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:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • @slack/types
  • I don't know

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.

@slifty slifty changed the title (Set a clear title describing your idea) Add type definitions to socket-mode events Apr 2, 2024
slifty added a commit to slifty/aprilbot that referenced this issue Apr 2, 2024
This boilerplate creates some basic AprilBot functionality for
connecting to slack and handling some basic types of interactions.

I had to create types for the event handlers for now, though I opened an
issue in the Slack sdk in the hopes they might add types [1] to their
events.

This also swaps out the class-methods-use-this lint rule for a smarter
variety, which is probably something that the upstream maintainer should
consider adding as well [2].

[1] slackapi/node-slack-sdk#1768
[2] iamturns/eslint-config-airbnb-typescript#344
@filmaj filmaj added enhancement M-T: A feature request for new functionality area:typescript issues that specifically impact using the package from typescript projects pkg:socket-mode applies to `@slack/socket-mode` and removed untriaged labels Apr 2, 2024
@filmaj
Copy link
Contributor

filmaj commented Apr 2, 2024

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.

@filmaj filmaj changed the title Add type definitions to socket-mode events socket-mode: Type event payloads Apr 2, 2024
@filmaj filmaj mentioned this issue Jun 14, 2024
7 tasks
@filmaj
Copy link
Contributor

filmaj commented Aug 29, 2024

I suppose this would technically be a breaking change, yes? Going from any to something more specific may possibly break existing apps, so this would be a major version change - but would be a great one!

This issue comment in the EventEmitter3 package that powers socket-mode has some great examples of using its generics support to provide nice type completion. I think this would be worthwhile doing!

First, though, what needs to happen:

Once these are in place, we can consume the new @slack/[email protected]+ package and leverage EventEmitter3 generics to provide a much better experience for socket-mode consumers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typescript issues that specifically impact using the package from typescript projects auto-triage-skip enhancement M-T: A feature request for new functionality pkg:socket-mode applies to `@slack/socket-mode` semver:major
Projects
None yet
Development

No branches or pull requests

3 participants