Support sending messageInvoice via inline mode.

This commit is contained in:
levlam 2021-03-31 02:38:16 +03:00
parent d7afe3d3e2
commit 32a5fc6855
4 changed files with 41 additions and 8 deletions

View File

@ -1309,13 +1309,18 @@ address country_code:string state:string city:string street_line1:string street_
//@description Portion of the price of a product (e.g., "delivery cost", "tax amount") @label Label for this portion of the product price @amount Currency amount in the smallest units of the currency
labeledPricePart label:string amount:int53 = LabeledPricePart;
//@description Product invoice @currency ISO 4217 currency code @price_parts A list of objects used to calculate the total price of the product
//@description Product invoice @currency ISO 4217 currency code
//@price_parts A list of objects used to calculate the total price of the product
//@max_tip_amount The maximum allowed amount of tip in the smallest units of the currency
//@suggested_tip_amounts Suggested amounts of tip in the smallest units of the currency
//@is_test True, if the payment is a test payment
//@need_name True, if the user's name is needed for payment @need_phone_number True, if the user's phone number is needed for payment @need_email_address True, if the user's email address is needed for payment
//@need_shipping_address True, if the user's shipping address is needed for payment @send_phone_number_to_provider True, if the user's phone number will be sent to the provider
//@send_email_address_to_provider True, if the user's email address will be sent to the provider @is_flexible True, if the total price depends on the shipping method
//@need_name True, if the user's name is needed for payment
//@need_phone_number True, if the user's phone number is needed for payment
//@need_email_address True, if the user's email address is needed for payment
//@need_shipping_address True, if the user's shipping address is needed for payment
//@send_phone_number_to_provider True, if the user's phone number will be sent to the provider
//@send_email_address_to_provider True, if the user's email address will be sent to the provider
//@is_flexible True, if the total price depends on the shipping method
invoice currency:string price_parts:vector<labeledPricePart> max_tip_amount:int53 suggested_tip_amounts:vector<int53> is_test:Bool need_name:Bool need_phone_number:Bool need_email_address:Bool need_shipping_address:Bool send_phone_number_to_provider:Bool send_email_address_to_provider:Bool is_flexible:Bool = Invoice;
//@description Order information @name Name of the user @phone_number Phone number of the user @email_address Email address of the user @shipping_address Shipping address for this order; may be null

View File

@ -1451,6 +1451,13 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
reply_markup = std::move(inline_message->reply_markup_);
break;
}
case telegram_api::botInlineMessageMediaInvoice::ID: {
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaInvoice>(bot_inline_message);
reply_markup = std::move(inline_message->reply_markup_);
result.message_content =
make_unique<MessageInvoice>(get_input_invoice(std::move(inline_message), td, DialogId()));
break;
}
case telegram_api::botInlineMessageMediaGeo::ID: {
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaGeo>(bot_inline_message);
if ((inline_message->flags_ & telegram_api::botInlineMessageMediaGeo::PERIOD_MASK) != 0 &&

View File

@ -640,6 +640,25 @@ InputInvoice get_input_invoice(tl_object_ptr<telegram_api::messageMediaInvoice>
return result;
}
InputInvoice get_input_invoice(tl_object_ptr<telegram_api::botInlineMessageMediaInvoice> &&message_invoice, Td *td,
DialogId owner_dialog_id) {
InputInvoice result;
result.title = std::move(message_invoice->title_);
result.description = std::move(message_invoice->description_);
result.photo = get_web_document_photo(td->file_manager_.get(), std::move(message_invoice->photo_), owner_dialog_id);
// result.start_parameter = string();
result.invoice.currency = std::move(message_invoice->currency_);
result.invoice.is_test = (message_invoice->flags_ & telegram_api::messageMediaInvoice::TEST_MASK) != 0;
result.invoice.need_shipping_address =
(message_invoice->flags_ & telegram_api::messageMediaInvoice::SHIPPING_ADDRESS_REQUESTED_MASK) != 0;
// result.payload = string();
// result.provider_token = string();
// result.provider_data = string();
result.total_amount = message_invoice->total_amount_;
// result.receipt_message_id = MessageId();
return result;
}
Result<InputInvoice> process_input_message_invoice(
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td) {
CHECK(input_message_content != nullptr);
@ -849,12 +868,11 @@ tl_object_ptr<telegram_api::inputBotInlineMessageMediaInvoice> get_input_bot_inl
flags |= telegram_api::inputMediaInvoice::PHOTO_MASK;
}
return make_tl_object<telegram_api::inputBotInlineMessageMediaInvoice>(
flags, false /*ignored*/, false /*ignored*/, input_invoice.title, input_invoice.description,
std::move(input_web_document), get_input_invoice(input_invoice.invoice), BufferSlice(input_invoice.payload),
input_invoice.provider_token,
flags, input_invoice.title, input_invoice.description, std::move(input_web_document),
get_input_invoice(input_invoice.invoice), BufferSlice(input_invoice.payload), input_invoice.provider_token,
telegram_api::make_object<telegram_api::dataJSON>(
input_invoice.provider_data.empty() ? "null" : input_invoice.provider_data),
input_invoice.start_parameter, std::move(reply_markup));
std::move(reply_markup));
}
vector<FileId> get_input_invoice_file_ids(const InputInvoice &input_invoice) {

View File

@ -124,6 +124,9 @@ bool operator!=(const InputInvoice &lhs, const InputInvoice &rhs);
InputInvoice get_input_invoice(tl_object_ptr<telegram_api::messageMediaInvoice> &&message_invoice, Td *td,
DialogId owner_dialog_id);
InputInvoice get_input_invoice(tl_object_ptr<telegram_api::botInlineMessageMediaInvoice> &&message_invoice, Td *td,
DialogId owner_dialog_id);
Result<InputInvoice> process_input_message_invoice(
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td);