Skip to content

Commit

Permalink
Expose user ID in context (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmatok authored May 24, 2023
1 parent 53bb992 commit 60b9862
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface AuthorizeResult {
userToken?: string; // used by `say` (overridden by botToken)
botId?: string; // required for `ignoreSelf` global middleware
botUserId?: string; // optional but allows `ignoreSelf` global middleware be more filter more than just message events
userId?: string;
teamId?: string;
enterpriseId?: string;
// TODO: for better type safety, we may want to revisit this
Expand Down Expand Up @@ -903,6 +904,11 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
}
}

// Try to set userId from AuthorizeResult before using one from source
if (authorizeResult.userId === undefined && source.userId !== undefined) {
authorizeResult.userId = source.userId;
}

// Try to set teamId from AuthorizeResult before using one from source
if (authorizeResult.teamId === undefined && source.teamId !== undefined) {
authorizeResult.teamId = source.teamId;
Expand Down
4 changes: 4 additions & 0 deletions src/types/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export interface Context extends StringIndexed {
* This value is optional but allows `ignoreSelf` global middleware be more filter more than just message events.
*/
botUserId?: string;
/**
* User ID.
*/
userId?: string;
/**
* Workspace ID.
*/
Expand Down

0 comments on commit 60b9862

Please sign in to comment.