Skip to main content

TelegramApiClient

Struct TelegramApiClient 

Source
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

Source

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.

Source

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…");
Source

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);
Source

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.

Source

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);
Source

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);
Source

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);
Source

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);
Source

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());
Source

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

Source§

fn clone(&self) -> TelegramApiClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TelegramApiClient

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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