systemprompt_models/services/
slack.rs1use std::collections::BTreeMap;
16
17use schemars::JsonSchema;
18use serde::{Deserialize, Serialize};
19use systemprompt_identifiers::{AgentName, SecretName, SlackWorkspaceId};
20
21use crate::errors::ConfigValidationError;
22
23#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
24#[serde(deny_unknown_fields)]
25pub struct SlackAppConfig {
26 pub workspace_id: SlackWorkspaceId,
27 pub signing_secret_ref: SecretName,
28 pub bot_token_ref: SecretName,
29 #[serde(default = "default_enabled")]
30 pub enabled: bool,
31 #[serde(default, skip_serializing_if = "Option::is_none")]
32 pub default_agent: Option<AgentName>,
33 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
34 pub routing: BTreeMap<String, AgentName>,
35 #[serde(default)]
36 pub authz: SlackAuthzConfig,
37}
38
39#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
40#[serde(deny_unknown_fields)]
41pub struct SlackAuthzConfig {
42 #[serde(default)]
43 pub allowed_roles: Vec<String>,
44 #[serde(default)]
46 pub link_by_workspace_email: bool,
47}
48
49const fn default_enabled() -> bool {
50 true
51}
52
53impl SlackAppConfig {
54 #[must_use]
55 pub fn agent_for(&self, key: &str) -> Option<&AgentName> {
56 self.routing.get(key).or(self.default_agent.as_ref())
57 }
58
59 pub fn validate(&self, name: &str) -> Result<(), ConfigValidationError> {
60 if self.workspace_id.as_str().is_empty() {
61 return Err(ConfigValidationError::invalid_field(format!(
62 "slack app '{name}' has an empty workspace_id"
63 )));
64 }
65 if self.default_agent.is_none() && self.routing.is_empty() {
66 return Err(ConfigValidationError::required(format!(
67 "slack app '{name}' must set default_agent or at least one routing entry"
68 )));
69 }
70 Ok(())
71 }
72}