Future proof multipart requests

This commit is contained in:
Waffle 2021-02-16 16:55:27 +03:00
parent 557002b43a
commit 8abf3863e5
85 changed files with 146 additions and 97 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `MultipartPayload` for future proofing ([#49][pr49])
- Support for `rustls` ([#24][pr24])
- `#[must_use]` attr to payloads implemented by macro ([#22][pr22])
- forward-to-deref `Requester` impls ([#39][pr39])
@ -52,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[pr35]: https://github.com/teloxide/teloxide-core/pull/35
[pr39]: https://github.com/teloxide/teloxide-core/pull/39
[pr46]: https://github.com/teloxide/teloxide-core/pull/46
[pr49]: https://github.com/teloxide/teloxide-core/pull/49
### Changed

View file

@ -9,7 +9,7 @@ use serde::{de::DeserializeOwned, Serialize};
use crate::{
bot::api_url::ApiUrl,
net,
requests::{Payload, ResponseResult},
requests::{MultipartPayload, Payload, ResponseResult},
serde_multipart,
};
@ -222,7 +222,7 @@ impl Bot {
payload: &P,
) -> impl Future<Output = ResponseResult<P::Output>>
where
P: Payload + Serialize,
P: MultipartPayload + Serialize,
P::Output: DeserializeOwned,
{
let client = self.client.clone();

View file

@ -133,11 +133,14 @@ macro_rules! calculated_doc {
);
}
/// Declare payload type, implement `Payload` trait amd ::new method for it,
/// Declare payload type, implement `Payload` trait and ::new method for it,
/// declare setters trait and implement it for all type which have payload.
#[macro_use]
macro_rules! impl_payload {
(
$(
@[$multipart_attr:ident]
)?
$(
#[ $($method_meta:tt)* ]
)*
@ -241,6 +244,8 @@ macro_rules! impl_payload {
}
impl<P> $Setters for P where P: crate::requests::HasPayload<Payload = $Method> {}
impl_payload! { @[$($multipart_attr)?] $Method req { $($($fields),*)? } opt { $($($opt_fields),*)? } }
};
(@setter_opt $Method:ident $field:ident : $FTy:ty [into]) => {
calculated_doc! {
@ -380,6 +385,11 @@ macro_rules! impl_payload {
(@convert_map ($e:expr)) => {
$e
};
(@[multipart] $Method:ident req { $($reqf:ident),* } opt { $($optf:ident),*} ) => {
impl crate::requests::MultipartPayload for $Method {}
impl crate::requests::multipart_payload::sealed::Sealed for $Method {}
};
(@[] $($ignored:tt)*) => {}
}
#[macro_use]

View file

@ -59,9 +59,10 @@ where
tokio::time::sleep(DELAY_ON_SERVER_ERROR).await;
}
serde_json::from_str::<TelegramResponse<T>>(
&response.text().await.map_err(RequestError::NetworkError)?,
)
serde_json::from_str::<TelegramResponse<T>>(dbg!(&response
.text()
.await
.map_err(RequestError::NetworkError)?))
.map_err(RequestError::InvalidJson)?
.into()
}

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{InputSticker, MaskPosition, True};
impl_payload! {
@[multipart]
/// Use this method to add a new sticker to a set created by the bot. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns _True_ on success.
#[derive(Debug, PartialEq, Clone, Serialize)]
pub AddStickerToSet (AddStickerToSetSetters) => True {

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{InputSticker, MaskPosition, True};
impl_payload! {
@[multipart]
/// Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields _png\_sticker_ or _tgs\_sticker_. Returns _True_ on success.
#[derive(Debug, PartialEq, Clone, Serialize)]
pub CreateNewStickerSet (CreateNewStickerSetSetters) => True {

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent [`Message`] is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
///
/// [`Message`]: crate::types::Message

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent [`Message`] is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
///
/// For sending voice messages, use the [`SendVoice`] method instead.

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send general files. On success, the sent [`Message`] is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
///
/// [`Message`]: crate::types::Message

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send photos. On success, the sent [`Message`] is returned.
///
/// [`Message`]: crate::types::Message

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send static .WEBP or [animated] .TGS stickers. On success, the sent Message is returned.
///
/// [animated]: https://telegram.org/blog/animated-stickers

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as [`Document`]). On success, the sent [`Message`] is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
///
/// [`Document`]: crate::types::Document

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ReplyMarkup};
impl_payload! {
@[multipart]
/// As of [v.4.0], Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent [`Message`] is returned.
///
/// [v.4.0]: https://core.telegram.org/bots/api#document

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
impl_payload! {
@[multipart]
/// Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as [`Audio`] or [`Document`]). On success, the sent [`Message`] is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
///
/// [`Document`]: crate::types::Document

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{ChatId, InputFile};
impl_payload! {
@[multipart]
/// Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
pub SetChatPhoto (SetChatPhotoSetters) => String {

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{InputFile, True};
impl_payload! {
@[multipart]
/// Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns _True_ on success.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
pub SetStickerSetThumb (SetStickerSetThumbSetters) => True {

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{AllowedUpdate, InputFile, True};
impl_payload! {
@[multipart]
/// Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized [`Update`]. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
///
/// If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. `https://www.example.com/<token>`. Since nobody else knows your bot's token, you can be pretty sure it's us.

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;

View file

@ -1,4 +1,4 @@
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (be02d84).
// This file is auto generated by `cg` <https://github.com/teloxide/cg> (8ee7ef2).
// **DO NOT EDIT THIS FILE**,
// edit `cg` instead.
use serde::Serialize;
@ -6,6 +6,7 @@ use serde::Serialize;
use crate::types::{File, InputFile};
impl_payload! {
@[multipart]
/// Use this method to upload a .PNG file with a sticker for later use in _createNewStickerSet_ and _addStickerToSet_ methods (can be used multiple times). Returns the uploaded File on success.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
pub UploadStickerFile (UploadStickerFileSetters) => File {

View file

@ -1,8 +1,9 @@
//! Telegram API requests.
pub use self::{
has_payload::HasPayload, json::JsonRequest, multipart::MultipartRequest, payload::Payload,
request::Request, requester::Requester, requester_ext::RequesterExt,
has_payload::HasPayload, json::JsonRequest, multipart::MultipartRequest,
multipart_payload::MultipartPayload, payload::Payload, request::Request, requester::Requester,
requester_ext::RequesterExt,
};
/// A type that is returned after making a request to Telegram.
@ -14,6 +15,7 @@ pub type Output<T> = <<T as HasPayload>::Payload as Payload>::Output;
mod has_payload;
mod json;
mod multipart;
pub(crate) mod multipart_payload;
mod payload;
mod request;
mod requester;

View file

@ -2,7 +2,7 @@ use serde::{de::DeserializeOwned, Serialize};
use crate::{
bot::Bot,
requests::{HasPayload, Payload, Request, ResponseResult},
requests::{HasPayload, MultipartPayload, Payload, Request, ResponseResult},
RequestError,
};
@ -33,7 +33,7 @@ where
// (though critically, currently we have no
// non-'static payloads)
P: 'static,
P: Payload + Serialize,
P: Payload + MultipartPayload + Serialize,
P::Output: DeserializeOwned,
{
type Err = RequestError;
@ -67,7 +67,7 @@ where
impl<P> core::ops::Deref for MultipartRequest<P>
where
P: 'static,
P: Payload + Serialize,
P: Payload + MultipartPayload,
P::Output: DeserializeOwned,
{
type Target = P;
@ -80,7 +80,7 @@ where
impl<P> core::ops::DerefMut for MultipartRequest<P>
where
P: 'static,
P: Payload + Serialize,
P: Payload + MultipartPayload,
P::Output: DeserializeOwned,
{
fn deref_mut(&mut self) -> &mut Self::Target {
@ -95,7 +95,7 @@ req_future! {
pub Send<U> (inner0) -> ResponseResult<U::Output>
where
U: 'static,
U: Payload + Serialize,
U: Payload + MultipartPayload + Serialize,
U::Output: DeserializeOwned,
}
@ -106,6 +106,6 @@ req_future! {
pub SendRef<U> (inner1) -> ResponseResult<U::Output>
where
U: 'static,
U: Payload + Serialize,
U: Payload + MultipartPayload + Serialize,
U::Output: DeserializeOwned,
}

View file

@ -0,0 +1,19 @@
use crate::{payloads, requests::Payload};
/// This is a future proof trait. It is `sealed` and can change at any time.
pub trait MultipartPayload: Payload + sealed::Sealed {}
// HACK(waffle): Sealed trait allows us to change `MultipartPayload` without
// breaking changes & refactor multipart requests later.
pub(crate) mod sealed {
pub trait Sealed {}
}
impl sealed::Sealed for payloads::SendMediaGroup {}
impl MultipartPayload for payloads::SendMediaGroup {}
impl sealed::Sealed for payloads::EditMessageMedia {}
impl MultipartPayload for payloads::EditMessageMedia {}
impl sealed::Sealed for payloads::EditMessageMediaInline {}
impl MultipartPayload for payloads::EditMessageMediaInline {}

View file

@ -410,9 +410,9 @@ impl InputMediaDocument {
}
}
impl InputMedia {
pub fn media(&self) -> &InputFile {
match self {
impl From<InputMedia> for InputFile {
fn from(media: InputMedia) -> InputFile {
match media {
InputMedia::Photo(InputMediaPhoto { media, .. })
| InputMedia::Document(InputMediaDocument { media, .. })
| InputMedia::Audio(InputMediaAudio { media, .. })
@ -422,9 +422,10 @@ impl InputMedia {
}
}
impl From<InputMedia> for InputFile {
fn from(media: InputMedia) -> InputFile {
match media {
impl InputMedia {
#[allow(dead_code)]
pub(crate) fn media(&self) -> &InputFile {
match self {
InputMedia::Photo(InputMediaPhoto { media, .. })
| InputMedia::Document(InputMediaDocument { media, .. })
| InputMedia::Audio(InputMediaAudio { media, .. })