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

Implement view submission and view closed handling on @slack/interactive-messages #904

Merged
merged 7 commits into from
Nov 12, 2019

Conversation

aoberoi
Copy link
Contributor

@aoberoi aoberoi commented Nov 8, 2019

Summary

Implements view submission handling as described in #288

Requirements (place an x in each [ ])

@aoberoi aoberoi added semver:minor pkg:interactive-messages (deprecated) applies to `@slack/interactive-messages` labels Nov 8, 2019
@aoberoi aoberoi requested a review from shaydewael November 8, 2019 23:53
@codecov
Copy link

codecov bot commented Nov 9, 2019

Codecov Report

Merging #904 into master will decrease coverage by 0.46%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #904      +/-   ##
==========================================
- Coverage   95.63%   95.17%   -0.47%     
==========================================
  Files          12       12              
  Lines         687      725      +38     
  Branches      147      164      +17     
==========================================
+ Hits          657      690      +33     
- Misses         11       13       +2     
- Partials       19       22       +3
Flag Coverage Δ
#eventsapi 89.61% <ø> (ø) ⬆️
#interactivemessages 95.22% <ø> (-1.12%) ⬇️
#webapi 98.51% <ø> (ø) ⬆️
#webhook 87.5% <ø> (ø) ⬆️
Impacted Files Coverage Δ
src/adapter.ts 95.52% <0%> (-1.59%) ⬇️

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 039e137...5fcba28. Read the comment docs.

*
* TODO: describe the payload and return values more specifically?
*/
type ViewSubmissionHandler = (payload: any) => any | Promise<any> | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

The types for these are in Bolt if you want them - https://github.com/slackapi/bolt/blob/master/src/types/view/index.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought - the options are to depend on @slack/bolt to get these types, to duplicate those types in @slack/interactive-messages, or to move those types into @slack/types (and then refactor Bolt and this package to grab those types from that package).

I think the ideal solution is the last one, but I don't think its wise to increase scope of this feature to get that done. In the meantime, I think we can proceed with this approach and revisit the refactoring of all payload types into @slack/types at a later time. Many other packages might also benefit from this.

@@ -486,6 +543,52 @@ export class SlackMessageAdapter {
}
}

if (constraints.handlerType === StoredConstraintsType.ViewSubmission) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These checks seem correct, but this and the ViewClosed constraints are the same. Is there a reason we can't combine them to reduce code duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a slight difference which is the first conditional within each section. The first checks for view_submission and the second checks for view_closed. But now that you point it out there's likely a way to reduce the code duplication - thanks!

*/
export interface ViewConstraints {
callbackId?: string | RegExp;
externalId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we allow RegExp for externalId too? Since they are unique on a per-user basis, it would be really hard to setup a handler for them with a type of string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Earlier I was trying not to expand scope so I didn't add RegExp matching to anything new - but now that you point it out that totally makes sense as a use case. It's not too much work to add that in now, so I might as well.

@pitininja
Copy link

Hello,
I have been testing this feature on this branch.
When I do a view_submission with debug, the condition in adapter.ts on line 454 is always matched because callback_id is not in payload but in payload.view.

// from matchCallback function
if (isString(constraints.callbackId) && payload.callback_id !== constraints.callbackId) {
    return false;
}

Maybe I am doing something wrong?
Sorry if I should not be posted here 🙏
Thank you for your work

@aoberoi
Copy link
Contributor Author

aoberoi commented Nov 11, 2019

@pitininja you're totally right! thanks for catching that.

@aoberoi
Copy link
Contributor Author

aoberoi commented Nov 12, 2019

@pitininja fixed the issue you pointed out (and the ones @shanedewael pointed out too).

we're likely releasing this change tomorrow.

@aoberoi aoberoi merged commit f9de24d into slackapi:master Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:interactive-messages (deprecated) applies to `@slack/interactive-messages` semver:minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants