pub struct Client { /* private fields */ }
Expand description
A client for interacting with the Telegram Bot API.
Implementations§
source§impl Client
impl Client
sourcepub fn new<T>(token: T) -> Result<Client, ClientError>
pub fn new<T>(token: T) -> Result<Client, ClientError>
Creates a new Telegram Bot API client with the provided bot token.
§Arguments
token
- A token associated with your bot.
sourcepub fn with_http_client<T>(http_client: Client, token: T) -> Client
pub fn with_http_client<T>(http_client: Client, token: T) -> Client
Creates a new Telegram Bot API client with a custom HTTP client and bot token.
§Arguments
client
- An HTTP client.token
- A token associated with your bot.
sourcepub async fn download_file<P>(
&self,
file_path: P
) -> Result<impl Stream<Item = Result<Bytes, Error>>, DownloadFileError>
pub async fn download_file<P>( &self, file_path: P ) -> Result<impl Stream<Item = Result<Bytes, Error>>, DownloadFileError>
Downloads a file.
Use crate::types::GetFile
method to get a value for the file_path
argument.
§Arguments
file_path
- The path to the file to be downloaded.
§Example
use tgbot::api::Client;
use futures_util::stream::StreamExt;
let api = Client::new("token").unwrap();
let mut stream = api.download_file("path").await.unwrap();
while let Some(chunk) = stream.next().await {
let chunk = chunk.unwrap();
// write chunk to something...
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
Mutably borrows from an owned value. Read more
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>
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 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>
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