pub struct ClientConfig {
pub token: String,
pub api_base_url: String,
pub timeout: Duration,
pub max_retries: u8,
}Expand description
Configuration for BotClient.
Use the builder methods to customise behaviour, then pass the config to
BotClient::new.
§Example
use std::time::Duration;
let config = ClientConfig::new("123456:ABC...")?
.api_base_url("http://localhost:8081") // local Bot API server
.timeout(Duration::from_secs(60))
.max_retries(5);Fields§
§token: StringBot token used to authenticate with the Telegram API.
api_base_url: StringBase URL of the Bot API server (default: https://api.telegram.org).
timeout: DurationPer-request HTTP timeout.
max_retries: u8Maximum number of automatic retries on flood control responses.
Applies to JSON requests only — see ClientConfig::max_retries.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new(token: impl Into<String>) -> Result<Self>
pub fn new(token: impl Into<String>) -> Result<Self>
Creates a new ClientConfig with the given bot token and default settings.
Sourcepub fn api_base_url(self, url: impl Into<String>) -> Self
pub fn api_base_url(self, url: impl Into<String>) -> Self
Sets a custom base URL for API requests, e.g. for a local Bot API server.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets a custom timeout for API requests (default 30 seconds).
Sourcepub fn max_retries(self, n: u8) -> Self
pub fn max_retries(self, n: u8) -> Self
Sets the maximum number of retries on HTTP 429 (flood control) errors (default 3).
§Uploads are not retried
This budget governs requests sent as JSON, which is every call that does
not upload file bytes — including media sent by file_id or URL. A
byte upload is never retried, whatever this is set to: the multipart
form is consumed when the request is sent and cannot be rebuilt for a
second attempt.
So max_retries(5) means five attempts for
send_message, and one for a
send_photo carrying
InputFile::Bytes. A bot that
uploads under load should expect Error::RateLimit
on the first flood-control response and back off itself, using
Error::retry_after.
Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more