-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.ts
More file actions
54 lines (46 loc) · 1.41 KB
/
Copy pathtarget.ts
File metadata and controls
54 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
export async function onboardMemberWorkflow(ctx: any, input: {
username: string;
channel_name: string;
welcome_message: string;
}) {
const { username, channel_name, welcome_message } = input;
// Step 1: Lookup user
const userResult = await get_api_v1_users_list({
username,
});
if (!userResult || !userResult.users || userResult.users.length === 0) {
throw new Error(`User '${username}' not found`);
}
const user = userResult.users[0];
// Step 2: Ensure channel exists (create if not)
let channel;
try {
const channelResult = await ctx.runTool("get-api-v1-channels.info", {
roomName: channel_name,
});
channel = channelResult.channel;
} catch (err) {
// If not found, create channel
const createResult = await ctx.runTool("post-api-v1-channels.create", {
name: channel_name,
});
channel = createResult.channel;
}
if (!channel) {
throw new Error(`Failed to ensure channel '${channel_name}'`);
}
// Step 3: Invite member to channel
await ctx.runTool("post-api-v1-channels.invite", {
roomId: channel._id,
userId: user._id,
});
// Step 4: Send welcome message
await ctx.runTool("post-api-v1-chat.postMessage", {
roomId: channel._id,
text: welcome_message,
});
return {
success: true,
message: `User '${username}' onboarded to '${channel_name}' successfully.`,
};
}