pub struct TelegramBot { /* private fields */ }Expand description
Blocking Telegram Bot API client.
Implementations§
Source§impl TelegramBot
impl TelegramBot
Sourcepub fn new(bot_token: String, allowed_user_ids: Vec<i64>) -> Self
pub fn new(bot_token: String, allowed_user_ids: Vec<i64>) -> Self
Create a new TelegramBot with the given token and allowed user IDs.
Sourcepub fn from_config(config: &ChannelConfig) -> Option<Self>
pub fn from_config(config: &ChannelConfig) -> Option<Self>
Build a TelegramBot from a ChannelConfig.
Returns None if no bot token is available — checks the config’s
bot_token field first, then falls back to the BATTY_TELEGRAM_BOT_TOKEN
environment variable.
Check whether a Telegram user ID is in the allowed list.
An empty allowed_user_ids list denies everyone.
Sourcepub fn send_message(&self, chat_id: &str, text: &str) -> Result<()>
pub fn send_message(&self, chat_id: &str, text: &str) -> Result<()>
Send a text message to a Telegram chat.
Messages longer than 4096 characters are split into multiple messages.
POST https://api.telegram.org/bot{token}/sendMessage
Sourcepub fn poll_updates(&mut self) -> Result<Vec<InboundMessage>>
pub fn poll_updates(&mut self) -> Result<Vec<InboundMessage>>
Poll the Telegram Bot API for new updates and return authorized inbound messages.
GET https://api.telegram.org/bot{token}/getUpdates?offset={}&timeout=0
Unauthorized messages are silently dropped (logged at debug level).