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 missing message events & more type tests #832

Merged
merged 1 commit into from
Mar 17, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Mar 15, 2021

Summary

This pull request adds a few subtyped message events to top-level exports (currently, only BotMessageEvent is available in from @slack/bolt`). Also, as the very first step for #826 improvements, I've added a few more tests with TODO comments.

Requirements (place an x in each [ ])

@seratch seratch added enhancement M-T: A feature request for new functionality TypeScript-specific labels Mar 15, 2021
@seratch seratch requested review from mwbrooks and stevengill March 15, 2021 05:44
@seratch seratch self-assigned this Mar 15, 2021
@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #832 (7c6c294) into main (74368d2) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #832   +/-   ##
=======================================
  Coverage   65.89%   65.89%           
=======================================
  Files          13       13           
  Lines        1173     1173           
  Branches      343      343           
=======================================
  Hits          773      773           
  Misses        334      334           
  Partials       66       66           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74368d2...868a2eb. Read the comment docs.

Copy link
Member Author

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comments for reviewers and anyone who are interested

@@ -1,5 +1,14 @@
export * from './base-events';
export { BotMessageEvent, GenericMessageEvent } from './message-events';
export {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change to the main code side.


const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });

expectType<void>(
// TODO: Resolve the event type when having subtype in a listener constraint
// app.message({pattern: 'foo', subtype: 'message_replied'}, async ({ message }) => {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't agreed to implement this yet but this could be beneficial for some use cases. There are a few more things to consider:

  • Should we enable developers to pass multiple subtypes here?
    • If yes, the message object type in the scenario is not fully deterministic (it can be a bit more specific than MessageEvent but it's still a union type).
    • If no, for handling multiple types of subtyped message events, the right way is to have different event listeners for each subtype (some of internal code can be reused).
  • Is pattern a good key name for the pattern here?
  • app.message<"message_replied"> vs app.message(constraints or should we support both?
    • app.action and app.options are not consistent at this point (refer to my comments below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of having a constraints object here. subtype in the constraints object makes sense. pattern seems like a reasonable key name.

If we wanted to support multiple subtypes in one listener, what would that look like? An array for subtype: ['message_replied']. Having an array in a constraint object would be new, but if using one listener for multiple subtypes is a usecase we think is common and should handle, it makes sense. Maybe @shaydewael can chime in on this.

My gut feeling is app.message(constraints is more important. Does app.options not support type in constraints?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have another pull request making changes to the app.message listener signature: #761

one more suggestion for this PR: can we add some type tests within type-tests/message.test-d.ts that illustrate (and validate) the expected usage?

Although Ankur asked the contributor to add more tests, we can handle the tests for the developer. Should we merge this PR before starting to work on the change we're discussing here?

@stevengill

My gut feeling is app.message(constraints is more important. Does app.options not support type in constraints?

As I mentioned the added tests for app.options in this PR, it just does not work. I think we should make the developer experience consistent across the listeners but currently there are some gaps. Refer to the TODO/FIXME comments in this PR for details.

}));

// block_suggestion
expectType<void>(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only app.options has the string type parameter like this. app.view and app.action do not support the same way while they can determine payload type in accordance with type in a constraint object.

@stevengill
Copy link
Member

Thanks for adding all of these great type tests.

@seratch seratch merged commit 3ed08fc into slackapi:main Mar 17, 2021
@seratch seratch deleted the missing-message-events-more-tests branch March 17, 2021 08:55
@seratch seratch added this to the 3.4.0 milestone Mar 23, 2021
MessageDeletedEvent,
ThreadBroadcastMessageEvent,
MessageChangedEvent,
EKMAccessDeniedMessageEvent,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance we can export all the message events? Why is the list limited to a subset of events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jestrada Do you have anything missing in your mind?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @seratch, thanks for the reply! Ya, all of the Channel*MessageEvent types are missing which makes it impossible to refer to import them. Is it possible to export all message event types.

Reference: https://github.com/slackapi/bolt-js/blob/main/src/types/events/message-events.ts#L3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I got the point. This is an easy fix. Thanks for pointing this out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

submitted a PR to fix this: #1254

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @seratch!

@seratch seratch mentioned this pull request Dec 22, 2021
2 tasks
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 this pull request may close these issues.

4 participants