Skip to content

Commit cfeb6ed

Browse files
committed
add Get Current User action
Copies the action with the same name added to the Slack app in the master branch.
1 parent 135030d commit cfeb6ed

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import slack from "../../slack.app.mjs";
2+
3+
export default {
4+
key: "slack_v2-get-current-user",
5+
name: "Get Current User",
6+
description: "Retrieve comprehensive context about the authenticated Slack member, combining `auth.test`, `users.info`, `users.profile.get`, and `team.info` payloads. Returns the user’s profile (name variants, email, locale, timezone, status, admin flags), raw auth test data, and workspace metadata (domain, enterprise info, icons). Ideal when you need to confirm which user token is active, tailor messages to their locale/timezone, or ground an LLM in the member’s role and workspace before executing other Slack actions. [See Slack API docs](https://api.slack.com/methods/auth.test).",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
slack,
16+
},
17+
async run({ $ }) {
18+
const authContext = await this.slack.authTest();
19+
20+
const userId = authContext.user_id || authContext.user;
21+
if (!userId) {
22+
throw new Error(`Unable to determine user ID from auth context. Received: ${JSON.stringify(authContext)}`);
23+
}
24+
25+
let userInfo;
26+
try {
27+
userInfo = await this.slack.usersInfo({
28+
user: userId,
29+
include_locale: true,
30+
});
31+
} catch (error) {
32+
// Gracefully degrade if scope not available
33+
}
34+
35+
let userProfile;
36+
try {
37+
userProfile = await this.slack.getUserProfile({
38+
user: userId,
39+
});
40+
} catch (error) {
41+
// Gracefully degrade if scope not available
42+
}
43+
44+
let teamInfo;
45+
try {
46+
teamInfo = await this.slack.getTeamInfo();
47+
} catch (error) {
48+
// Gracefully degrade if scope not available
49+
}
50+
51+
const user = userInfo?.user;
52+
const profile = userProfile?.profile ?? user?.profile;
53+
const summaryName =
54+
profile?.real_name_normalized
55+
|| profile?.display_name_normalized
56+
|| authContext.user
57+
|| userId;
58+
59+
$.export("$summary", `Retrieved Slack user ${summaryName}`);
60+
61+
return {
62+
authContext,
63+
user,
64+
profile,
65+
team: teamInfo?.team,
66+
};
67+
},
68+
};

0 commit comments

Comments
 (0)