Skip to main content

HttpTelegramBot

Struct HttpTelegramBot 

Source
pub struct HttpTelegramBot { /* private fields */ }
Expand description

TelegramBot over the Telegram Bot API: POST {base}/bot{token}/{method} with a JSON body, through the runtime’s HttpClient port.

No Debug derive: the token is a struct field, and a derived Debug would print it wherever a log line met the adapter. The hand-written one prints a placeholder instead.

Implementations§

Source§

impl HttpTelegramBot

Source

pub fn new( http: Arc<dyn HttpClient>, clock: Arc<dyn Clock>, bot_token: impl Into<String>, ) -> Self

A bot pointed at Telegram under bot_token.

Source

pub fn with_base(self, base_url: impl Into<String>) -> Self

Overrides the root every request is posted to — a fake in tests — instead of https://api.telegram.org.

Source

pub fn with_limits(self, limits: RateLimits) -> Self

Replaces the rate budgets with limits, discarding the tokens the old budgets had accrued and any 429 deadlines. Chain after new.

Source

pub async fn set_webhook( &self, url: &str, secret_token: &str, allowed_updates: &[&str], ) -> Result<(), TelegramError>

Registers url as the bot’s webhook with secret_token in webhook::SECRET_HEADER and the named update types delivered. An empty url deletes the webhook.

Counted against the global budget only: there is no chat to scope a per-chat bucket to, and a 429 here has nothing to remember one for.

§Errors

TelegramError::Invalid for a url that is neither https nor a localhost http (the one exception Telegram allows), a secret outside Telegram’s alphabet, or a bot token that is not shaped like one; otherwise the same mapping as TelegramBot::send_message.

Trait Implementations§

Source§

impl Debug for HttpTelegramBot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The bot token is a struct field, so it is written as a placeholder: a log line that meets the adapter must never carry it.

Source§

impl TelegramBot for HttpTelegramBot

Source§

fn send_message<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 OutgoingMessage, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, TelegramError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends a text message, with any buttons, and reports where it landed. Read more
Source§

fn edit_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, chat_id: i64, message_id: i64, text: &'life1 str, buttons: &'life2 [Vec<InlineButton>], ) -> Pin<Box<dyn Future<Output = Result<(), TelegramError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Edits a message this bot previously sent, replacing the text and the inline keyboard (an empty buttons removes the keyboard). Read more
Source§

fn delete_message<'life0, 'async_trait>( &'life0 self, chat_id: i64, message_id: i64, ) -> Pin<Box<dyn Future<Output = Result<(), TelegramError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Deletes a message this bot previously sent. Read more
Source§

fn answer_callback<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, callback_query_id: &'life1 str, text: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<(), TelegramError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Acknowledges a callback query, optionally showing text as a toast to the user who pressed the button. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more