storkit: merge 396_story_whatsapp_bot_startup_announcement_after_restart
This commit is contained in:
@@ -379,6 +379,43 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
let whatsapp_ctx_for_shutdown: Option<Arc<chat::transport::whatsapp::WhatsAppWebhookContext>> =
|
||||
whatsapp_ctx.clone();
|
||||
|
||||
// ── Startup announcements (WhatsApp & Slack) ──────────────────────────
|
||||
//
|
||||
// Send "{bot_name} is online." to all known contacts so users know the bot
|
||||
// is ready. This mirrors the Matrix bot's startup announcement and fires
|
||||
// on every fresh process start — including after a rebuild/re-exec.
|
||||
//
|
||||
// • WhatsApp: send to all phone numbers present in persisted history.
|
||||
// • Slack: send to all configured channel IDs (channel_ids from bot.toml).
|
||||
// • 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 history = Arc::clone(&ctx.history);
|
||||
tokio::spawn(async move {
|
||||
let senders: Vec<String> = history.lock().await.keys().cloned().collect();
|
||||
if senders.is_empty() {
|
||||
return;
|
||||
}
|
||||
let notifier =
|
||||
crate::rebuild::BotShutdownNotifier::new(transport, senders, bot_name);
|
||||
notifier.notify_startup().await;
|
||||
});
|
||||
}
|
||||
if let Some(ref ctx) = slack_ctx {
|
||||
let transport = Arc::clone(&ctx.transport) as Arc<dyn crate::chat::ChatTransport>;
|
||||
let bot_name = ctx.bot_name.clone();
|
||||
let channels: Vec<String> = ctx.channel_ids.iter().cloned().collect();
|
||||
tokio::spawn(async move {
|
||||
if channels.is_empty() {
|
||||
return;
|
||||
}
|
||||
let notifier =
|
||||
crate::rebuild::BotShutdownNotifier::new(transport, channels, bot_name);
|
||||
notifier.notify_startup().await;
|
||||
});
|
||||
}
|
||||
|
||||
// Watch channel: signals the Matrix bot task to send a shutdown announcement.
|
||||
// `None` initial value means "server is running".
|
||||
let (matrix_shutdown_tx, matrix_shutdown_rx) =
|
||||
|
||||
Reference in New Issue
Block a user