Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e68debd42
|
||
|
|
d21d72f596
|
||
|
|
29fcf41a9c
|
||
|
|
f0ffc580e6
|
||
|
|
57d16c6996
|
@@ -21,7 +21,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
@@ -60,7 +60,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
@@ -80,7 +80,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
@@ -99,7 +99,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
|
|||||||
Generated
+7
@@ -57,6 +57,12 @@ version = "0.22.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64-ng"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8452b0c98385f31f08318109d6e06a859f89e0c5e38aad6103f095443b063052"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.12.1"
|
version = "2.12.1"
|
||||||
@@ -1569,6 +1575,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||||||
name = "swoosh"
|
name = "swoosh"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64-ng",
|
||||||
"const_format",
|
"const_format",
|
||||||
"futures",
|
"futures",
|
||||||
"http",
|
"http",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ reqwest = { version = "0.13.3", features = ["form", "json", "blocking", "multipa
|
|||||||
rand = { version = "0.10.1" }
|
rand = { version = "0.10.1" }
|
||||||
time = { version = "0.3.47", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.47", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
||||||
|
base64-ng = { version = "1.0.6" }
|
||||||
const_format = { version = "0.2.36" }
|
const_format = { version = "0.2.36" }
|
||||||
josekit = { version = "0.10.3" }
|
josekit = { version = "0.10.3" }
|
||||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0-20-15820d5505-111" }
|
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(),
|
"application/x-www-form-urlencoded".parse().unwrap(),
|
||||||
);
|
);
|
||||||
headers.insert("Accept", "application/json".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", "Basic QUNlZmExZWY1MTYzMTRjOWQxYTY4Y2JkNjU3ZGU0OTI3NzpmNGExZjJiMGI3OWVhMzczNTA3OGMyZDhlZTk2ODRlMQ==".parse()?);
|
||||||
|
headers.insert("Authorization", auth.parse().unwrap());
|
||||||
|
|
||||||
let mut params = std::collections::HashMap::new();
|
let mut params = std::collections::HashMap::new();
|
||||||
params.insert("To", contact.phone_number.as_str());
|
params.insert("To", contact.phone_number.as_str());
|
||||||
@@ -59,7 +60,7 @@ pub async fn send_mssage(
|
|||||||
params.insert("Body", msg.content.as_str());
|
params.insert("Body", msg.content.as_str());
|
||||||
|
|
||||||
let url = format!(
|
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();
|
// let client = reqwest::Client::new();
|
||||||
@@ -72,10 +73,19 @@ pub async fn send_mssage(
|
|||||||
|
|
||||||
match request.send().await {
|
match request.send().await {
|
||||||
Ok(response) => {
|
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 {
|
match response.text().await {
|
||||||
Ok(body) => {
|
Ok(body) => {
|
||||||
let mut obj = crate::twilio::api::types::TwilioAPIMessage {
|
let mut obj = crate::twilio::api::types::TwilioAPIMessage {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(obj)
|
Ok(obj)
|
||||||
@@ -84,6 +94,7 @@ pub async fn send_mssage(
|
|||||||
Err(std::io::Error::other(err))
|
Err(std::io::Error::other(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -191,5 +213,17 @@ fn is_scheduleable(
|
|||||||
now: &Option<time::OffsetDateTime>,
|
now: &Option<time::OffsetDateTime>,
|
||||||
scheduled: &Option<time::OffsetDateTime>,
|
scheduled: &Option<time::OffsetDateTime>,
|
||||||
) -> bool {
|
) -> 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