-
Notifications
You must be signed in to change notification settings - Fork 395
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
Fix context.team_id for view interactions in a Slack Connect channel #1615
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1368,29 +1368,43 @@ function buildSource<IsEnterpriseInstall extends boolean>( | |||||
return (body as SlackCommandMiddlewareArgs['body']).team_id; | ||||||
} | ||||||
|
||||||
const parseTeamId = ( | ||||||
bodyAs: | ||||||
| SlackAction | ||||||
| SlackViewAction | ||||||
| SlackShortcut | ||||||
| KnownOptionsPayloadFromType<OptionsSource>, | ||||||
): string | undefined => { | ||||||
// When the app is installed using org-wide deployment, team property will be null | ||||||
if (typeof bodyAs.team !== 'undefined' && bodyAs.team !== null) { | ||||||
return bodyAs.team.id; | ||||||
} | ||||||
|
||||||
// This is the only place where this function might return undefined | ||||||
return bodyAs.user.team_id; | ||||||
}; | ||||||
|
||||||
if (type === IncomingEventType.ViewAction) { | ||||||
const bodyAsView = body as SlackViewMiddlewareArgs['body']; | ||||||
|
||||||
if (bodyAsView.view.app_installed_team_id) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Can we also add a comment for future eyes about when this condition is met, since it's a little nuanced? Maybe mirroring what Kaz has added in his PR |
||||||
return bodyAsView.view.app_installed_team_id; | ||||||
} | ||||||
|
||||||
return parseTeamId(bodyAsView); | ||||||
} | ||||||
|
||||||
if ( | ||||||
type === IncomingEventType.Action || | ||||||
type === IncomingEventType.Options || | ||||||
type === IncomingEventType.ViewAction || | ||||||
type === IncomingEventType.Shortcut | ||||||
) { | ||||||
const bodyAsActionOrOptionsOrViewActionOrShortcut = body as ( | ||||||
const bodyAsActionOrOptionsOrOrShortcut = body as ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 💯 |
||||||
| SlackActionMiddlewareArgs | ||||||
| SlackOptionsMiddlewareArgs | ||||||
| SlackViewMiddlewareArgs | ||||||
| SlackShortcutMiddlewareArgs | ||||||
)['body']; | ||||||
|
||||||
// When the app is installed using org-wide deployment, team property will be null | ||||||
if ( | ||||||
typeof bodyAsActionOrOptionsOrViewActionOrShortcut.team !== 'undefined' && | ||||||
bodyAsActionOrOptionsOrViewActionOrShortcut.team !== null | ||||||
) { | ||||||
return bodyAsActionOrOptionsOrViewActionOrShortcut.team.id; | ||||||
} | ||||||
|
||||||
// This is the only place where this function might return undefined | ||||||
return bodyAsActionOrOptionsOrViewActionOrShortcut.user.team_id; | ||||||
return parseTeamId(bodyAsActionOrOptionsOrOrShortcut); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return assertNever(type); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for decomposing this out into its own function! Slowly but surely, the horrible mess that is App.ts will be reformed :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, we will eventually get there 🥇