From 60b98622ec243710fac2d21a260721cf7ddafcc0 Mon Sep 17 00:00:00 2001 From: Gil Matok Date: Thu, 25 May 2023 02:57:47 +0300 Subject: [PATCH] Expose user ID in context (#1853) --- src/App.ts | 6 ++++++ src/types/middleware.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/App.ts b/src/App.ts index 08b087e09..07552bc8b 100644 --- a/src/App.ts +++ b/src/App.ts @@ -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 @@ -903,6 +904,11 @@ export default class App } } + // 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; diff --git a/src/types/middleware.ts b/src/types/middleware.ts index a3189d3b7..a36fddc62 100644 --- a/src/types/middleware.ts +++ b/src/types/middleware.ts @@ -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. */