Twilio Config refactor (#27)
Reviewed-on: phoenix/textsender_api#27
This commit was merged in pull request #27.
This commit is contained in:
Generated
+3
-3
@@ -3069,7 +3069,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
[[package]]
|
||||
name = "swoosh"
|
||||
version = "0.4.1"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/swoosh.git?tag=v0.4.1-10-9e8ec15910-871#9e8ec159102951606e30ad2013f4db8dad184fad"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/swoosh.git?tag=v0.4.1-10-6bdec12084-871#6bdec1208499dfa9962efd89b549d1bfa5441d85"
|
||||
dependencies = [
|
||||
"base64-ng",
|
||||
"const_format",
|
||||
@@ -3153,7 +3153,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "textsender_api"
|
||||
version = "0.1.20"
|
||||
version = "0.1.21"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-extra",
|
||||
@@ -3181,7 +3181,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "textsender_models"
|
||||
version = "0.4.3"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.4.3-29-7e5bc016b1-111#7e5bc016b11509d0468f10a5449c6918128f2e20"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.4.3-29-720f3d8f75-111#720f3d8f7515d8cd20a9cd73086bd6c1ab857651"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "textsender_api"
|
||||
version = "0.1.20"
|
||||
version = "0.1.21"
|
||||
edition = "2024"
|
||||
rust-version = "1.96"
|
||||
|
||||
@@ -22,8 +22,8 @@ jsonwebtoken = { version = "10.4.0", features = ["rust_crypto"] }
|
||||
josekit = { version = "0.10.3" }
|
||||
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.3-29-7e5bc016b1-111" }
|
||||
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.4.1-10-9e8ec15910-871" }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.3-29-720f3d8f75-111" }
|
||||
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.4.1-10-6bdec12084-871" }
|
||||
|
||||
[dev-dependencies]
|
||||
url = { version = "2.5.8" }
|
||||
|
||||
+13
-48
@@ -81,36 +81,34 @@ pub mod endpoint {
|
||||
match message_repo::get(&pool, &payload.message_id).await {
|
||||
Ok(message) => {
|
||||
println!("Valid message");
|
||||
let t_config = match load_config().await {
|
||||
Ok(config) => config,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error getting config");
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let t_config =
|
||||
match textsender_models::config::auxiliary::load_config().await {
|
||||
Ok(config) => config,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error getting config");
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let mut results: Vec<
|
||||
textsender_models::message::event::MessageEventResponse,
|
||||
> = Vec::new();
|
||||
// let mut results: Vec<serde_json::Value> = Vec::new();
|
||||
let pp = swoosh::twilio::types::Parameters {
|
||||
schedule: false,
|
||||
schedule_at: None,
|
||||
};
|
||||
|
||||
for contact in &contacts {
|
||||
match swoosh::twilio::api::send_mssage(
|
||||
match swoosh::twilio::api::send_message(
|
||||
&message, contact, &pp, &t_config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => {
|
||||
println!("Response: {result:?}");
|
||||
let val = swoosh::twilio::api::response_to_json(result).await;
|
||||
// results.push(val);
|
||||
let mer = textsender_models::message::event::MessageEventResponse {
|
||||
user_id: payload.user_id,
|
||||
// TODO: Make this more accurate
|
||||
@@ -170,37 +168,4 @@ pub mod endpoint {
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_config()
|
||||
-> Result<textsender_models::config::auxiliary::TwilioConfig, std::io::Error> {
|
||||
let mut config = textsender_models::config::auxiliary::TwilioConfig {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let auth_sid_var = textsender_models::envy::environment::get_env("TWILIO_AUTH_SID").await;
|
||||
println!("{auth_sid_var:?}");
|
||||
let service_sid_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_SERVICE_SID").await;
|
||||
println!("{service_sid_var:?}");
|
||||
let auth_token_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_AUTH_TOKEN").await;
|
||||
println!("{auth_token_var:?}");
|
||||
let phone_number_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_PHONE_NUMBER").await;
|
||||
println!("{phone_number_var:?}");
|
||||
|
||||
if auth_sid_var.value.is_empty()
|
||||
|| service_sid_var.value.is_empty()
|
||||
|| auth_token_var.value.is_empty()
|
||||
|| phone_number_var.value.is_empty()
|
||||
{
|
||||
Err(std::io::Error::other("Config not set"))
|
||||
} else {
|
||||
config.account_sid = auth_sid_var.value;
|
||||
config.service_sid = service_sid_var.value;
|
||||
config.auth_token = auth_token_var.value;
|
||||
config.phone_number = phone_number_var.value;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user