Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29fcf41a9c
|
||
|
|
f0ffc580e6
|
||
|
|
57d16c6996
|
Generated
+7
@@ -57,6 +57,12 @@ version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "base64-ng"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8452b0c98385f31f08318109d6e06a859f89e0c5e38aad6103f095443b063052"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.12.1"
|
||||
@@ -1569,6 +1575,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
name = "swoosh"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"base64-ng",
|
||||
"const_format",
|
||||
"futures",
|
||||
"http",
|
||||
|
||||
@@ -15,6 +15,7 @@ reqwest = { version = "0.13.3", features = ["form", "json", "blocking", "multipa
|
||||
rand = { version = "0.10.1" }
|
||||
time = { version = "0.3.47", features = ["formatting", "macros", "parsing", "serde"] }
|
||||
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
||||
base64-ng = { version = "1.0.6" }
|
||||
const_format = { version = "0.2.36" }
|
||||
josekit = { version = "0.10.3" }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0-20-15820d5505-111" }
|
||||
|
||||
+39
-5
@@ -22,8 +22,9 @@ pub async fn send_mssage(
|
||||
"application/x-www-form-urlencoded".parse().unwrap(),
|
||||
);
|
||||
headers.insert("Accept", "application/json".parse().unwrap());
|
||||
let auth = generate_auth(&config);
|
||||
let auth = generate_auth(config).unwrap();
|
||||
// headers.insert("Authorization", "Basic QUNlZmExZWY1MTYzMTRjOWQxYTY4Y2JkNjU3ZGU0OTI3NzpmNGExZjJiMGI3OWVhMzczNTA3OGMyZDhlZTk2ODRlMQ==".parse()?);
|
||||
headers.insert("Authorization", auth.parse().unwrap());
|
||||
|
||||
let mut params = std::collections::HashMap::new();
|
||||
params.insert("To", contact.phone_number.as_str());
|
||||
@@ -59,7 +60,7 @@ pub async fn send_mssage(
|
||||
params.insert("Body", msg.content.as_str());
|
||||
|
||||
let url = format!(
|
||||
"https://api.twilio.com/2010-04-01/Accounts/ACefa1ef516314c9d1a68cbd657de49277/Messages.json"
|
||||
"https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json", config.account_sid
|
||||
);
|
||||
|
||||
// let client = reqwest::Client::new();
|
||||
@@ -72,10 +73,19 @@ pub async fn send_mssage(
|
||||
|
||||
match request.send().await {
|
||||
Ok(response) => {
|
||||
match response.json::<crate::twilio::api::types::TwilioAPIMessage>().await {
|
||||
Ok(resp) => {
|
||||
Ok(resp)
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::other(err))
|
||||
}
|
||||
}
|
||||
/*
|
||||
match response.text().await {
|
||||
Ok(body) => {
|
||||
let mut obj = crate::twilio::api::types::TwilioAPIMessage {
|
||||
..Default::default()
|
||||
let mut obj = crate::twilio::api::types::TwilioAPIMessage {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Ok(obj)
|
||||
@@ -84,6 +94,7 @@ pub async fn send_mssage(
|
||||
Err(std::io::Error::other(err))
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
@@ -93,6 +104,17 @@ pub async fn send_mssage(
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_auth(config: &textsender_models::config::auxiliary::TwilioConfig) -> Result<String, base64_ng::EncodeError> {
|
||||
let input = format!("{}:{}", config.account_sid, config.auth_token);
|
||||
match base64_ng::encode(input.as_bytes()) {
|
||||
Ok(encoded) => {
|
||||
Ok(format!("Basic {encoded}"))
|
||||
}
|
||||
Err(err) => {
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -191,5 +213,17 @@ fn is_scheduleable(
|
||||
now: &Option<time::OffsetDateTime>,
|
||||
scheduled: &Option<time::OffsetDateTime>,
|
||||
) -> bool {
|
||||
true
|
||||
match scheduled {
|
||||
Some(schedule_at) => {
|
||||
let early = now.unwrap().checked_add(time::Duration::seconds(300)).unwrap();
|
||||
if *schedule_at > early {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
None => {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user