feat(gateway): full Telegram+Discord integration with agent loop
Complete multi-platform gateway wiring: config: - [platform.telegram] section with bot_token - [platform.discord] section with bot_token + guild_id - Threaded through GyandootConfig → AgentConfig via typed structs gateway: - GatewayRunner::new(platforms) takes Vec<Box<dyn Platform>> - start() spawns all platform pollers, merges receivers - serve(agent) runs full message loop: receive → access control → typing indicator → session_turn() → platform.send() - Ctrl+C graceful shutdown via tokio::select! cmd_serve now: 1. Loads config, creates agent 2. Builds Telegram + Discord adapters from config 3. Starts gateway pollers 4. Enters serve loop until Ctrl+C
This commit is contained in:
54
src/main.rs
54
src/main.rs
@@ -364,19 +364,53 @@ fn load_and_convert_config(path: &std::path::Path) -> Result<gyandoot_core::conf
|
||||
}
|
||||
|
||||
/// Start the gateway server for multi-platform sessions
|
||||
async fn cmd_serve(profile_name: &str, host: &str, port: u16) -> anyhow::Result<()> {
|
||||
tracing::info!(
|
||||
"Starting gateway server (profile={}, bind={}:{})",
|
||||
profile_name, host, port
|
||||
);
|
||||
async fn cmd_serve(profile_name: &str, _host: &str, _port: u16) -> anyhow::Result<()> {
|
||||
tracing::info!("Starting gateway server (profile={})", profile_name);
|
||||
|
||||
let gateway = gyandoot_gateway::GatewayRunner::new();
|
||||
let config = load_agent_config();
|
||||
let agent = gyandoot_agent::agent_loop::AgentLoop::new(config.clone());
|
||||
|
||||
// Build platform adapters from config
|
||||
let mut platforms: Vec<Box<dyn gyandoot_platform::Platform>> = Vec::new();
|
||||
|
||||
// Telegram
|
||||
if let Some(tg) = &config.platform.telegram {
|
||||
if !tg.bot_token.is_empty() {
|
||||
platforms.push(Box::new(
|
||||
gyandoot_platform::telegram::TelegramPlatform::new(&tg.bot_token),
|
||||
));
|
||||
tracing::info!("Telegram platform added");
|
||||
}
|
||||
}
|
||||
|
||||
// Discord
|
||||
if let Some(dc) = &config.platform.discord {
|
||||
if !dc.bot_token.is_empty() {
|
||||
platforms.push(Box::new(
|
||||
gyandoot_platform::discord::DiscordPlatform::new(&dc.bot_token, dc.guild_id),
|
||||
));
|
||||
tracing::info!("Discord platform added");
|
||||
}
|
||||
}
|
||||
|
||||
// Gateway
|
||||
let mut gateway = gyandoot_gateway::GatewayRunner::new(platforms);
|
||||
gateway.start().await?;
|
||||
tracing::info!("Gateway running on {}:{} — press Ctrl+C to stop", host, port);
|
||||
tracing::info!("Gateway started — listening on platforms");
|
||||
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
tracing::info!("Shutting down gateway...");
|
||||
gateway.stop();
|
||||
}
|
||||
result = gateway.serve(&agent) => {
|
||||
match result {
|
||||
Ok(()) => tracing::info!("Gateway serve completed"),
|
||||
Err(e) => tracing::error!("Gateway serve error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep running until signal
|
||||
tokio::signal::ctrl_c().await?;
|
||||
gateway.stop().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user