pub struct TelegramApiClient { /* private fields */ }Expand description
Raw HTTP client for Telegram Bot API 10.0 methods not covered by teloxide.
The bot token is embedded in the base URL and is never written to logs — the
Debug implementation redacts it.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("123456:ABC-DEF…");
let result = client.answer_guest_query("query_id", "Hello!", None).await?;
println!("sent message_id={}", result.message_id);Implementations§
Source§impl TelegramApiClient
impl TelegramApiClient
Sourcepub fn new(token: impl Into<String>) -> Self
pub fn new(token: impl Into<String>) -> Self
Create a new client for the given bot token.
The base URL is set to https://api.telegram.org/bot<TOKEN> so that each
post() call appends only the method name (e.g., /answerGuestQuery).
Creates an independent reqwest::Client with its own connection pool and
a [REQUEST_TIMEOUT] per-request timeout. To share a connection pool with
an existing client, use TelegramApiClient::with_client.
§Panics
Panics if the TLS backend cannot be initialised (i.e. reqwest::ClientBuilder::build
returns an error). This does not occur in practice when the crate is compiled with a
supported TLS backend.
Sourcepub fn with_client(client: Client, token: &str) -> Self
pub fn with_client(client: Client, token: &str) -> Self
Create a client that reuses an existing reqwest::Client.
This allows sharing a connection pool with another HTTP client — for
example, the reqwest::Client backing teloxide’s Bot — to avoid
opening duplicate TCP connections to api.telegram.org.
The base URL is set to https://api.telegram.org/bot<token> using the
supplied token.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let shared = reqwest::Client::new();
let client = TelegramApiClient::with_client(shared, "123456:ABC-DEF…");Sourcepub async fn get_me(&self) -> Result<GuestUser, TelegramApiError>
pub async fn get_me(&self) -> Result<GuestUser, TelegramApiError>
Fetch the bot’s own user information via getMe.
Returns the bot’s Telegram user ID. This is the value to pass as
bot_user_id when constructing a TelegramModerationBackend for
pre-flight admin checks.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let me = client.get_me().await?;
println!("bot user id: {}", me.id);Sourcepub fn with_base_url(base_url: impl Into<String>) -> Self
pub fn with_base_url(base_url: impl Into<String>) -> Self
Create a client with a fully-qualified custom base URL.
The base_url is stored as-is and each method name is appended with /.
The bot token is not automatically embedded — the caller is responsible
for including the full path prefix required by the target server.
For the official Telegram Bot API protocol the expected format is:
https://api.telegram.org/bot<TOKEN> (same as what new builds).
For a local Telegram Bot API server
the format is typically http://localhost:8081/bot<TOKEN>.
This method is primarily intended for testing (point at a wiremock server) or for deployments that proxy through a local Bot API server.
§Panics
Panics if the TLS backend cannot be initialised. This does not occur in practice when the crate is compiled with a supported TLS backend.
Sourcepub async fn answer_guest_query(
&self,
query_id: &str,
text: &str,
parse_mode: Option<&str>,
) -> Result<SentGuestMessage, TelegramApiError>
pub async fn answer_guest_query( &self, query_id: &str, text: &str, parse_mode: Option<&str>, ) -> Result<SentGuestMessage, TelegramApiError>
Answer a Guest Mode query on behalf of a managed bot.
§Arguments
query_id— identifier of the guest query to answer.text— reply text.parse_mode— optional parse mode ("HTML","MarkdownV2", etc.).
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let sent = client.answer_guest_query("qid_123", "Hello!", Some("HTML")).await?;
println!("message_id={}", sent.message_id);Sourcepub async fn get_managed_bot_access_settings(
&self,
) -> Result<BotAccessSettings, TelegramApiError>
pub async fn get_managed_bot_access_settings( &self, ) -> Result<BotAccessSettings, TelegramApiError>
Retrieve access settings for a managed bot.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let settings = client.get_managed_bot_access_settings().await?;
println!("bot_messages={}", settings.allow_bot_messages);Sourcepub async fn set_managed_bot_access_settings(
&self,
settings: &BotAccessSettings,
) -> Result<bool, TelegramApiError>
pub async fn set_managed_bot_access_settings( &self, settings: &BotAccessSettings, ) -> Result<bool, TelegramApiError>
Update access settings for a managed bot.
Returns true when the settings were applied successfully.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::{BotAccessSettings, TelegramApiClient};
let client = TelegramApiClient::new("TOKEN");
let ok = client.set_managed_bot_access_settings(&BotAccessSettings {
allow_user_messages: true,
allow_bot_messages: true,
}).await?;
assert!(ok);Sourcepub async fn delete_message_reaction(
&self,
chat_id: i64,
message_id: i64,
user_id: i64,
reaction: &str,
) -> Result<bool, TelegramApiError>
pub async fn delete_message_reaction( &self, chat_id: i64, message_id: i64, user_id: i64, reaction: &str, ) -> Result<bool, TelegramApiError>
Delete a specific reaction left by user_id on a message.
Returns true on success.
§Arguments
chat_id— identifier of the chat containing the message.message_id— identifier of the message.user_id— identifier of the user whose reaction to remove.reaction— emoji or custom reaction string to remove.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let ok = client.delete_message_reaction(123, 456, 789, "👍").await?;
assert!(ok);Sourcepub async fn get_chat_member(
&self,
chat_id: i64,
user_id: i64,
) -> Result<ChatMember, TelegramApiError>
pub async fn get_chat_member( &self, chat_id: i64, user_id: i64, ) -> Result<ChatMember, TelegramApiError>
Retrieve the membership status of user_id in chat_id.
Used for a pre-flight admin check before executing moderation actions. The result is not cached — each call makes a live API request.
§Arguments
chat_id— identifier of the chat to query.user_id— identifier of the user whose membership to retrieve.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let member = client.get_chat_member(123, 456).await?;
println!("is admin: {}", member.is_admin());Sourcepub async fn delete_all_message_reactions(
&self,
chat_id: i64,
message_id: i64,
user_id: i64,
) -> Result<bool, TelegramApiError>
pub async fn delete_all_message_reactions( &self, chat_id: i64, message_id: i64, user_id: i64, ) -> Result<bool, TelegramApiError>
Delete all reactions left by user_id on a message.
Returns true on success.
§Arguments
chat_id— identifier of the chat containing the message.message_id— identifier of the message.user_id— identifier of the user whose reactions to remove.
§Errors
Returns TelegramApiError on HTTP failure or when ok: false.
§Examples
use zeph_channels::telegram_api_ext::TelegramApiClient;
let client = TelegramApiClient::new("TOKEN");
let ok = client.delete_all_message_reactions(123, 456, 789).await?;
assert!(ok);Trait Implementations§
Source§impl Clone for TelegramApiClient
impl Clone for TelegramApiClient
Source§fn clone(&self) -> TelegramApiClient
fn clone(&self) -> TelegramApiClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TelegramApiClient
impl !UnwindSafe for TelegramApiClient
impl Freeze for TelegramApiClient
impl Send for TelegramApiClient
impl Sync for TelegramApiClient
impl Unpin for TelegramApiClient
impl UnsafeUnpin for TelegramApiClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request