mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Merge pull request #25 from async-telegram-bot/feature/GetFile
add getFile implementation
This commit is contained in:
commit
2b49b22b42
1 changed files with 40 additions and 2 deletions
|
@ -1,8 +1,46 @@
|
|||
use crate::core::requests::RequestContext;
|
||||
//TODO:: need implementation
|
||||
use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request};
|
||||
use crate::core::types::File;
|
||||
use crate::core::network;
|
||||
|
||||
/// Use this method to get basic info about a file and prepare it for downloading.
|
||||
/// For the moment, bots can download files of up to 20MB in size.
|
||||
/// On success, a File object is returned.
|
||||
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
|
||||
/// where <file_path> is taken from the response.
|
||||
/// It is guaranteed that the link will be valid for at least 1 hour.
|
||||
/// When the link expires, a new one can be requested by calling getFile again.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct GetFile<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
ctx: RequestContext<'a>,
|
||||
/// File identifier to get info about
|
||||
file_id: String
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Request<'a> for GetFile<'a> {
|
||||
type ReturnValue = File;
|
||||
|
||||
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||
Box::pin(async move {
|
||||
network::request_json(
|
||||
&self.ctx.client,
|
||||
&self.ctx.token,
|
||||
"getFile",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> GetFile<'a>{
|
||||
pub fn file_id<T>(mut self, file_id: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.file_id = message_id.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue