Skip to main content

telegram_tool/
lib.rs

1//! Shared Telegram integration for tools and inbound message adapters.
2//!
3//! A single TelegramGateway owns update polling. Replies to interactive tool
4//! questions are routed by Telegram message ID; all other messages are
5//! broadcast to inbound adapters.
6
7mod client;
8mod tool;
9
10use std::{path::PathBuf, sync::Arc};
11
12use agent_config::ConfigError;
13use agent_runtime::ToolRegistry;
14
15pub use client::{IncomingMessage, TelegramError, TelegramGateway};
16
17/// Register Telegram tools. The gateway is shared with the server's inbound
18/// message handler; when absent, tool calls fail with a configuration error.
19pub fn register_tools(
20    registry: &mut ToolRegistry,
21    gateway: Option<Arc<TelegramGateway>>,
22) -> Result<(), ConfigError> {
23    let data_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data");
24
25    registry.register_from_file(
26        data_dir.join("tg_notify_user.toml"),
27        tool::TgNotifyUser::new(gateway.clone()),
28    )?;
29    registry.register_from_file(
30        data_dir.join("tg_ask_user.toml"),
31        tool::TgAskUser::new(gateway),
32    )?;
33
34    Ok(())
35}