use actix_web::{post, web, App, HttpResponse, HttpServer, Responder};
use cots::agents::{AgentClient, AgentConfig, NormalizedAction};
#[post("/notify")]
async fn notify(agent: web::Data<AgentClient>) -> impl Responder {
let result = agent
.guard(NormalizedAction::new("Slack", "send_slack_message"), || async {
"sent (actix)"
})
.await;
match result {
Ok(r) => HttpResponse::Ok().json(serde_json::json!({
"action_event_id": r.action_event_id,
"decision": r.decision,
"outcome": format!("{:?}", r.outcome),
})),
Err(e) => HttpResponse::BadGateway().body(e.to_string()),
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let agent = web::Data::new(AgentClient::new(AgentConfig::new("ten_demo", "agt_demo")));
println!("actix-web + cots::agents on http://127.0.0.1:8090");
HttpServer::new(move || App::new().app_data(agent.clone()).service(notify))
.bind(("127.0.0.1", 8090))?
.run()
.await
}