summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-11 13:58:09 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-11 13:58:09 +0200
commit0c3b44cead20fb421bdacaba7613348f7573b282 (patch)
tree74cef323003d7a542cf1f7e3801cb471c0aa4de8
parent924dd8b38b588fad05f55424f547e521ccfe71f5 (diff)
Update to API 6.1
-rw-r--r--README.md2
-rw-r--r--include/tgbot/Api.h72
-rw-r--r--include/tgbot/types/Animation.h7
-rw-r--r--include/tgbot/types/Audio.h15
-rw-r--r--include/tgbot/types/Chat.h34
-rw-r--r--include/tgbot/types/Document.h15
-rw-r--r--include/tgbot/types/File.h26
-rw-r--r--include/tgbot/types/InlineKeyboardButton.h12
-rw-r--r--include/tgbot/types/Sticker.h14
-rw-r--r--include/tgbot/types/User.h33
-rw-r--r--include/tgbot/types/Video.h15
-rw-r--r--include/tgbot/types/Voice.h7
-rw-r--r--src/Api.cpp83
-rw-r--r--src/TgTypeParser.cpp22
14 files changed, 272 insertions, 85 deletions
diff --git a/README.md b/README.md
index 54444e5..8d7b96d 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 ~ 4.9
- [x] Bot API 5.0 ~ 5.7 (Implemented all APIs except 'Run Your Own Bot API Server')
-- [x] Bot API 6.0
+- [x] Bot API 6.0 ~ 6.1
## Sample
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 5292e87..a3f4b37 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -69,37 +69,40 @@ public:
const StringArrayPtr& allowedUpdates = nullptr) const;
/**
- * @brief 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 @ref Update.
+ * @brief 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.
*
- * 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.
+ * If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secretToken.
+ * If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.
*
- * You will not be able to receive updates using @ref Api::getUpdates for as long as an outgoing webhook is set up.
+ * You will not be able to receive updates using Api::getUpdates for as long as an outgoing webhook is set up.
*
* To use a self-signed certificate, you need to upload your public key certificate using certificate parameter.
* Please upload as InputFile, sending a String will not work.
*
- * Ports currently supported for Webhooks: 443, 80, 88, 8443.
+ * Ports currently supported for webhooks: 443, 80, 88, 8443.
*
* If you're having any trouble setting up webhooks, please check out https://core.telegram.org/bots/webhooks.
*
- * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration
+ * @param url HTTPS URL to send updates to. Use an empty string to remove webhook integration
* @param certificate Optional. Upload your public key certificate so that the root certificate in use can be checked. See https://core.telegram.org/bots/self-signed for details.
- * @param maxConnection Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
- * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
+ * @param maxConnection Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
+ * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chatMember (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
* @param ipAddress Optional. The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
* @param dropPendingUpdates Optional. Pass True to drop all pending updates
+ * @param secretToken Optional. A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you.
*
- * @return True on success.
+ * @return Returns True on success.
*/
bool setWebhook(const std::string& url,
InputFile::Ptr certificate = nullptr,
std::int32_t maxConnection = 40,
const StringArrayPtr& allowedUpdates = nullptr,
const std::string& ipAddress = "",
- bool dropPendingUpdates = false) const;
+ bool dropPendingUpdates = false,
+ const std::string& secretToken = "") const;
/**
* @brief Use this method to remove webhook integration if you decide to switch back to @ref Api::getUpdates.
@@ -1430,6 +1433,53 @@ public:
bool protectContent = false) const;
/**
+ * @brief Use this method to create a link for an invoice.
+ *
+ * @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 Payment provider token, obtained via BotFather
+ * @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 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 maxTipAmount = 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 providerData Optional. 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.
+ * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
+ * @param photoSize Optional. Photo size in bytes
+ * @param photoWidth Optional. Photo width
+ * @param photoHeight Optional. Photo height
+ * @param needName Optional. Pass True, if you require the user's full name to complete the order
+ * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order
+ * @param needEmail Optional. Pass True, if you require the user's email address to complete the order
+ * @param needShippingAddress Optional. Pass True, if you require the user's shipping address to complete the order
+ * @param sendPhoneNumberToProvider Optional. Pass True, if the user's phone number should be sent to the provider
+ * @param sendEmailToProvider Optional. Pass True, if the user's email address should be sent to the provider
+ * @param isFlexible Optional. Pass True, if the final price depends on the shipping method
+ *
+ * @return Returns the created invoice link as String on success.
+ */
+ std::string createInvoiceLink(const std::string& title,
+ const std::string& description,
+ const std::string& payload,
+ const std::string& providerToken,
+ const std::string& currency,
+ const std::vector<LabeledPrice::Ptr>& prices,
+ std::int32_t maxTipAmount = 0,
+ const std::vector<std::int32_t>& suggestedTipAmounts = std::vector<std::int32_t>(),
+ const std::string& providerData = "",
+ const std::string& photoUrl = "",
+ std::int32_t photoSize = 0,
+ std::int32_t photoWidth = 0,
+ std::int32_t photoHeight = 0,
+ bool needName = false,
+ bool needPhoneNumber = false,
+ bool needEmail = false,
+ bool needShippingAddress = false,
+ bool sendPhoneNumberToProvider = false,
+ bool sendEmailToProvider = false,
+ bool isFlexible = false) const;
+
+ /**
* @brief Use this method to reply to shipping queries.
*
* If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shipping_query field to the bot.
diff --git a/include/tgbot/types/Animation.h b/include/tgbot/types/Animation.h
index ee3cdd4..8d9688f 100644
--- a/include/tgbot/types/Animation.h
+++ b/include/tgbot/types/Animation.h
@@ -60,9 +60,12 @@ public:
std::string mimeType;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
};
}
diff --git a/include/tgbot/types/Audio.h b/include/tgbot/types/Audio.h
index 50611ca..5095e5c 100644
--- a/include/tgbot/types/Audio.h
+++ b/include/tgbot/types/Audio.h
@@ -1,11 +1,11 @@
-#ifndef TGBOT_CPP_AUDIO_H
-#define TGBOT_CPP_AUDIO_H
+#ifndef TGBOT_AUDIO_H
+#define TGBOT_AUDIO_H
#include "tgbot/types/PhotoSize.h"
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
@@ -56,9 +56,12 @@ public:
std::string mimeType;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
/**
* @brief Optional. Thumbnail of the album cover to which the music file belongs
@@ -67,4 +70,4 @@ public:
};
}
-#endif //TGBOT_CPP_AUDIO_H
+#endif //TGBOT_AUDIO_H
diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h
index 24f7955..931427e 100644
--- a/include/tgbot/types/Chat.h
+++ b/include/tgbot/types/Chat.h
@@ -1,17 +1,18 @@
-#ifndef TGBOT_CPP_CHAT_H
-#define TGBOT_CPP_CHAT_H
+#ifndef TGBOT_CHAT_H
+#define TGBOT_CHAT_H
#include "tgbot/types/ChatPhoto.h"
#include "tgbot/types/ChatPermissions.h"
#include "tgbot/types/ChatLocation.h"
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
class Message;
+
/**
* @brief This object represents a chat.
*
@@ -81,20 +82,31 @@ public:
bool hasPrivateForwards;
/**
+ * @brief Optional. True, if users need to join the supergroup before they can send messages.
+ * Returned only in Api::getChat.
+ */
+ bool joinToSendMessages;
+
+ /**
+ * @brief Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators.
+ * Returned only in Api::getChat.
+ */
+ bool joinByRequest;
+
+ /**
* @brief Optional. Description, for groups, supergroups and channel chats.
* Returned only in Api::getChat.
*/
std::string description;
/**
- * @brief Optional. Chat invite link, for groups, supergroups and channel chats.
- * Each administrator in a chat generates their own invite links, so the bot must first generate the link using Api::exportChatInviteLink.
+ * @brief Optional. Primary invite link, for groups, supergroups and channel chats.
* Returned only in Api::getChat.
*/
std::string inviteLink;
/**
- * @brief Optional. Pinned message, for groups, supergroups and channels.
+ * @brief Optional. The most recent pinned message (by sending date).
* Returned only in Api::getChat.
*/
std::shared_ptr<Message> pinnedMessage;
@@ -106,13 +118,13 @@ public:
ChatPermissions::Ptr permissions;
/**
- * @brief Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user.
+ * @brief Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds.
* Returned only in Api::getChat.
*/
std::int32_t slowModeDelay;
/**
- * @brief Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds.
+ * @brief Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds.
* Returned only in Api::getChat.
*/
std::int32_t messageAutoDeleteTime;
@@ -137,21 +149,19 @@ public:
/**
* @brief Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats.
+ * Returned only in Api::getChat.
*
* This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it.
* But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
- *
- * Returned only in Api::getChat.
*/
std::int64_t linkedChatId;
/**
* @brief Optional. For supergroups, the location to which the supergroup is connected.
- *
* Returned only in Api::getChat.
*/
ChatLocation::Ptr location;
};
}
-#endif //TGBOT_CPP_CHAT_H
+#endif //TGBOT_CHAT_H
diff --git a/include/tgbot/types/Document.h b/include/tgbot/types/Document.h
index 71f4f3c..0593076 100644
--- a/include/tgbot/types/Document.h
+++ b/include/tgbot/types/Document.h
@@ -1,11 +1,11 @@
-#ifndef TGBOT_CPP_DOCUMENT_H
-#define TGBOT_CPP_DOCUMENT_H
+#ifndef TGBOT_DOCUMENT_H
+#define TGBOT_DOCUMENT_H
#include "tgbot/types/PhotoSize.h"
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
@@ -46,10 +46,13 @@ public:
std::string mimeType;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
};
}
-#endif //TGBOT_CPP_DOCUMENT_H
+#endif //TGBOT_DOCUMENT_H
diff --git a/include/tgbot/types/File.h b/include/tgbot/types/File.h
index e684528..e923881 100644
--- a/include/tgbot/types/File.h
+++ b/include/tgbot/types/File.h
@@ -1,18 +1,19 @@
-#ifndef TGBOT_CPP_FILE_H
-#define TGBOT_CPP_FILE_H
+#ifndef TGBOT_FILE_H
+#define TGBOT_FILE_H
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
/**
* @brief This object represents a file ready to be downloaded.
- * The file can be downloaded via @ref Api::downloadFile.
- * It is guaranteed that the @ref File::filePath will be valid for at least 1 hour.
- * When the @ref File::filePath expires, a new one can be requested by calling @ref Api::getFile.
- * Maximum file size to download is 20 MB
+ * The file can be downloaded via Api::downloadFile.
+ * It is guaranteed that the File::filePath will be valid for at least 1 hour.
+ * When the File::filePath expires, a new one can be requested by calling Api::getFile.
+ *
+ * The maximum file size to download is 20 MB
*
* @ingroup types
*/
@@ -33,16 +34,19 @@ public:
std::string fileUniqueId;
/**
- * @brief Optional. File size, if known
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
/**
* @brief Optional. File path.
- * Use @ref Api::downloadFile to get the file.
+ * Use Api::downloadFile to get the file.
*/
std::string filePath;
};
}
-#endif //TGBOT_CPP_FILE_H
+#endif //TGBOT_FILE_H
diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h
index 36f150d..f216669 100644
--- a/include/tgbot/types/InlineKeyboardButton.h
+++ b/include/tgbot/types/InlineKeyboardButton.h
@@ -26,7 +26,7 @@ public:
std::string text;
/**
- * @brief Optional. HTTP or tg:// url to be opened when the button is pressed.
+ * @brief Optional. HTTP or tg:// URL to be opened when the button is pressed.
* Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
*/
std::string url;
@@ -44,25 +44,25 @@ public:
WebAppInfo::Ptr webApp;
/**
- * @brief Optional. An HTTP URL used to automatically authorize the user.
+ * @brief Optional. An HTTPS URL used to automatically authorize the user.
* Can be used as a replacement for the Telegram Login Widget.
*/
LoginUrl::Ptr loginUrl;
/**
* @brief Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field.
- * Can be empty, in which case just the bot's username will be inserted.
+ * May be empty, in which case just the bot's username will be inserted.
*
* Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it.
- * Especially useful when combined with switch_pm… actions – in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
+ * Especially useful when combined with switch_pm… actions - in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
*/
std::string switchInlineQuery;
/**
* @brief Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field.
- * Can be empty, in which case only the bot's username will be inserted.
+ * May be empty, in which case only the bot's username will be inserted.
*
- * This offers a quick way for the user to open your bot in inline mode in the same chat – good for selecting something from multiple options.
+ * This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options.
*/
std::string switchInlineQueryCurrentChat;
diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h
index 2dd35fa..0d14ba4 100644
--- a/include/tgbot/types/Sticker.h
+++ b/include/tgbot/types/Sticker.h
@@ -1,12 +1,13 @@
-#ifndef TGBOT_CPP_STICKER_H
-#define TGBOT_CPP_STICKER_H
+#ifndef TGBOT_STICKER_H
+#define TGBOT_STICKER_H
#include "tgbot/types/PhotoSize.h"
+#include "tgbot/types/File.h"
#include "tgbot/types/MaskPosition.h"
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
@@ -67,6 +68,11 @@ public:
std::string setName;
/**
+ * @brief Optional. Premium animation for the sticker, if the sticker is premium
+ */
+ File::Ptr premiumAnimation;
+
+ /**
* @brief Optional. For mask stickers, the position where the mask should be placed
*/
MaskPosition::Ptr maskPosition;
@@ -78,4 +84,4 @@ public:
};
}
-#endif //TGBOT_CPP_STICKER_H
+#endif //TGBOT_STICKER_H
diff --git a/include/tgbot/types/User.h b/include/tgbot/types/User.h
index 629ee6c..328c0a2 100644
--- a/include/tgbot/types/User.h
+++ b/include/tgbot/types/User.h
@@ -1,5 +1,5 @@
-#ifndef TGBOT_CPP_USER_H
-#define TGBOT_CPP_USER_H
+#ifndef TGBOT_USER_H
+#define TGBOT_USER_H
#include <cstdint>
#include <string>
@@ -18,7 +18,10 @@ public:
typedef std::shared_ptr<User> Ptr;
/**
- * @brief Unique identifier for this user or bot
+ * @brief Unique identifier for this user or bot.
+ *
+ * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier.
*/
std::int64_t id;
@@ -28,17 +31,17 @@ public:
bool isBot;
/**
- * @brief User‘s or bot’s first name
+ * @brief User's or bot's first name
*/
std::string firstName;
/**
- * @brief Optional. User‘s or bot’s last name
+ * @brief Optional. User's or bot's last name
*/
std::string lastName;
/**
- * @brief Optional. User‘s or bot’s username
+ * @brief Optional. User's or bot's username
*/
std::string username;
@@ -48,23 +51,33 @@ public:
std::string languageCode;
/**
+ * @brief Optional. True, if this user is a Telegram Premium user
+ */
+ bool isPremium;
+
+ /**
+ * @brief Optional. True, if this user added the bot to the attachment menu
+ */
+ bool addedToAttachmentMenu;
+
+ /**
* @brief Optional. True, if the bot can be invited to groups.
- * Returned only in @ref Api::getMe.
+ * Returned only in Api::getMe.
*/
bool canJoinGroups;
/**
* @brief Optional. True, if privacy mode is disabled for the bot.
- * Returned only in @ref Api::getMe.
+ * Returned only in Api::getMe.
*/
bool canReadAllGroupMessages;
/**
* @brief Optional. True, if the bot supports inline queries.
- * Returned only in @ref Api::getMe.
+ * Returned only in Api::getMe.
*/
bool supportsInlineQueries;
};
}
-#endif //TGBOT_CPP_USER_H
+#endif //TGBOT_USER_H
diff --git a/include/tgbot/types/Video.h b/include/tgbot/types/Video.h
index c1328b5..95590ad 100644
--- a/include/tgbot/types/Video.h
+++ b/include/tgbot/types/Video.h
@@ -1,11 +1,11 @@
-#ifndef TGBOT_CPP_VIDEO_H
-#define TGBOT_CPP_VIDEO_H
+#ifndef TGBOT_VIDEO_H
+#define TGBOT_VIDEO_H
#include "tgbot/types/PhotoSize.h"
#include <cstdint>
-#include <string>
#include <memory>
+#include <string>
namespace TgBot {
@@ -61,10 +61,13 @@ public:
std::string mimeType;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
};
}
-#endif //TGBOT_CPP_VIDEO_H
+#endif //TGBOT_VIDEO_H
diff --git a/include/tgbot/types/Voice.h b/include/tgbot/types/Voice.h
index c337b0a..763ffae 100644
--- a/include/tgbot/types/Voice.h
+++ b/include/tgbot/types/Voice.h
@@ -38,9 +38,12 @@ public:
std::string mimeType;
/**
- * @brief Optional. File size
+ * @brief Optional. File size in bytes.
+ *
+ * It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it.
+ * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value.
*/
- std::int32_t fileSize;
+ std::int64_t fileSize;
};
}
diff --git a/src/Api.cpp b/src/Api.cpp
index ee17b51..8d5ef2d 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -45,9 +45,10 @@ bool Api::setWebhook(const std::string& url,
std::int32_t maxConnection,
const StringArrayPtr& allowedUpdates,
const std::string& ipAddress,
- bool dropPendingUpdates) const {
+ bool dropPendingUpdates,
+ const std::string& secretToken) const {
vector<HttpReqArg> args;
- args.reserve(6);
+ args.reserve(7);
args.emplace_back("url", url);
if (certificate != nullptr) {
@@ -69,6 +70,9 @@ bool Api::setWebhook(const std::string& url,
if (dropPendingUpdates) {
args.emplace_back("drop_pending_updates", dropPendingUpdates);
}
+ if (!secretToken.empty()) {
+ args.emplace_back("secret_token", secretToken);
+ }
return sendRequest("setWebhook").get<bool>("", false);
}
@@ -1919,6 +1923,81 @@ Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, const std::string&> c
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args));
}
+std::string Api::createInvoiceLink(const std::string& title,
+ const std::string& description,
+ const std::string& payload,
+ const std::string& providerToken,
+ const std::string& currency,
+ const std::vector<LabeledPrice::Ptr>& prices,
+ std::int32_t maxTipAmount,
+ const std::vector<std::int32_t>& suggestedTipAmounts,
+ const std::string& providerData,
+ const std::string& photoUrl,
+ std::int32_t photoSize,
+ std::int32_t photoWidth,
+ std::int32_t photoHeight,
+ bool needName,
+ bool needPhoneNumber,
+ bool needEmail,
+ bool needShippingAddress,
+ bool sendPhoneNumberToProvider,
+ bool sendEmailToProvider,
+ bool isFlexible) const {
+ vector<HttpReqArg> args;
+ args.reserve(20);
+
+ args.emplace_back("title", title);
+ args.emplace_back("description", description);
+ args.emplace_back("payload", payload);
+ args.emplace_back("provider_token", providerToken);
+ 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 (!providerData.empty()) {
+ args.emplace_back("provider_data", providerData);
+ }
+ if (!photoUrl.empty()) {
+ args.emplace_back("photo_url", photoUrl);
+ }
+ if (photoSize) {
+ args.emplace_back("photo_size", photoSize);
+ }
+ if (photoWidth) {
+ args.emplace_back("photo_width", photoWidth);
+ }
+ if (photoHeight) {
+ args.emplace_back("photo_height", photoHeight);
+ }
+ if (needName) {
+ args.emplace_back("need_name", needName);
+ }
+ if (needPhoneNumber) {
+ args.emplace_back("need_phone_number", needPhoneNumber);
+ }
+ if (needEmail) {
+ args.emplace_back("need_email", needEmail);
+ }
+ if (needShippingAddress) {
+ args.emplace_back("need_shipping_address", needShippingAddress);
+ }
+ if (sendPhoneNumberToProvider) {
+ args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider);
+ }
+ if (sendEmailToProvider) {
+ args.emplace_back("send_email_to_provider", sendEmailToProvider);
+ }
+ if (isFlexible) {
+ args.emplace_back("is_flexible", isFlexible);
+ }
+
+ return sendRequest("createInvoiceLink", args).get<std::string>("", "");
+}
+
bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector<ShippingOption::Ptr>& shippingOptions, const std::string& errorMessage) const {
vector<HttpReqArg> args;
args.reserve(4);
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 27e96ae..e6a4317 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -25,6 +25,8 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d
result->photo = tryParseJson<ChatPhoto>(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo");
result->bio = data.get<std::string>("bio", "");
result->hasPrivateForwards = data.get<bool>("has_private_forwards", false);
+ result->joinToSendMessages = data.get<bool>("join_to_send_messages", false);
+ result->joinByRequest = data.get<bool>("join_by_request", false);
result->description = data.get<std::string>("description", "");
result->inviteLink = data.get<std::string>("invite_link", "");
result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message");
@@ -62,6 +64,8 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const {
appendToJson(result, "photo", parseChatPhoto(object->photo));
appendToJson(result, "bio", object->bio);
appendToJson(result, "has_private_forwards", object->hasPrivateForwards);
+ appendToJson(result, "join_to_send_messages", object->joinToSendMessages);
+ appendToJson(result, "join_by_request", object->joinByRequest);
appendToJson(result, "description", object->description);
appendToJson(result, "invite_link", object->inviteLink);
appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage));
@@ -86,6 +90,8 @@ User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& d
result->lastName = data.get<std::string>("last_name", "");
result->username = data.get<std::string>("username", "");
result->languageCode = data.get<std::string>("language_code", "");
+ result->isPremium = data.get<bool>("is_premium", false);
+ result->addedToAttachmentMenu = data.get<bool>("added_to_attachment_menu", false);
result->canJoinGroups = data.get<bool>("can_join_groups", false);
result->canReadAllGroupMessages = data.get<bool>("can_read_all_group_messages", false);
result->supportsInlineQueries = data.get<bool>("supports_inline_queries", false);
@@ -104,6 +110,8 @@ std::string TgTypeParser::parseUser(const User::Ptr& object) const {
appendToJson(result, "last_name", object->lastName);
appendToJson(result, "username", object->username);
appendToJson(result, "language_code", object->languageCode);
+ appendToJson(result, "is_premium", object->isPremium);
+ appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu);
appendToJson(result, "can_join_groups", object->canJoinGroups);
appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages);
appendToJson(result, "supports_inline_queries", object->supportsInlineQueries);
@@ -328,7 +336,7 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const boost::property_tree::ptree&
result->title = data.get<std::string>("title", "");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
return result;
}
@@ -360,7 +368,7 @@ Document::Ptr TgTypeParser::parseJsonAndGetDocument(const boost::property_tree::
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
@@ -392,6 +400,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->emoji = data.get<std::string>("emoji", "");
result->setName = data.get<std::string>("set_name", "");
+ result->premiumAnimation = tryParseJson<File>(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation");
result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position");
result->fileSize = data.get<std::int32_t>("file_size", 0);
return result;
@@ -412,6 +421,7 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
appendToJson(result, "thumb", parsePhotoSize(object->thumb));
appendToJson(result, "emoji", object->emoji);
appendToJson(result, "set_name", object->setName);
+ appendToJson(result, "premium_animation", parseFile(object->premiumAnimation));
appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition));
appendToJson(result, "file_size", object->fileSize);
removeLastComma(result);
@@ -643,7 +653,7 @@ Video::Ptr TgTypeParser::parseJsonAndGetVideo(const boost::property_tree::ptree&
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
@@ -673,7 +683,7 @@ Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const boost::property_tree::ptree&
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
result->duration = data.get<std::int32_t>("duration", 0);
result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
@@ -796,7 +806,7 @@ Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const boost::property_tree
result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
result->fileName = data.get<std::string>("file_name", "");
result->mimeType = data.get<std::string>("mime_type", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
return result;
}
@@ -1274,7 +1284,7 @@ File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& d
auto result(std::make_shared<File>());
result->fileId = data.get<std::string>("file_id", "");
result->fileUniqueId = data.get<std::string>("file_unique_id", "");
- result->fileSize = data.get<std::int32_t>("file_size", 0);
+ result->fileSize = data.get<std::int64_t>("file_size", 0);
result->filePath = data.get<std::string>("file_path", "");
return result;
}