[][src]Struct telegram_bot_async::Api

pub struct Api<C: Connector> { /* fields omitted */ }

Main type for sending requests to the Telegram bot API.

Methods

impl<C: Connector> Api<C>[src]

pub fn new_default(token: String) -> Result<DefaultApi, Error>[src]

Start construction of the Api instance.

Examples

Using default connector.

use telegram_bot_fork::DefaultApi;

let api = DefaultApi::new_default(telegram_token.to_string()).unwrap();

pub fn with_connector(token: String, connector: C) -> Api<C>[src]

Creates new API using custom connector.

use telegram_bot_fork::{connector::hyper, Api};

let api = Api::with_connector(telegram_token.to_string(), hyper::default_connector().unwrap());

pub fn set_url<T: AsRef<str>>(&mut self, url: T) -> &mut Self[src]

Sets base telegram API server URL.

pub fn into_stream(self) -> UpdatesStream<C>[src]

Create a stream which produces updates from the Telegram server.

Examples


#[for_await]
for update in stream.updates() {
    println!("{:?}", update);
}
Ok(())

pub async fn send_timeout<'_, Req: Request>(
    &'_ self,
    request: Req,
    duration: Duration
) -> Result<<Req::Response as ResponseType>::Type, Error>
[src]

Send a request to the Telegram server and wait for a response, timing out after duration. Future will resolve to None if timeout fired.

Examples

use std::time::Duration;

let resp = api.send_timeout(GetMe, Duration::from_secs(5)).await?;
Ok(())

pub async fn send<'_, Req: Request>(
    &'_ self,
    request: Req
) -> Result<<Req::Response as ResponseType>::Type, Error>
[src]

Send a request to the Telegram server and wait for a response.

Examples

let resp = api.send(GetMe).await?;
Ok(())

Trait Implementations

impl<C: Clone + Connector> Clone for Api<C>[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for Api<C> where
    C: RefUnwindSafe

impl<C> Send for Api<C>

impl<C> Sync for Api<C>

impl<C> Unpin for Api<C> where
    C: Unpin

impl<C> UnwindSafe for Api<C> where
    C: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.