forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmessaging-config.ts
More file actions
74 lines (65 loc) · 2.24 KB
/
Copy pathmessaging-config.ts
File metadata and controls
74 lines (65 loc) · 2.24 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import type { DiscordGuilds, MessagingAllowedIds } from "./build-env.ts";
const CHANNEL_TOKEN_ENVS: Record<string, string[]> = {
telegram: ["TELEGRAM_BOT_TOKEN"],
discord: ["DISCORD_BOT_TOKEN"],
slack: ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"],
};
export function buildMessagingEnvLines(
enabledChannels: Set<string>,
allowedIds: MessagingAllowedIds,
discordGuilds: DiscordGuilds,
): string[] {
const envLines = ["API_SERVER_PORT=18642", "API_SERVER_HOST=127.0.0.1"];
for (const channel of enabledChannels) {
const envKeys = CHANNEL_TOKEN_ENVS[channel] ?? [];
for (const envKey of envKeys) {
envLines.push(`${envKey}=openshell:resolve:env:${envKey}`);
}
}
const discordAllowedUsers = collectDiscordAllowedUsers(allowedIds, discordGuilds);
if (discordAllowedUsers.length > 0) {
envLines.push(`DISCORD_ALLOWED_USERS=${discordAllowedUsers.join(",")}`);
}
if (allowedIds.telegram?.length) {
envLines.push(`TELEGRAM_ALLOWED_USERS=${allowedIds.telegram.map(String).join(",")}`);
}
if (allowedIds.slack?.length) {
envLines.push(`SLACK_ALLOWED_USERS=${allowedIds.slack.map(String).join(",")}`);
}
return envLines;
}
export function buildDiscordConfig(discordGuilds: DiscordGuilds): Record<string, unknown> {
return {
require_mention: getDiscordRequireMention(discordGuilds),
free_response_channels: "",
allowed_channels: "",
auto_thread: true,
reactions: true,
channel_prompts: {},
};
}
function getDiscordRequireMention(discordGuilds: DiscordGuilds): boolean {
for (const guildConfig of Object.values(discordGuilds)) {
if (typeof guildConfig?.requireMention === "boolean") {
return guildConfig.requireMention;
}
}
return true;
}
function collectDiscordAllowedUsers(
allowedIds: MessagingAllowedIds,
discordGuilds: DiscordGuilds,
): string[] {
const users = new Set<string>();
for (const user of allowedIds.discord ?? []) {
users.add(String(user));
}
for (const guildConfig of Object.values(discordGuilds)) {
for (const user of guildConfig?.users ?? []) {
users.add(String(user));
}
}
return [...users];
}