2026-06-14 20:27:52 +02:00
|
|
|
use crate::{
|
|
|
|
|
actions::get_action,
|
|
|
|
|
error::AppError,
|
2026-07-02 06:51:03 +05:30
|
|
|
handlers::actions::{ConfirmActionRequest, ConfirmActionResponse},
|
2026-06-14 20:27:52 +02:00
|
|
|
};
|
|
|
|
|
|
2026-07-02 06:51:03 +05:30
|
|
|
#[derive(Clone, Default)]
|
|
|
|
|
pub struct ActionConfirmationService;
|
2026-06-14 20:27:52 +02:00
|
|
|
|
|
|
|
|
impl ActionConfirmationService {
|
2026-07-02 06:51:03 +05:30
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self
|
2026-06-14 20:27:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn confirm_action(
|
|
|
|
|
&self,
|
|
|
|
|
request: ConfirmActionRequest,
|
2026-07-23 17:32:01 +05:30
|
|
|
confirmed_by_user_id: &str,
|
2026-06-14 20:27:52 +02:00
|
|
|
) -> Result<ConfirmActionResponse, AppError> {
|
|
|
|
|
if !request.confirmed {
|
2026-07-23 17:32:01 +05:30
|
|
|
tracing::info!(
|
|
|
|
|
user_id = %confirmed_by_user_id,
|
|
|
|
|
action = %request.action,
|
|
|
|
|
conversation_id = %request.conversation_id,
|
|
|
|
|
"action confirmation cancelled by user"
|
|
|
|
|
);
|
2026-06-14 20:27:52 +02:00
|
|
|
return Ok(ConfirmActionResponse {
|
|
|
|
|
success: false,
|
2026-07-02 06:51:03 +05:30
|
|
|
delegated: false,
|
2026-06-14 20:27:52 +02:00
|
|
|
message: "Action cancelled by user.".to_string(),
|
|
|
|
|
action: request.action.clone(),
|
2026-07-02 06:51:03 +05:30
|
|
|
backend_handler: None,
|
2026-06-14 20:27:52 +02:00
|
|
|
record_id: None,
|
2026-07-02 06:51:03 +05:30
|
|
|
fields: None,
|
2026-06-14 20:27:52 +02:00
|
|
|
ui_events: None,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-02 06:51:03 +05:30
|
|
|
let action = get_action(&request.action);
|
|
|
|
|
let backend_handler = action
|
|
|
|
|
.as_ref()
|
|
|
|
|
.map(|item| item.backend_handler.clone())
|
|
|
|
|
.unwrap_or_else(|| request.action.clone());
|
2026-06-14 20:27:52 +02:00
|
|
|
|
2026-07-23 17:32:01 +05:30
|
|
|
tracing::info!(
|
|
|
|
|
user_id = %confirmed_by_user_id,
|
|
|
|
|
action = %request.action,
|
|
|
|
|
backend_handler = %backend_handler,
|
|
|
|
|
conversation_id = %request.conversation_id,
|
|
|
|
|
"action confirmed by user"
|
|
|
|
|
);
|
|
|
|
|
|
2026-06-14 20:27:52 +02:00
|
|
|
Ok(ConfirmActionResponse {
|
|
|
|
|
success: true,
|
2026-07-02 06:51:03 +05:30
|
|
|
delegated: true,
|
|
|
|
|
message: format!(
|
|
|
|
|
"Action approved. Execute '{}' in the product backend.",
|
|
|
|
|
backend_handler
|
|
|
|
|
),
|
2026-06-14 20:27:52 +02:00
|
|
|
action: request.action.clone(),
|
2026-07-02 06:51:03 +05:30
|
|
|
backend_handler: Some(backend_handler),
|
2026-06-14 20:27:52 +02:00
|
|
|
record_id: None,
|
2026-07-02 06:51:03 +05:30
|
|
|
fields: Some(request.fields),
|
|
|
|
|
ui_events: None,
|
2026-06-14 20:27:52 +02:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|