pub struct Api(/* private fields */);
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);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Api
impl !RefUnwindSafe for Api
impl Send for Api
impl Sync for Api
impl Unpin for Api
impl !UnwindSafe for Api
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