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).
Auto Trait Implementations§
impl Freeze for TelegramBot
impl RefUnwindSafe for TelegramBot
impl Send for TelegramBot
impl Sync for TelegramBot
impl Unpin for TelegramBot
impl UnsafeUnpin for TelegramBot
impl UnwindSafe for TelegramBot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.