flows_connector_dsi/
twilio.rs

1use serde::Serialize;
2
3#[derive(Serialize)]
4pub struct OutboundData {
5    #[serde(rename = "To")]
6    to: String,
7    #[serde(rename = "Body")]
8    body: Option<String>,
9}
10
11impl OutboundData {
12    /// Set the body.
13    pub fn body<S: Into<String>>(mut self, body: S) -> OutboundData {
14        self.body = Some(body.into());
15        self
16    }
17
18    /// Build outbound JSON data.
19    pub fn build(self) -> Result<String, String> {
20        if self.body.is_none() {
21            return Err("OutboundData build failed: Body is empty".to_string());
22        }
23
24        serde_json::to_string(&self)
25            .map_err(|e| format!("OutboundData build failed: {}", e.to_string()))
26    }
27}
28
29/// Send a SMS message via Twilio.
30/// 
31/// eg.
32/// ```rust
33/// outbound("+11234567890")
34///     .body("This is a test message")
35///     .build()
36/// ```
37pub fn outbound<S: Into<String>>(phone_number: S) -> OutboundData {
38    OutboundData {
39        to: phone_number.into(),
40        body: None,
41    }
42}