Skip to main content

plexus_comms/
config.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct CommsConfig {
6    pub email: Option<EmailConfig>,
7    pub sms: Option<SmsConfig>,
8    pub push: Option<PushConfig>,
9    pub telegram: Option<TelegramConfig>,
10    pub whatsapp: Option<WhatsappConfig>,
11    pub slack: Option<SlackConfig>,
12    pub discord: Option<DiscordConfig>,
13}
14
15impl Default for CommsConfig {
16    fn default() -> Self {
17        Self {
18            email: Some(EmailConfig::default()),
19            sms: None,
20            push: None,
21            telegram: None,
22            whatsapp: None,
23            slack: None,
24            discord: None,
25        }
26    }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct EmailConfig {
31    pub provider: EmailProvider,
32    #[serde(flatten)]
33    pub credentials: EmailCredentials,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(tag = "provider", rename_all = "lowercase")]
38pub enum EmailProvider {
39    Smtp,
40    SendGrid,
41    Ses,
42    Mailgun,
43    Postmark,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum EmailCredentials {
49    Smtp {
50        smtp_host: String,
51        smtp_port: u16,
52        smtp_username: String,
53        smtp_password: String,
54        smtp_from: String,
55    },
56    ApiKey {
57        api_key: String,
58        from_email: String,
59        from_name: Option<String>,
60    },
61    Aws {
62        region: String,
63        from_email: String,
64    },
65}
66
67impl Default for EmailConfig {
68    fn default() -> Self {
69        Self {
70            provider: EmailProvider::Smtp,
71            credentials: EmailCredentials::Smtp {
72                smtp_host: "localhost".to_string(),
73                smtp_port: 25,
74                smtp_username: "".to_string(),
75                smtp_password: "".to_string(),
76                smtp_from: "noreply@localhost".to_string(),
77            },
78        }
79    }
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct SmsConfig {
84    pub provider: SmsProvider,
85    #[serde(flatten)]
86    pub credentials: SmsCredentials,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(tag = "provider", rename_all = "lowercase")]
91pub enum SmsProvider {
92    Twilio,
93    Sns,
94    Vonage,
95    MessageBird,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum SmsCredentials {
101    Twilio {
102        account_sid: String,
103        auth_token: String,
104        from_number: String,
105    },
106    Aws {
107        region: String,
108    },
109    ApiKey {
110        api_key: String,
111        api_secret: Option<String>,
112        from_number: String,
113    },
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct PushConfig {
118    pub ios: Option<ApnsConfig>,
119    pub android: Option<FcmConfig>,
120    pub web: Option<WebPushConfig>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct ApnsConfig {
125    pub key_file: PathBuf,
126    pub key_id: String,
127    pub team_id: String,
128    pub environment: ApnsEnvironment,
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(rename_all = "lowercase")]
133pub enum ApnsEnvironment {
134    Production,
135    Sandbox,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
139pub struct FcmConfig {
140    pub service_account_key: PathBuf,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct WebPushConfig {
145    pub vapid_private_key: String,
146    pub vapid_public_key: String,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct TelegramConfig {
151    pub bot_token: String,
152    pub mode: TelegramMode,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(rename_all = "lowercase")]
157pub enum TelegramMode {
158    Polling,
159    Webhook { url: String },
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct WhatsappConfig {
164    pub mode: WhatsappMode,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
168#[serde(tag = "mode", rename_all = "lowercase")]
169pub enum WhatsappMode {
170    BusinessApi {
171        phone_number_id: String,
172        access_token: String,
173        webhook_verify_token: String,
174    },
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct SlackConfig {
179    pub bot_token: String,
180    pub app_token: Option<String>,
181    pub mode: SlackMode,
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
185#[serde(rename_all = "lowercase")]
186pub enum SlackMode {
187    Socket,
188    Webhook { url: String },
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct DiscordConfig {
193    pub bot_token: String,
194}