tandem_server/config/
channels.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct TelegramConfigFile {
5 pub bot_token: String,
6 #[serde(default = "default_allow_all")]
7 pub allowed_users: Vec<String>,
8 #[serde(default)]
9 pub mention_only: bool,
10 #[serde(default)]
11 pub style_profile: tandem_channels::config::TelegramStyleProfile,
12 #[serde(default)]
13 pub security_profile: tandem_channels::config::ChannelSecurityProfile,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct DiscordConfigFile {
18 pub bot_token: String,
19 #[serde(default)]
20 pub guild_id: Option<String>,
21 #[serde(default = "default_allow_all")]
22 pub allowed_users: Vec<String>,
23 #[serde(default = "default_discord_mention_only")]
24 pub mention_only: bool,
25 #[serde(default)]
26 pub security_profile: tandem_channels::config::ChannelSecurityProfile,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct SlackConfigFile {
31 pub bot_token: String,
32 pub channel_id: String,
33 #[serde(default = "default_allow_all")]
34 pub allowed_users: Vec<String>,
35 #[serde(default)]
36 pub mention_only: bool,
37 #[serde(default)]
38 pub security_profile: tandem_channels::config::ChannelSecurityProfile,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, Default)]
42pub struct ChannelsConfigFile {
43 pub telegram: Option<TelegramConfigFile>,
44 pub discord: Option<DiscordConfigFile>,
45 pub slack: Option<SlackConfigFile>,
46 #[serde(default)]
47 pub tool_policy: tandem_channels::config::ChannelToolPolicy,
48}
49
50pub fn normalize_allowed_users_or_wildcard(raw: Vec<String>) -> Vec<String> {
51 let normalized = normalize_non_empty_list(raw);
52 if normalized.is_empty() {
53 return default_allow_all();
54 }
55 normalized
56}
57
58pub fn normalize_allowed_tools(raw: Vec<String>) -> Vec<String> {
59 normalize_non_empty_list(raw)
60}
61
62fn default_allow_all() -> Vec<String> {
63 vec!["*".to_string()]
64}
65
66fn default_discord_mention_only() -> bool {
67 true
68}
69
70fn normalize_non_empty_list(raw: Vec<String>) -> Vec<String> {
71 let mut out = Vec::new();
72 let mut seen = std::collections::HashSet::new();
73 for item in raw {
74 let normalized = item.trim().to_string();
75 if normalized.is_empty() {
76 continue;
77 }
78 if seen.insert(normalized.clone()) {
79 out.push(normalized);
80 }
81 }
82 out
83}