Struct telegram_bot_ars::Api
source · pub struct Api(_);
Expand description
Main type for sending requests to the Telegram bot API.
Implementations§
source§impl Api
impl Api
sourcepub fn new<T: AsRef<str>>(token: T) -> Self
pub fn new<T: AsRef<str>>(token: T) -> Self
Create a new Api
instance.
Example
Using default connector.
use telegram_bot_ars::Api;
let api = Api::new(telegram_token);
sourcepub fn with_connector<T: AsRef<str>>(
token: T,
connector: Box<dyn Connector>
) -> Self
pub fn with_connector<T: AsRef<str>>(
token: T,
connector: Box<dyn Connector>
) -> Self
Create a new Api
instance wtih custom connector.
sourcepub fn stream(&self) -> UpdatesStream
pub fn stream(&self) -> UpdatesStream
Create a stream which produces updates from the Telegram server.
Examples
use futures::StreamExt;
let mut stream = api.stream();
let update = stream.next().await;
println!("{:?}", update);
sourcepub fn spawn<Req: Request>(&self, request: Req)
pub fn spawn<Req: Request>(&self, request: Req)
Send a request to the Telegram server and do not wait for a response.
Examples
let chat = ChatId::new(61031);
api.spawn(chat.text("Message"));
sourcepub fn send_timeout<Req: Request>(
&self,
request: Req,
duration: Duration
) -> impl Future<Output = Result<Option<<Req::Response as ResponseType>::Type>, Error>> + Send
pub fn send_timeout<Req: Request>(
&self,
request: Req,
duration: Duration
) -> impl Future<Output = Result<Option<<Req::Response as ResponseType>::Type>, Error>> + Send
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
let result = api.send_timeout(GetMe, Duration::from_secs(2)).await;
println!("{:?}", result);