summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--include/tgbot/Api.h29
-rw-r--r--include/tgbot/TgTypeParser.h8
-rw-r--r--include/tgbot/types/InlineQuery.h25
-rw-r--r--include/tgbot/types/InputInvoiceMessageContent.h140
-rw-r--r--include/tgbot/types/Message.h6
-rw-r--r--include/tgbot/types/VoiceChatScheduled.h26
-rw-r--r--src/Api.cpp25
-rw-r--r--src/TgTypeParser.cpp109
-rw-r--r--src/types/InputMessageContent.cpp2
10 files changed, 334 insertions, 38 deletions
diff --git a/README.md b/README.md
index f83854b..c64f9cf 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
- [x] Bot API 3.0 ~ 3.6
- [x] Bot API 4.0 ~ 4.9
-- [x] Bot API 5.0 ~ 5.1 (Implemented all APIs except 'Run Your Own Bot API Server')
+- [x] Bot API 5.0 ~ 5.2 (Implemented all APIs except 'Run Your Own Bot API Server')
## Sample
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 53a8850..a2de0a9 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -602,15 +602,22 @@ public:
bool allowSendingWithoutReply = false) const;
/**
- * @brief Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
+ * @brief Use this method when you need to tell the user that something is happening on the bot's side.
+ * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
*
- * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
+ * Example: The ImageBot needs some time to process a request and upload the image.
+ * Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo.
+ * The user will see a “sending photo” status for the bot.
+ *
* We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
*
- * @param chatId Unique identifier for the target chat.
- * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
+ * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.
+ *
+ * @return True on success.
*/
- void sendChatAction(std::int64_t chatId, const std::string& action) const;
+ bool sendChatAction(std::int64_t chatId,
+ const std::string& action) const;
/**
* @brief Use this method to get a list of profile pictures for a user.
@@ -1157,12 +1164,11 @@ public:
/**
* @brief Use this method to send invoices.
*
- * @param chatId Unique identifier for the target private chat
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param title Product name, 1-32 characters
* @param description Product description, 1-255 characters
* @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
* @param providerToken Payments provider token, obtained via Botfather
- * @param startParameter Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
* @param currency Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
* @param prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
* @param providerData Optional. A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
@@ -1181,6 +1187,9 @@ public:
* @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
* @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound.
* @param allowSendingWithoutReply Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
+ * @param maxTipAmount Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in https://core.telegram.org/bots/payments/currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
+ * @param suggestedTipAmounts Optional. A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount.
+ * @param startParameter Optional. Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter
*
* @return On success, the sent Message is returned.
*/
@@ -1189,7 +1198,6 @@ public:
const std::string& description,
const std::string& payload,
const std::string& providerToken,
- const std::string& startParameter,
const std::string& currency,
const std::vector<LabeledPrice::Ptr>& prices,
const std::string& providerData = "",
@@ -1207,7 +1215,10 @@ public:
std::int32_t replyToMessageId = 0,
GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(),
bool disableNotification = false,
- bool allowSendingWithoutReply = false) const;
+ bool allowSendingWithoutReply = false,
+ std::int32_t maxTipAmount = 0,
+ const std::vector<std::int32_t>& suggestedTipAmounts = std::vector<std::int32_t>(),
+ const std::string& startParameter = "") const;
/**
* @brief Use this method to reply to shipping queries.
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index 86f3b31..a4482f7 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -25,6 +25,7 @@
#include "tgbot/types/Location.h"
#include "tgbot/types/ProximityAlertTriggered.h"
#include "tgbot/types/MessageAutoDeleteTimerChanged.h"
+#include "tgbot/types/VoiceChatScheduled.h"
#include "tgbot/types/VoiceChatStarted.h"
#include "tgbot/types/VoiceChatEnded.h"
#include "tgbot/types/VoiceChatParticipantsInvited.h"
@@ -77,6 +78,7 @@
#include "tgbot/types/InputLocationMessageContent.h"
#include "tgbot/types/InputVenueMessageContent.h"
#include "tgbot/types/InputContactMessageContent.h"
+#include "tgbot/types/InputInvoiceMessageContent.h"
#include "tgbot/types/Invoice.h"
#include "tgbot/types/OrderInfo.h"
#include "tgbot/types/PreCheckoutQuery.h"
@@ -209,6 +211,9 @@ public:
MessageAutoDeleteTimerChanged::Ptr parseJsonAndGetMessageAutoDeleteTimerChanged(const boost::property_tree::ptree& data) const;
std::string parseMessageAutoDeleteTimerChanged(const MessageAutoDeleteTimerChanged::Ptr& object) const;
+ VoiceChatScheduled::Ptr parseJsonAndGetVoiceChatScheduled(const boost::property_tree::ptree& data) const;
+ std::string parseVoiceChatScheduled(const VoiceChatScheduled::Ptr& object) const;
+
VoiceChatStarted::Ptr parseJsonAndGetVoiceChatStarted(const boost::property_tree::ptree& data) const;
std::string parseVoiceChatStarted(const VoiceChatStarted::Ptr& object) const;
@@ -374,6 +379,9 @@ public:
InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const;
std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const;
+ InputInvoiceMessageContent::Ptr parseJsonAndGetInputInvoiceMessageContent(const boost::property_tree::ptree& data) const;
+ std::string parseInputInvoiceMessageContent(const InputInvoiceMessageContent::Ptr& object) const;
+
Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const;
std::string parseInvoice(const Invoice::Ptr& object) const;
diff --git a/include/tgbot/types/InlineQuery.h b/include/tgbot/types/InlineQuery.h
index e50f6d6..ad04b8f 100644
--- a/include/tgbot/types/InlineQuery.h
+++ b/include/tgbot/types/InlineQuery.h
@@ -11,6 +11,7 @@ namespace TgBot {
/**
* @brief This object represents an incoming inline query.
+ * When the user sends an empty query, your bot could return some default or trending results.
*
* @ingroup types
*/
@@ -19,31 +20,37 @@ public:
typedef std::shared_ptr<InlineQuery> Ptr;
/**
- * @brief Unique query identifier.
+ * @brief Unique identifier for this query
*/
std::string id;
/**
- * @brief Sender.
+ * @brief Sender
*/
User::Ptr from;
/**
- * @brief Optional. Sender location, only for bots that request user location
+ * @brief Text of the query (up to 256 characters)
*/
- Location::Ptr location;
+ std::string query;
/**
- * @brief Text of the query.
+ * @brief Offset of the results to be returned, can be controlled by the bot
*/
- std::string query;
+ std::string offset;
/**
- * @brief Offset of the results to be returned.
+ * @brief Optional. Type of the chat, from which the inline query was sent.
+ * Can be either “sender” for a private chat with the inline query sender, “private”, “group”, “supergroup”, or “channel”.
+ * The chat type should be always known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat
*/
- std::string offset;
-};
+ std::string chatType;
+ /**
+ * @brief Optional. Sender location, only for bots that request user location
+ */
+ Location::Ptr location;
+};
}
#endif //TGBOT_INLINEQUERY_H
diff --git a/include/tgbot/types/InputInvoiceMessageContent.h b/include/tgbot/types/InputInvoiceMessageContent.h
new file mode 100644
index 0000000..36f9056
--- /dev/null
+++ b/include/tgbot/types/InputInvoiceMessageContent.h
@@ -0,0 +1,140 @@
+#ifndef TGBOT_INPUTINVOICEMESSAGECONTENT_H
+#define TGBOT_INPUTINVOICEMESSAGECONTENT_H
+
+#include "tgbot/types/InputMessageContent.h"
+#include "tgbot/types/LabeledPrice.h"
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace TgBot {
+
+/**
+ * @brief Represents the content of an invoice message to be sent as the result of an inline query.
+ *
+ * @ingroup types
+ */
+class InputInvoiceMessageContent : public InputMessageContent {
+public:
+ static const std::string TYPE;
+
+ typedef std::shared_ptr<InputInvoiceMessageContent> Ptr;
+
+ InputInvoiceMessageContent() {
+ this->type = TYPE;
+ }
+
+ /**
+ * @brief Product name, 1-32 characters
+ */
+ std::string title;
+
+ /**
+ * @brief Product description, 1-255 characters
+ */
+ std::string description;
+
+ /**
+ * @brief Bot-defined invoice payload, 1-128 bytes.
+ * This will not be displayed to the user, use for your internal processes.
+ */
+ std::string payload;
+
+ /**
+ * @brief Payment provider token, obtained via Botfather
+ */
+ std::string providerToken;
+
+ /**
+ * @brief Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
+ */
+ std::string currency;
+
+ /**
+ * @brief Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
+ */
+ std::vector<LabeledPrice::Ptr> prices;
+
+ /**
+ * @brief Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double).
+ * For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145.
+ * See the exp parameter in https://core.telegram.org/bots/payments/currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
+ * Defaults to 0
+ */
+ std::int32_t maxTipAmount;
+
+ /**
+ * @brief Optional. A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double).
+ * At most 4 suggested tip amounts can be specified.
+ * The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount.
+ */
+ std::vector<std::int32_t> suggestedTipAmounts;
+
+ /**
+ * @brief Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider.
+ * A detailed description of the required fields should be provided by the payment provider.
+ */
+ std::string providerData;
+
+ /**
+ * @brief Optional. URL of the product photo for the invoice.
+ * Can be a photo of the goods or a marketing image for a service.
+ * People like it better when they see what they are paying for.
+ */
+ std::string photoUrl;
+
+ /**
+ * @brief Optional. Photo size
+ */
+ std::int32_t photoSize;
+
+ /**
+ * @brief Optional. Photo width
+ */
+ std::int32_t photoWidth;
+
+ /**
+ * @brief Optional. Photo height
+ */
+ std::int32_t photoHeight;
+
+ /**
+ * @brief Optional. Pass True, if you require the user's full name to complete the order
+ */
+ bool needName;
+
+ /**
+ * @brief Optional. Pass True, if you require the user's phone number to complete the order
+ */
+ bool needPhoneNumber;
+
+ /**
+ * @brief Optional. Pass True, if you require the user's email address to complete the order
+ */
+ bool needEmail;
+
+ /**
+ * @brief Optional. Pass True, if you require the user's shipping address to complete the order
+ */
+ bool needShippingAddress;
+
+ /**
+ * @brief Optional. Pass True, if user's phone number should be sent to provider
+ */
+ bool sendPhoneNumberToProvider;
+
+ /**
+ * @brief Optional. Pass True, if user's email address should be sent to provider
+ */
+ bool sendEmailToProvider;
+
+ /**
+ * @brief Optional. Pass True, if the final price depends on the shipping method
+ */
+ bool isFlexible;
+};
+}
+
+#endif //TGBOT_INPUTINVOICEMESSAGECONTENT_H
diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h
index fc99873..dc65604 100644
--- a/include/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -24,6 +24,7 @@
#include "tgbot/types/SuccessfulPayment.h"
#include "tgbot/types/PassportData.h"
#include "tgbot/types/ProximityAlertTriggered.h"
+#include "tgbot/types/VoiceChatScheduled.h"
#include "tgbot/types/VoiceChatStarted.h"
#include "tgbot/types/VoiceChatEnded.h"
#include "tgbot/types/VoiceChatParticipantsInvited.h"
@@ -322,6 +323,11 @@ public:
ProximityAlertTriggered::Ptr proximityAlertTriggered;
/**
+ * @brief Optional. Service message: voice chat scheduled
+ */
+ VoiceChatScheduled::Ptr voiceChatScheduled;
+
+ /**
* @brief Optional. Service message: voice chat started
*/
VoiceChatStarted::Ptr voiceChatStarted;
diff --git a/include/tgbot/types/VoiceChatScheduled.h b/include/tgbot/types/VoiceChatScheduled.h
new file mode 100644
index 0000000..8611d5f
--- /dev/null
+++ b/include/tgbot/types/VoiceChatScheduled.h
@@ -0,0 +1,26 @@
+#ifndef TGBOT_CPP_VOICECHATSCHEDULED_H
+#define TGBOT_CPP_VOICECHATSCHEDULED_H
+
+#include <cstdint>
+#include <memory>
+
+namespace TgBot {
+
+/**
+ * @brief This object represents a service message about a voice chat scheduled in the chat.
+ *
+ * @ingroup types
+ */
+class VoiceChatScheduled {
+
+public:
+ typedef std::shared_ptr<VoiceChatScheduled> Ptr;
+
+ /**
+ * @brief Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator
+ */
+ std::int32_t startDate;
+};
+}
+
+#endif //TGBOT_CPP_VOICECHATSCHEDULED_H
diff --git a/src/Api.cpp b/src/Api.cpp
index bcb711c..5cdab54 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -893,12 +893,15 @@ Message::Ptr Api::sendDice(std::int64_t chatId,
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args));
}
-void Api::sendChatAction(std::int64_t chatId, const string& action) const {
+bool Api::sendChatAction(std::int64_t chatId,
+ const std::string& action) const {
vector<HttpReqArg> args;
args.reserve(2);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("action", action);
- sendRequest("sendChatAction", args);
+
+ return sendRequest("sendChatAction", args).get<bool>("", false);
}
UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const {
@@ -1573,7 +1576,6 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId,
const std::string& description,
const std::string& payload,
const std::string& providerToken,
- const std::string& startParameter,
const std::string& currency,
const std::vector<LabeledPrice::Ptr>& prices,
const std::string& providerData,
@@ -1591,18 +1593,29 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId,
std::int32_t replyToMessageId,
GenericReply::Ptr replyMarkup,
bool disableNotification,
- bool allowSendingWithoutReply) const {
+ bool allowSendingWithoutReply,
+ std::int32_t maxTipAmount,
+ const std::vector<std::int32_t>& suggestedTipAmounts,
+ const std::string& startParameter) const {
vector<HttpReqArg> args;
- args.reserve(24);
+ args.reserve(26);
args.emplace_back("chat_id", chatId);
args.emplace_back("title", title);
args.emplace_back("description", description);
args.emplace_back("payload", payload);
args.emplace_back("provider_token", providerToken);
- args.emplace_back("start_parameter", startParameter);
args.emplace_back("currency", currency);
args.emplace_back("prices", _tgTypeParser.parseArray<LabeledPrice>(&TgTypeParser::parseLabeledPrice, prices));
+ args.emplace_back("max_tip_amount", maxTipAmount);
+ if (!suggestedTipAmounts.empty()) {
+ args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray<std::int32_t>([] (const std::int32_t& option) -> std::int32_t {
+ return option;
+ }, suggestedTipAmounts));
+ }
+ if (!startParameter.empty()) {
+ args.emplace_back("start_parameter", startParameter);
+ }
if (!providerData.empty()) {
args.emplace_back("provider_data", providerData);
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 0491360..48b542a 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -188,6 +188,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
result->proximityAlertTriggered = tryParseJson<ProximityAlertTriggered>(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered");
+ result->voiceChatScheduled = tryParseJson<VoiceChatScheduled>(&TgTypeParser::parseJsonAndGetVoiceChatScheduled, data, "voice_chat_scheduled");
result->voiceChatStarted = tryParseJson<VoiceChatStarted>(&TgTypeParser::parseJsonAndGetVoiceChatStarted, data, "voice_chat_started");
result->voiceChatEnded = tryParseJson<VoiceChatEnded>(&TgTypeParser::parseJsonAndGetVoiceChatEnded, data, "voice_chat_ended");
result->voiceChatParticipantsInvited = tryParseJson<VoiceChatParticipantsInvited>(&TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited, data, "voice_chat_participants_invited");
@@ -253,6 +254,7 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "connected_website", object->connectedWebsite);
appendToJson(result, "passport_data", parsePassportData(object->passportData));
appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered));
+ appendToJson(result, "voice_chat_scheduled", parseVoiceChatScheduled(object->voiceChatScheduled));
appendToJson(result, "voice_chat_started", parseVoiceChatStarted(object->voiceChatStarted));
appendToJson(result, "voice_chat_ended", parseVoiceChatEnded(object->voiceChatEnded));
appendToJson(result, "voice_chat_participants_invited", parseVoiceChatParticipantsInvited(object->voiceChatParticipantsInvited));
@@ -913,6 +915,24 @@ std::string TgTypeParser::parseMessageAutoDeleteTimerChanged(const MessageAutoDe
return result;
}
+VoiceChatScheduled::Ptr TgTypeParser::parseJsonAndGetVoiceChatScheduled(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<VoiceChatScheduled>());
+ result->startDate = data.get<std::int32_t>("start_date", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseVoiceChatScheduled(const VoiceChatScheduled::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "start_date", object->startDate);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
VoiceChatStarted::Ptr TgTypeParser::parseJsonAndGetVoiceChatStarted(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<VoiceChatStarted>());
return result;
@@ -1529,12 +1549,12 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con
InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<InlineQuery>());
- result->id = data.get<std::string>("id");
+ result->id = data.get<std::string>("id", "");
result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->query = data.get<std::string>("query", "");
+ result->offset = data.get<std::string>("offset", "");
+ result->chatType = data.get<std::string>("chat_type", "");
result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
- result->query = data.get<std::string>("query");
- result->offset = data.get<std::string>("offset");
-
return result;
}
@@ -1546,9 +1566,10 @@ std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const
result += '{';
appendToJson(result, "id", object->id);
appendToJson(result, "from", parseUser(object->from));
- appendToJson(result, "location", parseLocation(object->location));
appendToJson(result, "query", object->query);
appendToJson(result, "offset", object->offset);
+ appendToJson(result, "chat_type", object->chatType);
+ appendToJson(result, "location", parseLocation(object->location));
removeLastComma(result);
result += '}';
return result;
@@ -2499,17 +2520,20 @@ InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const
std::string messageText = data.get<std::string>("message_text", "");
float latitude = data.get<float>("latitude", 1000); // latitude belong (-90,90)
- std::string title = data.get<std::string>("title", "");
+ std::string address = data.get<std::string>("address", "");
std::string phoneNumber = data.get<std::string>("phone_number", "");
+ std::string description = data.get<std::string>("description", "");
if (!messageText.empty()) {
result = std::static_pointer_cast<InputMessageContent>(parseJsonAndGetInputTextMessageContent(data));
- } else if (!title.empty()) {
+ } else if (!address.empty()) {
result = std::static_pointer_cast<InputMessageContent>(parseJsonAndGetInputVenueMessageContent(data));
} else if (latitude != 1000) {
result = std::static_pointer_cast<InputMessageContent>(parseJsonAndGetInputLocationMessageContent(data));
} else if (!phoneNumber.empty()) {
result = std::static_pointer_cast<InputMessageContent>(parseJsonAndGetInputContactMessageContent(data));
+ } else if (!description.empty()) {
+ result = std::static_pointer_cast<InputMessageContent>(parseJsonAndGetInputInvoiceMessageContent(data));
} else {
result = std::make_shared<InputMessageContent>();
}
@@ -2526,15 +2550,14 @@ std::string TgTypeParser::parseInputMessageContent(const InputMessageContent::Pt
if (object->type == InputTextMessageContent::TYPE) {
result += parseInputTextMessageContent(std::static_pointer_cast<InputTextMessageContent>(object));
- }
- else if (object->type == InputLocationMessageContent::TYPE) {
+ } else if (object->type == InputLocationMessageContent::TYPE) {
result += parseInputLocationMessageContent(std::static_pointer_cast<InputLocationMessageContent>(object));
- }
- else if (object->type == InputVenueMessageContent::TYPE) {
+ } else if (object->type == InputVenueMessageContent::TYPE) {
result += parseInputVenueMessageContent(std::static_pointer_cast<InputVenueMessageContent>(object));
- }
- else if (object->type == InputContactMessageContent::TYPE) {
+ } else if (object->type == InputContactMessageContent::TYPE) {
result += parseInputContactMessageContent(std::static_pointer_cast<InputContactMessageContent>(object));
+ } else if (object->type == InputInvoiceMessageContent::TYPE) {
+ result += parseInputInvoiceMessageContent(std::static_pointer_cast<InputInvoiceMessageContent>(object));
}
removeLastComma(result);
@@ -2650,6 +2673,66 @@ std::string TgTypeParser::parseInputContactMessageContent(const InputContactMess
return result;
}
+InputInvoiceMessageContent::Ptr TgTypeParser::parseJsonAndGetInputInvoiceMessageContent(const boost::property_tree::ptree& data) const {
+ // NOTE: This function will be called by parseJsonAndGetInputMessageContent().
+ auto result(std::make_shared<InputInvoiceMessageContent>());
+ result->title = data.get<std::string>("title", "");
+ result->description = data.get<std::string>("description", "");
+ result->payload = data.get<std::string>("payload", "");
+ result->providerToken = data.get<std::string>("provider_token", "");
+ result->currency = data.get<std::string>("currency", "");
+ result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices");
+ result->maxTipAmount = data.get<std::int32_t>("max_tip_amount", 0);
+ result->suggestedTipAmounts = parseJsonAndGetArray<std::int32_t>([] (const boost::property_tree::ptree& innerData)->std::int32_t {
+ return innerData.get<std::int32_t>(0);
+ }, data, "suggested_tip_amounts");
+ result->providerData = data.get<std::string>("provider_data", "");
+ result->photoUrl = data.get<std::string>("photo_url", "");
+ result->photoSize = data.get<std::int32_t>("photo_size", 0);
+ result->photoWidth = data.get<std::int32_t>("photo_width", 0);
+ result->photoHeight = data.get<std::int32_t>("photo_height", 0);
+ result->needName = data.get<bool>("need_name", false);
+ result->needPhoneNumber = data.get<bool>("need_phone_number", false);
+ result->needEmail = data.get<bool>("need_email", false);
+ result->needShippingAddress = data.get<bool>("need_shipping_address", false);
+ result->sendPhoneNumberToProvider = data.get<bool>("send_phone_number_to_provider", false);
+ result->sendEmailToProvider = data.get<bool>("send_email_to_provider", false);
+ result->isFlexible = data.get<bool>("is_flexible", false);
+ return result;
+}
+
+std::string TgTypeParser::parseInputInvoiceMessageContent(const InputInvoiceMessageContent::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ // This function will be called by parseInputMessageContent()
+ std::string result;
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "description", object->description);
+ appendToJson(result, "payload", object->payload);
+ appendToJson(result, "provider_token", object->providerToken);
+ appendToJson(result, "currency", object->currency);
+ appendToJson(result, "prices", parseArray(&TgTypeParser::parseLabeledPrice, object->prices));
+ appendToJson(result, "max_tip_amount", object->maxTipAmount);
+ appendToJson(result, "suggested_tip_amounts", parseArray<std::int32_t>([] (std::int32_t i)->std::int32_t {
+ return i;
+ }, object->suggestedTipAmounts));
+ appendToJson(result, "provider_data", object->providerData);
+ appendToJson(result, "photo_url", object->photoUrl);
+ appendToJson(result, "photo_size", object->photoSize);
+ appendToJson(result, "photo_width", object->photoWidth);
+ appendToJson(result, "photo_height", object->photoHeight);
+ appendToJson(result, "need_name", object->needName);
+ appendToJson(result, "need_phone_number", object->needPhoneNumber);
+ appendToJson(result, "need_email", object->needEmail);
+ appendToJson(result, "need_shipping_address", object->needShippingAddress);
+ appendToJson(result, "send_phone_number_to_provider", object->sendPhoneNumberToProvider);
+ appendToJson(result, "send_email_to_provider", object->sendEmailToProvider);
+ appendToJson(result, "is_flexible", object->isFlexible);
+ // The last comma will be erased by parseInputMessageContent().
+ return result;
+}
+
Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<Invoice>());
result->title = data.get<std::string>("title");
diff --git a/src/types/InputMessageContent.cpp b/src/types/InputMessageContent.cpp
index 8f6d69d..2f54e00 100644
--- a/src/types/InputMessageContent.cpp
+++ b/src/types/InputMessageContent.cpp
@@ -2,6 +2,7 @@
#include "tgbot/types/InputLocationMessageContent.h"
#include "tgbot/types/InputVenueMessageContent.h"
#include "tgbot/types/InputContactMessageContent.h"
+#include "tgbot/types/InputInvoiceMessageContent.h"
#include <string>
@@ -11,3 +12,4 @@ const std::string InputTextMessageContent::TYPE = "text";
const std::string InputLocationMessageContent::TYPE = "location";
const std::string InputVenueMessageContent::TYPE = "venue";
const std::string InputContactMessageContent::TYPE = "contact";
+const std::string InputInvoiceMessageContent::TYPE = "invoice";