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)]
47 pub link_by_workspace_email: bool,
48}
49
50const fn default_enabled() -> bool {
51 true
52}
53
54impl SlackAppConfig {
55 #[must_use]
56 pub fn agent_for(&self, key: &str) -> Option<&AgentName> {
57 self.routing.get(key).or(self.default_agent.as_ref())
58 }
59
60 pub fn validate(&self, name: &str) -> Result<(), ConfigValidationError> {
61 if self.workspace_id.as_str().is_empty() {
62 return Err(ConfigValidationError::invalid_field(format!(
63 "slack app '{name}' has an empty workspace_id"
64 )));
65 }
66 if self.default_agent.is_none() && self.routing.is_empty() {
67 return Err(ConfigValidationError::required(format!(
68 "slack app '{name}' must set default_agent or at least one routing entry"
69 )));
70 }
71 Ok(())
72 }
73}