summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp83
-rw-r--r--src/TgTypeParser.cpp22
2 files changed, 97 insertions, 8 deletions
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;
}