huskies: merge 639_refactor_migrate_whatsapp_transport_to_services_bundle
This commit is contained in:
+12
-20
@@ -564,8 +564,6 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
// Wrap perm_rx in Arc<Mutex> so it can be shared across the Services
|
||||
// bundle (AppContext + Matrix bot) and the webhook-based transports.
|
||||
let perm_rx = Arc::new(tokio::sync::Mutex::new(perm_rx));
|
||||
let perm_rx_for_whatsapp = Arc::clone(&perm_rx);
|
||||
|
||||
// Capture project root, agents Arc, and reconciliation sender before ctx
|
||||
// is consumed by build_routes.
|
||||
let startup_root: Option<PathBuf> = app_state.project_root.lock().unwrap().clone();
|
||||
@@ -628,30 +626,17 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
template_name,
|
||||
))
|
||||
};
|
||||
let bot_name = cfg
|
||||
.display_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Assistant".to_string());
|
||||
let root = startup_root.clone().unwrap();
|
||||
let history = chat::transport::whatsapp::load_whatsapp_history(&root);
|
||||
Arc::new(chat::transport::whatsapp::WhatsAppWebhookContext {
|
||||
services: Arc::clone(&services),
|
||||
verify_token: cfg.whatsapp_verify_token.clone().unwrap_or_default(),
|
||||
provider,
|
||||
transport,
|
||||
project_root: root,
|
||||
agents: Arc::clone(&startup_agents),
|
||||
bot_name,
|
||||
bot_user_id: "whatsapp-bot".to_string(),
|
||||
ambient_rooms: Arc::new(std::sync::Mutex::new(std::collections::HashSet::new())),
|
||||
history: std::sync::Arc::new(tokio::sync::Mutex::new(history)),
|
||||
history_size: cfg.history_size,
|
||||
window_tracker: Arc::new(chat::transport::whatsapp::MessagingWindowTracker::new()),
|
||||
allowed_phones: cfg.whatsapp_allowed_phones.clone(),
|
||||
perm_rx: perm_rx_for_whatsapp,
|
||||
pending_perm_replies: Arc::new(tokio::sync::Mutex::new(
|
||||
std::collections::HashMap::new(),
|
||||
)),
|
||||
permission_timeout_secs: cfg.permission_timeout_secs,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -744,7 +729,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
// • Matrix: handled by spawn_bot() below; no action needed here.
|
||||
if let Some(ref ctx) = whatsapp_ctx {
|
||||
let transport = Arc::clone(&ctx.transport);
|
||||
let bot_name = ctx.bot_name.clone();
|
||||
let bot_name = ctx.services.bot_name.clone();
|
||||
let history: WhatsAppConversationHistory = Arc::clone(&ctx.history);
|
||||
tokio::spawn(async move {
|
||||
let senders: Vec<String> = history.lock().await.keys().cloned().collect();
|
||||
@@ -905,7 +890,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
// Spawn stage-transition notification listeners for WhatsApp and Slack.
|
||||
// These mirror the listener that the Matrix bot spawns internally.
|
||||
if let (Some(ctx), Some(root)) = (&whatsapp_ctx, &startup_root) {
|
||||
let ambient_rooms = Arc::clone(&ctx.ambient_rooms);
|
||||
let ambient_rooms = Arc::clone(&ctx.services.ambient_rooms);
|
||||
crate::service::notifications::spawn_notification_listener(
|
||||
Arc::clone(&ctx.transport),
|
||||
move || ambient_rooms.lock().unwrap().iter().cloned().collect(),
|
||||
@@ -991,12 +976,19 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
// WhatsApp: read the current set of ambient rooms and notify each sender.
|
||||
if let Some(ref ctx) = whatsapp_ctx_for_shutdown {
|
||||
let rooms: Vec<String> = ctx.ambient_rooms.lock().unwrap().iter().cloned().collect();
|
||||
let rooms: Vec<String> = ctx
|
||||
.services
|
||||
.ambient_rooms
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
if !rooms.is_empty() {
|
||||
let wa_notifier = BotShutdownNotifier::new(
|
||||
Arc::clone(&ctx.transport) as Arc<dyn crate::chat::ChatTransport>,
|
||||
rooms,
|
||||
ctx.bot_name.clone(),
|
||||
ctx.services.bot_name.clone(),
|
||||
);
|
||||
wa_notifier.notify(ShutdownReason::Manual).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user