forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsandbox-channels.ts
More file actions
107 lines (98 loc) · 4.23 KB
/
Copy pathsandbox-channels.ts
File metadata and controls
107 lines (98 loc) · 4.23 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { deleteCredential, saveCredential } from "./credentials";
export interface ChannelDef {
envKey: string;
description: string;
help: string;
label: string;
appTokenEnvKey?: string;
appTokenHelp?: string;
appTokenLabel?: string;
userIdEnvKey?: string;
userIdHelp?: string;
userIdLabel?: string;
allowIdsMode?: "dm" | "guild";
serverIdEnvKey?: string;
serverIdHelp?: string;
serverIdLabel?: string;
requireMentionEnvKey?: string;
requireMentionHelp?: string;
tokenFormat?: RegExp;
tokenFormatHint?: string;
appTokenFormat?: RegExp;
appTokenFormatHint?: string;
}
export const KNOWN_CHANNELS: Record<string, ChannelDef> = {
telegram: {
envKey: "TELEGRAM_BOT_TOKEN",
description: "Telegram bot messaging",
help: "Create a bot via @BotFather on Telegram, then copy the token.",
label: "Telegram Bot Token",
userIdEnvKey: "TELEGRAM_ALLOWED_IDS",
userIdHelp: "Send /start to @userinfobot on Telegram to get your numeric user ID.",
userIdLabel: "Telegram User ID (for DM access)",
allowIdsMode: "dm",
requireMentionEnvKey: "TELEGRAM_REQUIRE_MENTION",
requireMentionHelp:
"Controls Telegram group-chat behavior only — reply only when @mentioned vs. to all group messages. Direct messages are unaffected by this setting and remain subject to pairing and TELEGRAM_ALLOWED_IDS.",
},
discord: {
envKey: "DISCORD_BOT_TOKEN",
description: "Discord bot messaging",
help: "Discord Developer Portal → Applications → Bot → Reset/Copy Token.",
label: "Discord Bot Token",
serverIdEnvKey: "DISCORD_SERVER_ID",
serverIdHelp:
"Enable Developer Mode in Discord, then right-click your server and copy the Server ID.",
serverIdLabel: "Discord Server ID (for guild workspace access)",
requireMentionEnvKey: "DISCORD_REQUIRE_MENTION",
requireMentionHelp:
"Choose whether the bot should reply only when @mentioned or to all messages in this server.",
userIdEnvKey: "DISCORD_USER_ID",
userIdHelp:
"Optional: enable Developer Mode in Discord, then right-click your user/avatar and copy the User ID. Leave blank to allow any member of the configured server to message the bot.",
userIdLabel: "Discord User ID (optional guild allowlist)",
allowIdsMode: "guild",
},
slack: {
envKey: "SLACK_BOT_TOKEN",
description: "Slack bot messaging",
help: "Slack API → Your Apps → OAuth & Permissions → Bot User OAuth Token (xoxb-...).",
label: "Slack Bot Token",
tokenFormat: /^xoxb-[A-Za-z0-9_-]+$/,
tokenFormatHint: "Slack bot tokens start with 'xoxb-' (e.g. xoxb-1234-5678-abcdef).",
appTokenEnvKey: "SLACK_APP_TOKEN",
appTokenHelp: "Slack API → Your Apps → Basic Information → App-Level Tokens (xapp-...).",
appTokenLabel: "Slack App Token (Socket Mode)",
appTokenFormat: /^xapp-[A-Za-z0-9_-]+$/,
appTokenFormatHint: "Slack app tokens start with 'xapp-' (e.g. xapp-1-A0000-12345-abcdef).",
userIdEnvKey: "SLACK_ALLOWED_USERS",
userIdHelp:
"In Slack, open each allowed human user's profile -> More -> Copy member ID. Enter one or more comma-separated member IDs, not the app or bot user ID. Member IDs look like U01ABC2DEF3.",
userIdLabel: "Slack Member IDs (comma-separated allowlist)",
allowIdsMode: "dm",
},
};
export function getChannelDef(name: string): ChannelDef | undefined {
return KNOWN_CHANNELS[name.trim().toLowerCase()];
}
export function knownChannelNames(): string[] {
return Object.keys(KNOWN_CHANNELS);
}
export function listChannels(): Array<{ name: string } & ChannelDef> {
return Object.entries(KNOWN_CHANNELS).map(([name, def]) => ({ name, ...def }));
}
export function getChannelTokenKeys(channel: ChannelDef): string[] {
return channel.appTokenEnvKey ? [channel.envKey, channel.appTokenEnvKey] : [channel.envKey];
}
export function persistChannelTokens(tokens: Record<string, string>): void {
for (const [key, value] of Object.entries(tokens)) {
saveCredential(key, value);
}
}
export function clearChannelTokens(channel: ChannelDef): void {
for (const key of getChannelTokenKeys(channel)) {
deleteCredential(key);
}
}