diff --git a/src/automations.rs b/src/automations.rs index f00dfb6..1383bac 100644 --- a/src/automations.rs +++ b/src/automations.rs @@ -7,8 +7,8 @@ use crate::{ list_opts::{ListOptions, ListResponse}, types::{ Automation, AutomationMinimal, AutomationRun, CreateAutomationOptions, - CreateAutomationResponse, DeleteAutomationResponse, StopAutomationResponse, - UpdateAutomationOptions, UpdateAutomationResponse, + CreateAutomationResponse, DeleteAutomationResponse, DuplicateAutomationResponse, + StopAutomationResponse, UpdateAutomationOptions, UpdateAutomationResponse, }, }; @@ -93,6 +93,20 @@ impl AutomationsSvc { Ok(content) } + /// Duplicate an existing automation. + /// + /// + #[maybe_async::maybe_async] + pub async fn duplicate(&self, automation_id: &str) -> Result { + let path = format!("/automations/{automation_id}/duplicate"); + + let request = self.0.build(Method::POST, &path); + let response = self.0.send(request).await?; + let content = response.json::().await?; + + Ok(content) + } + /// Remove an existing automation. /// /// @@ -429,6 +443,12 @@ pub mod types { pub status: AutomationStatus, } + #[must_use] + #[derive(Debug, Clone, Serialize, Deserialize)] + pub struct DuplicateAutomationResponse { + pub id: AutomationId, + } + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DeleteAutomationResponse { pub id: AutomationId, @@ -594,6 +614,12 @@ mod test { .await?; assert!(runs.data.is_empty()); + // Duplicate + let duplicated = resend.automations.duplicate(&automation.id).await?; + std::thread::sleep(std::time::Duration::from_secs(2)); + let deleted = resend.automations.delete(&duplicated.id).await?; + assert!(deleted.deleted); + // Stop let automation = resend.automations.stop(&automation.id).await?; diff --git a/src/lib.rs b/src/lib.rs index eaa936a..a60d53d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,9 +106,9 @@ pub mod types { AddToSegmentStepConfig, Automation, AutomationId, AutomationMinimal, AutomationRun, AutomationRunId, AutomationStatus, AutomationTemplate, Connection, ConnectionType, CreateAutomationOptions, CreateAutomationResponse, DelayStepConfig, - DeleteAutomationResponse, SendEmailStepConfig, Step, StopAutomationResponse, - TriggerStepConfig, UpdateAutomationOptions, UpdateAutomationResponse, - WaitForEventStepConfig, + DeleteAutomationResponse, DuplicateAutomationResponse, SendEmailStepConfig, Step, + StopAutomationResponse, TriggerStepConfig, UpdateAutomationOptions, + UpdateAutomationResponse, WaitForEventStepConfig, }; pub use super::batch::types::{ BatchValidation, PermissiveBatchErrors, SendEmailBatchPermissiveResponse,