1use crate::activations::*;
2use crate::config::CommsConfig;
3use plexus_core::DynamicHub;
4use std::sync::Arc;
5
6pub async fn build_comms_hub(config: CommsConfig) -> Result<Arc<DynamicHub>, String> {
8 let mut hub = DynamicHub::new("comms");
9
10 let email = Email::new()
12 .await
13 .map_err(|e| format!("Failed to initialize email activation: {}", e))?;
14 hub = hub.register(email);
15 tracing::info!("Email activation registered (multi-account mode)");
16
17 let discord = Discord::new()
19 .await
20 .map_err(|e| format!("Failed to initialize Discord activation: {}", e))?;
21 hub = hub.register(discord);
22 tracing::info!("Discord activation registered (multi-account mode)");
23
24 if let Some(sms_config) = config.sms {
26 let sms = Sms::new(sms_config)
27 .await
28 .map_err(|e| format!("Failed to initialize SMS activation: {}", e))?;
29 hub = hub.register(sms);
30 tracing::info!("SMS activation registered");
31 }
32
33 if let Some(push_config) = config.push {
35 let push = Push::new(push_config)
36 .await
37 .map_err(|e| format!("Failed to initialize push activation: {}", e))?;
38 hub = hub.register(push);
39 tracing::info!("Push activation registered");
40 }
41
42 if let Some(telegram_config) = config.telegram {
44 let telegram = Telegram::new(telegram_config)
45 .await
46 .map_err(|e| format!("Failed to initialize Telegram activation: {}", e))?;
47 hub = hub.register(telegram);
48 tracing::info!("Telegram activation registered");
49 }
50
51 if let Some(whatsapp_config) = config.whatsapp {
53 let whatsapp = Whatsapp::new(whatsapp_config)
54 .await
55 .map_err(|e| format!("Failed to initialize WhatsApp activation: {}", e))?;
56 hub = hub.register(whatsapp);
57 tracing::info!("WhatsApp activation registered");
58 }
59
60 if let Some(slack_config) = config.slack {
62 let slack = Slack::new(slack_config)
63 .await
64 .map_err(|e| format!("Failed to initialize Slack activation: {}", e))?;
65 hub = hub.register(slack);
66 tracing::info!("Slack activation registered");
67 }
68
69 Ok(Arc::new(hub))
70}
71
72pub async fn build_default_hub() -> Result<Arc<DynamicHub>, String> {
74 build_comms_hub(CommsConfig::default()).await
75}
76
77pub async fn build_from_config_file(path: &str) -> Result<Arc<DynamicHub>, String> {
79 let config_str = std::fs::read_to_string(path)
80 .map_err(|e| format!("Failed to read config file: {}", e))?;
81
82 let config: CommsConfig = toml::from_str(&config_str)
83 .map_err(|e| format!("Failed to parse config file: {}", e))?;
84
85 build_comms_hub(config).await
86}