Add td_api::inputMessagePaidMedia and support sending single paid media.

This commit is contained in:
levlam 2024-06-24 21:36:14 +03:00
parent 9c85fdf990
commit f23e47b3e4
6 changed files with 97 additions and 17 deletions

View File

@ -3112,7 +3112,7 @@ messageText text:formattedText web_page:webPage link_preview_options:linkPreview
//@description An animation message (GIF-style).
//@animation The animation description
//@caption Animation caption
//@show_caption_above_media True, if caption must be shown above the animation; otherwise, caption must be shown below the animation
//@show_caption_above_media True, if the caption must be shown above the animation; otherwise, the caption must be shown below the animation
//@has_spoiler True, if the animation preview must be covered by a spoiler animation
//@is_secret True, if the animation thumbnail must be blurred and the animation must be shown only while tapped
messageAnimation animation:animation caption:formattedText show_caption_above_media:Bool has_spoiler:Bool is_secret:Bool = MessageContent;
@ -3132,7 +3132,7 @@ messagePaidMedia star_count:int53 media:vector<MessageExtendedMedia> caption:for
//@description A photo message
//@photo The photo
//@caption Photo caption
//@show_caption_above_media True, if caption must be shown above the photo; otherwise, caption must be shown below the photo
//@show_caption_above_media True, if the caption must be shown above the photo; otherwise, the caption must be shown below the photo
//@has_spoiler True, if the photo preview must be covered by a spoiler animation
//@is_secret True, if the photo must be blurred and must be shown only while tapped
messagePhoto photo:photo caption:formattedText show_caption_above_media:Bool has_spoiler:Bool is_secret:Bool = MessageContent;
@ -3143,7 +3143,7 @@ messageSticker sticker:sticker is_premium:Bool = MessageContent;
//@description A video message
//@video The video description
//@caption Video caption
//@show_caption_above_media True, if caption must be shown above the video; otherwise, caption must be shown below the video
//@show_caption_above_media True, if the caption must be shown above the video; otherwise, the caption must be shown below the video
//@has_spoiler True, if the video preview must be covered by a spoiler animation
//@is_secret True, if the video thumbnail must be blurred and the video must be shown only while tapped
messageVideo video:video caption:formattedText show_caption_above_media:Bool has_spoiler:Bool is_secret:Bool = MessageContent;
@ -3565,7 +3565,7 @@ inputMessageText text:formattedText link_preview_options:linkPreviewOptions clea
//@width Width of the animation; may be replaced by the server
//@height Height of the animation; may be replaced by the server
//@caption Animation caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the animation; otherwise, caption must be shown below the animation; not supported in secret chats
//@show_caption_above_media True, if the caption must be shown above the animation; otherwise, the caption must be shown below the animation; not supported in secret chats
//@has_spoiler True, if the animation preview must be covered by a spoiler animation; not supported in secret chats
inputMessageAnimation animation:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 caption:formattedText show_caption_above_media:Bool has_spoiler:Bool = InputMessageContent;
@ -3585,6 +3585,13 @@ inputMessageAudio audio:InputFile album_cover_thumbnail:inputThumbnail duration:
//@caption Document caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
inputMessageDocument document:InputFile thumbnail:inputThumbnail disable_content_type_detection:Bool caption:formattedText = InputMessageContent;
//@description A message with paid media; can be used only in channel chats
//@star_count The number of stars that must be paid to see the media; 1-getOption("paid_media_message_star_count_max")
//@paid_media The content of the paid media
//@caption Message caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if the caption must be shown above the video; otherwise, the caption must be shown below the video; not supported in secret chats
inputMessagePaidMedia star_count:int53 paid_media:vector<inputMessageExtendedMedia> caption:formattedText show_caption_above_media:Bool = InputMessageContent;
//@description A photo message
//@photo Photo to send. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20
//@thumbnail Photo thumbnail to be sent; pass null to skip thumbnail uploading. The thumbnail is sent to the other party only in secret chats
@ -3592,7 +3599,7 @@ inputMessageDocument document:InputFile thumbnail:inputThumbnail disable_content
//@width Photo width
//@height Photo height
//@caption Photo caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the photo; otherwise, caption must be shown below the photo; not supported in secret chats
//@show_caption_above_media True, if the caption must be shown above the photo; otherwise, the caption must be shown below the photo; not supported in secret chats
//@self_destruct_type Photo self-destruct type; pass null if none; private chats only
//@has_spoiler True, if the photo preview must be covered by a spoiler animation; not supported in secret chats
inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText show_caption_above_media:Bool self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
@ -3614,7 +3621,7 @@ inputMessageSticker sticker:InputFile thumbnail:inputThumbnail width:int32 heigh
//@height Video height
//@supports_streaming True, if the video is supposed to be streamed
//@caption Video caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the video; otherwise, caption must be shown below the video; not supported in secret chats
//@show_caption_above_media True, if the caption must be shown above the video; otherwise, the caption must be shown below the video; not supported in secret chats
//@self_destruct_type Video self-destruct type; pass null if none; private chats only
//@has_spoiler True, if the video preview must be covered by a spoiler animation; not supported in secret chats
inputMessageVideo video:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 supports_streaming:Bool caption:formattedText show_caption_above_media:Bool self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
@ -8432,7 +8439,7 @@ editMessageMedia chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_m
//@message_id Identifier of the message
//@reply_markup The new message reply markup; pass null if none; for bots only
//@caption New message content caption; 0-getOption("message_caption_length_max") characters; pass null to remove caption
//@show_caption_above_media Pass true to show the caption above the media; otherwise, caption will be shown below the media. Can be true only for animation, photo, and video messages
//@show_caption_above_media Pass true to show the caption above the media; otherwise, the caption will be shown below the media. Can be true only for animation, photo, and video messages
editMessageCaption chat_id:int53 message_id:int53 reply_markup:ReplyMarkup caption:formattedText show_caption_above_media:Bool = Message;
//@description Edits the message reply markup; for bots only. Returns the edited message after the edit is completed on the server side.
@ -8468,7 +8475,7 @@ editInlineMessageMedia inline_message_id:string reply_markup:ReplyMarkup input_m
//@inline_message_id Inline message identifier
//@reply_markup The new message reply markup; pass null if none
//@caption New message content caption; pass null to remove caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media Pass true to show the caption above the media; otherwise, caption will be shown below the media. Can be true only for animation, photo, and video messages
//@show_caption_above_media Pass true to show the caption above the media; otherwise, the caption will be shown below the media. Can be true only for animation, photo, and video messages
editInlineMessageCaption inline_message_id:string reply_markup:ReplyMarkup caption:formattedText show_caption_above_media:Bool = Ok;
//@description Edits the reply markup of an inline message sent via a bot; for bots only
@ -8545,7 +8552,7 @@ editBusinessMessageMedia business_connection_id:string chat_id:int53 message_id:
//@message_id Identifier of the message
//@reply_markup The new message reply markup; pass null if none
//@caption New message content caption; pass null to remove caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media Pass true to show the caption above the media; otherwise, caption will be shown below the media. Can be true only for animation, photo, and video messages
//@show_caption_above_media Pass true to show the caption above the media; otherwise, the caption will be shown below the media. Can be true only for animation, photo, and video messages
editBusinessMessageCaption business_connection_id:string chat_id:int53 message_id:int53 reply_markup:ReplyMarkup caption:formattedText show_caption_above_media:Bool = BusinessMessage;
//@description Edits the reply markup of a message sent on behalf of a business account; for bots only

View File

@ -779,9 +779,13 @@ Result<InputMessageContent> BusinessConnectionManager::process_input_message_con
if (input_message_content == nullptr) {
return Status::Error(400, "Can't send message without content");
}
if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) {
auto message_content_id = input_message_content->get_id();
if (message_content_id == td_api::inputMessageForwarded::ID) {
return Status::Error(400, "Can't forward messages as business");
}
if (message_content_id == td_api::inputMessagePaidMedia::ID) {
return Status::Error(400, "Can't send paid media as business");
}
return get_input_message_content(DialogId(), std::move(input_message_content), td_, true);
}

View File

@ -2662,6 +2662,10 @@ td_api::object_ptr<td_api::formattedText> extract_input_caption(
auto input_document = static_cast<td_api::inputMessageDocument *>(input_message_content.get());
return std::move(input_document->caption_);
}
case td_api::inputMessagePaidMedia::ID: {
auto input_paid_media = static_cast<td_api::inputMessagePaidMedia *>(input_message_content.get());
return std::move(input_paid_media->caption_);
}
case td_api::inputMessagePhoto::ID: {
auto input_photo = static_cast<td_api::inputMessagePhoto *>(input_message_content.get());
return std::move(input_photo->caption_);
@ -2685,6 +2689,10 @@ bool extract_input_invert_media(const td_api::object_ptr<td_api::InputMessageCon
auto input_animation = static_cast<const td_api::inputMessageAnimation *>(input_message_content.get());
return input_animation->show_caption_above_media_;
}
case td_api::inputMessagePaidMedia::ID: {
auto input_paid_media = static_cast<const td_api::inputMessagePaidMedia *>(input_message_content.get());
return input_paid_media->show_caption_above_media_;
}
case td_api::inputMessagePhoto::ID: {
auto input_photo = static_cast<const td_api::inputMessagePhoto *>(input_message_content.get());
return input_photo->show_caption_above_media_;
@ -2797,6 +2805,33 @@ static Result<InputMessageContent> create_input_message_content(
content = make_unique<MessageDocument>(file_id, std::move(caption));
break;
case td_api::inputMessagePaidMedia::ID: {
auto input_paid_media = static_cast<td_api::inputMessagePaidMedia *>(input_message_content.get());
invert_media = input_paid_media->show_caption_above_media_ && !is_secret;
if (input_paid_media->star_count_ <= 0 ||
input_paid_media->star_count_ >
td->option_manager_->get_option_integer("paid_media_message_star_count_max")) {
return Status::Error(400, "Invalid media price specified");
}
vector<MessageExtendedMedia> extended_media;
for (auto &paid_media : input_paid_media->paid_media_) {
TRY_RESULT(media, MessageExtendedMedia::get_message_extended_media(td, std::move(paid_media), dialog_id));
if (media.is_empty()) {
return Status::Error(400, "Paid media must be non-empty");
}
extended_media.push_back(std::move(media));
}
static constexpr size_t MAX_PAID_MEDIA = 10; // server side limit
if (extended_media.empty() || extended_media.size() > MAX_PAID_MEDIA) {
return Status::Error(400, "Invalid number of paid media specified");
}
content = td::make_unique<MessagePaidMedia>(std::move(extended_media), std::move(caption),
input_paid_media->star_count_);
break;
}
case td_api::inputMessagePhoto::ID: {
auto input_photo = static_cast<td_api::inputMessagePhoto *>(input_message_content.get());
@ -3396,9 +3431,16 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
return m->location.get_input_media_geo_point();
}
case MessageContentType::PaidMedia: {
// const auto *m = static_cast<const MessagePaidMedia *>(content);
// TODO get_input_media
return nullptr;
const auto *m = static_cast<const MessagePaidMedia *>(content);
vector<telegram_api::object_ptr<telegram_api::InputMedia>> input_media;
for (auto &extended_media : m->media) {
auto media = extended_media.get_input_media(td, std::move(input_file), std::move(input_thumbnail));
if (media == nullptr) {
return nullptr;
}
input_media.push_back(std::move(media));
}
return telegram_api::make_object<telegram_api::inputMediaPaidMedia>(m->star_count, std::move(input_media));
}
case MessageContentType::Photo: {
const auto *m = static_cast<const MessagePhoto *>(content);
@ -6533,7 +6575,6 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
auto result = make_unique<MessagePaidMedia>(*static_cast<const MessagePaidMedia *>(content));
if (type != MessageContentDupType::Forward) {
// TODO support PaidMedia sending
return nullptr;
}
return result;
}

View File

@ -24000,6 +24000,10 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect
} else {
auto input_media =
get_input_media(content, td_, m->ttl, m->send_emoji, td_->auth_manager_->is_bot() && bad_parts.empty());
if (file_ids.size() > 1u) {
// TODO PaidMedia
return;
}
if (input_media == nullptr) {
if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll ||
content_type == MessageContentType::Story) {

View File

@ -3345,13 +3345,17 @@ Result<InputMessageContent> QuickReplyManager::process_input_message_content(
if (input_message_content == nullptr) {
return Status::Error(400, "Can't add quick reply without content");
}
if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) {
auto message_content_id = input_message_content->get_id();
if (message_content_id == td_api::inputMessageForwarded::ID) {
return Status::Error(400, "Can't forward messages to quick replies");
}
if (input_message_content->get_id() == td_api::inputMessagePoll::ID) {
if (message_content_id == td_api::inputMessagePoll::ID) {
return Status::Error(400, "Can't add poll as a quick reply");
}
if (input_message_content->get_id() == td_api::inputMessageLocation::ID &&
if (message_content_id == td_api::inputMessagePaidMedia::ID) {
return Status::Error(400, "Can't send paid media as business");
}
if (message_content_id == td_api::inputMessageLocation::ID &&
static_cast<const td_api::inputMessageLocation *>(input_message_content.get())->live_period_ != 0) {
return Status::Error(400, "Can't add live location as a quick reply");
}

View File

@ -4967,6 +4967,26 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::addLocalMessage>(
chat_id, as_message_sender(sender_id), get_input_message_reply_to(), false,
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), get_link_preview_options(), true)));
} else if (op == "spmp") {
ChatId chat_id;
get_args(args, chat_id, args);
auto paid_media = transform(full_split(args), [this](const string &photo) {
return td_api::make_object<td_api::inputMessageExtendedMedia>(
td_api::make_object<td_api::inputMessageExtendedMediaTypePhoto>(), as_input_file(photo), nullptr,
vector<int32>(), 0, 0);
});
send_message(chat_id, td_api::make_object<td_api::inputMessagePaidMedia>(11, std::move(paid_media),
as_caption("12_3_ __4__"), rand_bool()));
} else if (op == "spmv") {
ChatId chat_id;
get_args(args, chat_id, args);
auto paid_media = transform(full_split(args), [this](const string &video) {
return td_api::make_object<td_api::inputMessageExtendedMedia>(
td_api::make_object<td_api::inputMessageExtendedMediaTypeVideo>(10, true), as_input_file(video), nullptr,
vector<int32>(), 0, 0);
});
send_message(chat_id, td_api::make_object<td_api::inputMessagePaidMedia>(12, std::move(paid_media),
as_caption("12_3_ __4__"), rand_bool()));
} else if (op == "smap") {
ChatId chat_id;
get_args(args, chat_id, args);