diff options
-rw-r--r-- | include/tgbot/Api.h | 29 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 35 | ||||
-rw-r--r-- | include/tgbot/tgbot.h | 1 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultGif.h | 5 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultMpeg4Gif.h | 5 | ||||
-rw-r--r-- | include/tgbot/types/Invoice.h | 78 | ||||
-rw-r--r-- | include/tgbot/types/LabeledPrice.h | 42 | ||||
-rw-r--r-- | include/tgbot/types/Message.h | 5 | ||||
-rw-r--r-- | include/tgbot/types/OrderInfo.h | 66 | ||||
-rw-r--r-- | include/tgbot/types/PreCheckoutQuery.h | 91 | ||||
-rw-r--r-- | include/tgbot/types/ShippingAddress.h | 75 | ||||
-rw-r--r-- | include/tgbot/types/ShippingOption.h | 43 | ||||
-rw-r--r-- | include/tgbot/types/ShippingQuery.h | 68 | ||||
-rw-r--r-- | include/tgbot/types/SuccessfulPayment.h | 90 | ||||
-rw-r--r-- | include/tgbot/types/User.h | 5 | ||||
-rw-r--r-- | include/tgbot/types/VideoNote.h | 70 | ||||
-rw-r--r-- | src/Api.cpp | 44 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 232 |
18 files changed, 984 insertions, 0 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 4eb63c7..10cc91e 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -230,6 +230,35 @@ public: int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** + * Use this method to send video messages. On success, the sent Message is returned. + * @param chatId Unique identifier for the target chat. + * @param videoNote Video note to send. + * @param replyToMessageId If the message is a reply, ID of the original message. + * @param disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param duration Duration of sent video in seconds. + * @param length Video width and height. + * @param replyMarkup Additional interface options. A object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, + int32_t duration = 0, int32_t length = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr()); + + /** + * Use this method to send video messages. On success, the sent Message is returned. + * @param chatId Unique identifier for the target chat. + * @param videoNote Id of the video note that exists on the Telegram servers. + * @param replyToMessageId If the message is a reply, ID of the original message. + * @param disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param duration Duration of sent video in seconds. + * @param length Video width and height. + * @param replyMarkup Additional interface options. A object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVideoNote(int64_t chatId, const std::string &videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, + int32_t duration = 0, int32_t length = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr()); + + + /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. * @param chatId Unique identifier for the target chat. * @param voice Audio file to send. diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 2faaf45..bfae9aa 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -36,6 +36,7 @@ #include "tgbot/types/Document.h" #include "tgbot/types/Sticker.h" #include "tgbot/types/Video.h" +#include "tgbot/types/VideoNote.h" #include "tgbot/types/Contact.h" #include "tgbot/types/Location.h" #include "tgbot/types/Update.h" @@ -80,6 +81,14 @@ #include "tgbot/types/InputLocationMessageContent.h" #include "tgbot/types/InputVenueMessageContent.h" #include "tgbot/types/InputContactMessageContent.h" +#include "tgbot/types/Invoice.h" +#include "tgbot/types/OrderInfo.h" +#include "tgbot/types/PreCheckoutQuery.h" +#include "tgbot/types/ShippingAddress.h" +#include "tgbot/types/ShippingQuery.h" +#include "tgbot/types/ShippingOption.h" +#include "tgbot/types/SuccessfulPayment.h" +#include "tgbot/types/LabeledPrice.h" namespace TgBot { @@ -111,6 +120,8 @@ public: std::string parseSticker(const Sticker::Ptr& object) const; Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; std::string parseVideo(const Video::Ptr& object) const; + VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const; + std::string parseVideoNote(const VideoNote::Ptr& object) const; Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const; std::string parseContact(const Contact::Ptr& object) const; Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const; @@ -234,6 +245,30 @@ public: InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; + Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const; + std::string parseInvoice(const Invoice::Ptr& object) const; + + LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const; + std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const; + + OrderInfo::Ptr parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const; + std::string parseOrderInfo(const OrderInfo::Ptr& object) const; + + PreCheckoutQuery::Ptr parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const; + std::string parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const; + + ShippingAddress::Ptr parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const; + std::string parseShippingAddress(const ShippingAddress::Ptr& object) const; + + ShippingOption::Ptr parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const; + std::string parseShippingOption(const ShippingOption::Ptr& object) const; + + ShippingQuery::Ptr parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const; + std::string parseShippingQuery(const ShippingQuery::Ptr& object) const; + + SuccessfulPayment::Ptr parseJsonAndGetSucessfulPayment(const boost::property_tree::ptree& data) const; + std::string parseSucessfulPayment(const SuccessfulPayment::Ptr& object) const; + inline boost::property_tree::ptree parseJson(const std::string& json) const { boost::property_tree::ptree tree; std::istringstream input(json); diff --git a/include/tgbot/tgbot.h b/include/tgbot/tgbot.h index 39de85e..687783b 100644 --- a/include/tgbot/tgbot.h +++ b/include/tgbot/tgbot.h @@ -45,6 +45,7 @@ #include "tgbot/types/User.h" #include "tgbot/types/UserProfilePhotos.h" #include "tgbot/types/Video.h" +#include "tgbot/types/VideoNote.h" #include "tgbot/types/InlineQuery.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/InlineQueryResultArticle.h" diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index 6159886..1b6f9a3 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -44,6 +44,11 @@ public: int32_t gifHeight; /** + * Optional. Duration of the GIF + */ + int32_t gifDuration; + + /** * URL of the static thumbnail for the result (jpeg or gif) */ std::string thumbUrl; diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index c1dbb9e..9727281 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -39,6 +39,11 @@ public: int32_t mpeg4Height; /** + * Optional. Video duration. + */ + int32_t mpeg4Duration; + + /** * URL of the static thumbnail (jpeg or gif) for the result */ std::string thumbUrl; diff --git a/include/tgbot/types/Invoice.h b/include/tgbot/types/Invoice.h new file mode 100644 index 0000000..7836e14 --- /dev/null +++ b/include/tgbot/types/Invoice.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_INVOICE_H +#define TGBOT_INVOICE_H + +#include <string> +#include <memory> + +namespace TgBot { + +/** + * @brief This object contains basic information about an invoice. + * + * https://core.telegram.org/bots/api#invoice + * + * @ingroup types + */ +class Invoice { +public: + typedef std::shared_ptr<Invoice> Ptr; + + /** + * @brief Product name. + */ + std::string title; + + /** + * @brief Product description. + */ + std::string description; + + /** + * @brief Unique bot deep-linking parameter that can be used to generate this invoice. + */ + std::string startParameter; + + /** + * @brief Three-letter ISO 4217 currency code. + */ + std::string currency; + + /** + * @brief Total price in the smallest units of the currency (integer, + * not float/double). + * + * For example, for a price of US$ 1.45 pass + * amount = 145. See the exp parameter in currencies.json, it shows + * the number of digits past the decimal point for each currency (2 + * for the majority of currencies). + * + * https://core.telegram.org/bots/payments/currencies.json + */ + int32_t totalAmount; +}; +} + +#endif //TGBOT_INVOICE_H diff --git a/include/tgbot/types/LabeledPrice.h b/include/tgbot/types/LabeledPrice.h new file mode 100644 index 0000000..64b9aeb --- /dev/null +++ b/include/tgbot/types/LabeledPrice.h @@ -0,0 +1,42 @@ +// +// Created by Maks Mazurov (fox.cpp) on 21.05.17. +// + +#ifndef TGBOT_LABELEDPRICE_H +#define TGBOT_LABELEDPRICE_H + +#include <string> +#include <memory> + +namespace TgBot { + +/** + * @brief This object represents a portion of the price for goods or services. + * + * https://core.telegram.org/bots/api#labeledprice + * @ingroup types + */ +class LabeledPrice { +public: + typedef std::shared_ptr<LabeledPrice> Ptr; + + /** + * @brief Portion label. + */ + std::string label; + + /** + * @brief Price of the product in the smallest units of the currency (integer, + * not float/double). + * + * For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter + * in currencies.json, it shows the number of digits past the decimal point + * for each currency (2 for the majority of currencies). + * + * https://core.telegram.org/bots/payments/currencies.json + */ + int32_t amount; +}; +} + +#endif //TGBOT_LABELEDPRICE_H diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 415f616..ee293b9 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -176,6 +176,11 @@ public: User::Ptr newChatMember; /** + * Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) + */ + std::vector<User::Ptr> newChatMembers; + + /** * Optional. A member was removed from the group, information about them (this member may be bot itself). */ User::Ptr leftChatMember; diff --git a/include/tgbot/types/OrderInfo.h b/include/tgbot/types/OrderInfo.h new file mode 100644 index 0000000..45c3d75 --- /dev/null +++ b/include/tgbot/types/OrderInfo.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_ORDERINFO_H +#define TGBOT_ORDERINFO_H + +#include <string> +#include <memory> +#include "tgbot/types/ShippingAddress.h" + +namespace TgBot { + +/** + * @brief This object represents information about an order. + * + * https://core.telegram.org/bots/api#orderinfo + * + * @ingroup types + */ +class OrderInfo { +public: + typedef std::shared_ptr<OrderInfo> Ptr; + + /** + * @brief Optional. User name. + */ + std::string name; + + /** + * @brief Optional. User's phone number. + */ + std::string phoneNumber; + + /** + * @brief Optional. User email. + */ + std::string email; + + /** + * @brief Optional. User shipping address. + */ + ShippingAddress::Ptr shippingAddress; +}; +} + +#endif //TGBOT_ORDERINFO_H diff --git a/include/tgbot/types/PreCheckoutQuery.h b/include/tgbot/types/PreCheckoutQuery.h new file mode 100644 index 0000000..7282b3b --- /dev/null +++ b/include/tgbot/types/PreCheckoutQuery.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_PRECHECKOUTQUERY_H +#define TGBOT_PRECHECKOUTQUERY_H + +#include <string> +#include <memory> +#include <vector> +#include "tgbot/types/User.h" +#include "tgbot/types/OrderInfo.h" + +namespace TgBot { + +/** + * @brief This object contains information about an incoming pre-checkout query. + * + * https://core.telegram.org/bots/api#precheckoutquery + * + * @ingroup types + */ +class PreCheckoutQuery { +public: + typedef std::shared_ptr<PreCheckoutQuery> Ptr; + + /** + * @brief Unique query identifier. + */ + std::string id; + + /** + * @brief User who sent the query. + */ + User::Ptr from; + + /** + * @brief Three-letter ISO 4217 currency code. + */ + std::string currency; + + /** + * @brief Total price in the smallest units of the currency (integer, + * not float/double). + * + * For example, for a price of US$ 1.45 pass + * amount = 145. See the exp parameter in currencies.json, it shows + * the number of digits past the decimal point for each currency (2 + * for the majority of currencies). + * + * https://core.telegram.org/bots/payments/currencies.json + */ + int32_t totalAmount; + + /** + * @brief Bot specified invoice payload. + */ + std::string invoicePayload; + + /** + * @brief Optional. Identifier of the shipping option chosen by the user. + */ + std::string shippingOptionId; + + /** + * @brief Optional. Order info provided by the user. + */ + OrderInfo::Ptr orderInfo; +}; +} + +#endif //TGBOT_PRECHECKOUTQUERY_H diff --git a/include/tgbot/types/ShippingAddress.h b/include/tgbot/types/ShippingAddress.h new file mode 100644 index 0000000..97ac33f --- /dev/null +++ b/include/tgbot/types/ShippingAddress.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_SHIPPINGADDRESS_H +#define TGBOT_SHIPPINGADDRESS_H + +#include <string> +#include <memory> + +namespace TgBot { + +/** + * @brief This object represents a shipping address. + * + * https://core.telegram.org/bots/api#shippingaddress + * + * @ingroup types + */ +class ShippingAddress { +public: + typedef std::shared_ptr<ShippingAddress> Ptr; + + /** + * @brief ISO 3166-1 alpha-2 country code. + */ + std::string countryCode; + + /** + * @brief State, if applicable. + */ + std::string state; + + /** + * @brief City. + */ + std::string city; + + /** + * @brief First line for the address. + */ + std::string streetLine1; + + /** + * @brief Second line for the address. + */ + std::string streetLine2; + + /** + * Address post code. + */ + std::string postCode; +}; +} + +#endif //TGBOT_SHIPPINGADDRESS_H diff --git a/include/tgbot/types/ShippingOption.h b/include/tgbot/types/ShippingOption.h new file mode 100644 index 0000000..a946681 --- /dev/null +++ b/include/tgbot/types/ShippingOption.h @@ -0,0 +1,43 @@ +// +// Created by Maks Mazurov (fox.cpp) on 21.05.17. +// + +#ifndef TGBOT_SHIPPINGOPTION_H +#define TGBOT_SHIPPINGOPTION_H + +#include <string> +#include <memory> +#include <vector> +#include "tgbot/types/LabeledPrice.h" + +namespace TgBot { + +/** + * @brief This object represents one shipping option. + * + * https://core.telegram.org/bots/api#shippingoption + * + * @ingroup types + */ +class ShippingOption { +public: + typedef std::shared_ptr<ShippingOption> Ptr; + + /** + * @brief Shipping option identifier. + */ + std::string id; + + /** + * @brief Option title. + */ + std::string title; + + /** + * @brief List of price options. + */ + std::vector<LabeledPrice::Ptr> prices; +}; +} + +#endif //TGBOT_SHIPPINGOPTION_H diff --git a/include/tgbot/types/ShippingQuery.h b/include/tgbot/types/ShippingQuery.h new file mode 100644 index 0000000..47c20d8 --- /dev/null +++ b/include/tgbot/types/ShippingQuery.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_SHIPPINGQUERY_H +#define TGBOT_SHIPPINGQUERY_H + +#include <string> +#include <memory> +#include <vector> +#include "tgbot/types/User.h" +#include "tgbot/types/ShippingAddress.h" + +namespace TgBot { + +/** + * @brief This object contains information about an incoming shipping query. + * + * https://core.telegram.org/bots/api#shippingquery + * + * @ingroup types + */ +class ShippingQuery { +public: + typedef std::shared_ptr<ShippingQuery> Ptr; + + /** + * @brief Unique query identifier. + */ + std::string id; + + /** + * @brief User who sent the query. + */ + User::Ptr from; + + /** + * @brief Bot specified invoice payload. + */ + std::string invoicePayload; + + /** + * @brief User specified shipping address. + */ + ShippingAddress::Ptr shippingAddress; +}; +} + +#endif //TGBOT_SHIPPINGQUERY_H diff --git a/include/tgbot/types/SuccessfulPayment.h b/include/tgbot/types/SuccessfulPayment.h new file mode 100644 index 0000000..ed96e8b --- /dev/null +++ b/include/tgbot/types/SuccessfulPayment.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * Copyright (c) 2017 Maks Mazurov (fox.cpp) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_SUCCESSFULPAYMENT_H +#define TGBOT_SUCCESSFULPAYMENT_H + +#include <string> +#include <memory> +#include <vector> +#include "tgbot/types/OrderInfo.h" + +namespace TgBot { + +/** + * @brief This object contains basic information about a successful payment. + * + * https://core.telegram.org/bots/api#successfulpayment + * + * @ingroup types + */ +class SuccessfulPayment { +public: + typedef std::shared_ptr<SuccessfulPayment> Ptr; + + /** + * @brief Three-letter ISO 4217 currency code + */ + std::string currency; + + /** + * @brief Total price in the smallest units of the currency (integer, + * not float/double). + * + * For example, for a price of US$ 1.45 pass + * amount = 145. See the exp parameter in currencies.json, it shows + * the number of digits past the decimal point for each currency (2 + * for the majority of currencies). + * + * https://core.telegram.org/bots/payments/currencies.json + */ + int32_t totalAmount; + + /** + * @brief Bot specified invoice payload. + */ + std::string invoicePayload; + + /** + * @brief Optional. Identifier of the shipping option chosen by the user. + */ + std::string shippingOptionId; + + /** + * @brief Optional. Order info provided by the user. + */ + OrderInfo::Ptr orderInfo; + + /** + * @brief Telegram payment identifier. + */ + std::string telegramPaymentChargeId; + + /** + * @brief Provider payment identifier. + */ + std::string providerPaymentChargeId; +}; +} + +#endif //TGBOT_SUCCESSFULPAYMENT_H diff --git a/include/tgbot/types/User.h b/include/tgbot/types/User.h index 420d355..f3a6960 100644 --- a/include/tgbot/types/User.h +++ b/include/tgbot/types/User.h @@ -56,6 +56,11 @@ public: * Optional. User‘s or bot’s username. */ std::string username; + + /** + * Optional. IETF language tag of the user's language. + */ + std::string languageCode; }; } diff --git a/include/tgbot/types/VideoNote.h b/include/tgbot/types/VideoNote.h new file mode 100644 index 0000000..bff452e --- /dev/null +++ b/include/tgbot/types/VideoNote.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Oleg Morozenkov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TGBOT_CPP_VIDEONOTE_H +#define TGBOT_CPP_VIDEONOTE_H + +#include <string> +#include <memory> + +#include "tgbot/types/PhotoSize.h" + +namespace TgBot { + +/** + * This object represents a video message (available in Telegram apps as of v.4.0). + * @ingroup types + */ +class VideoNote { + +public: + typedef std::shared_ptr<VideoNote> Ptr; + + /** + * Unique identifier for this file. + */ + std::string fileId; + + /** + * Video width and height as defined by sender. + */ + int32_t length; + + /** + * Duration of the video in seconds as defined by sender. + */ + int32_t duration; + + /** + * Optional. Video thumbnail. + */ + PhotoSize::Ptr thumb; + + /** + * Optional. File size. + */ + int32_t fileSize; +}; + +} + +#endif //TGBOT_CPP_VIDEONOTE_H diff --git a/src/Api.cpp b/src/Api.cpp index 31e08f3..5e39a9a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -291,6 +291,50 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t durat return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } +Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) { + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("video_note", videoNote)); + if (disableNotification) { + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (length) { + args.push_back(HttpReqArg("length", length)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); +} + +Message::Ptr Api::sendVideoNote(int64_t chatId, const std::string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) { + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("video_note", videoNote)); + if (disableNotification) { + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (length) { + args.push_back(HttpReqArg("length", length)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); +} + Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 1b80d7f..c442600 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -85,6 +85,7 @@ User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { result->firstName = data.get<string>("first_name"); result->lastName = data.get("last_name", ""); result->username = data.get("username", ""); + result->languageCode = data.get("language_code", ""); return result; } @@ -98,6 +99,7 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); appendToJson(result, "username", object->username); + appendToJson(result, "language_code", object->languageCode); result.erase(result.length() - 1); result += '}'; return result; @@ -135,6 +137,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact"); result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->newChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant"); + result->newChatMembers = parseJsonAndGetArray<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_members"); result->leftChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_participant"); result->newChatTitle = data.get("new_chat_title", ""); result->newChatPhoto = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "new_chat_photo"); @@ -173,6 +176,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "contact", parseContact(object->contact)); appendToJson(result, "location", parseLocation(object->location)); appendToJson(result, "new_chat_member", parseUser(object->newChatMember)); + appendToJson(result, "new_chat_members", parseArray(&TgTypeParser::parseUser, object->newChatMembers)); appendToJson(result, "left_chat_member", parseUser(object->leftChatMember)); appendToJson(result, "new_chat_title", object->newChatTitle); appendToJson(result, "new_chat_photo", parseArray(&TgTypeParser::parsePhotoSize, object->newChatPhoto)); @@ -322,6 +326,32 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { return result; } +VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const ptree& data) const { + VideoNote::Ptr result(new VideoNote); + result->fileId = data.get<string>("file_id"); + result->length = data.get<int32_t>("length"); + result->duration = data.get<int32_t>("duration"); + result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->fileSize = data.get("file_size", 0); + return result; +} + +string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "file_id", object->fileId); + appendToJson(result, "length", object->length); + appendToJson(result, "duration", object->duration); + appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "file_size", object->fileSize); + result += '}'; + result.erase(); + return result; +} + Contact::Ptr TgTypeParser::parseJsonAndGetContact(const ptree& data) const { auto result(make_shared<Contact>()); result->phoneNumber = data.get<string>("phone_number"); @@ -1178,6 +1208,7 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons result->gifUrl = data.get<string>("gif_url", ""); result->gifWidth = data.get("gif_width", 0); result->gifHeight = data.get("gif_height", 0); + result->gifDuration = data.get("gif_duration", 0); result->thumbUrl = data.get<string>("thumb_url"); return result; } @@ -1191,6 +1222,7 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif:: appendToJson(result, "gif_url", object->gifUrl); appendToJson(result, "gif_width", object->gifWidth); appendToJson(result, "gif_height", object->gifHeight); + appendToJson(result, "gif_duration", object->gifDuration); appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; @@ -1202,6 +1234,7 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe result->mpeg4Url = data.get<string>("mpeg4_url"); result->mpeg4Width = data.get("mpeg4_width", 0); result->mpeg4Height = data.get("mpeg4_height", 0); + result->mpeg4Duration = data.get("mpeg4_duration", 0); result->thumbUrl = data.get<string>("thumb_url"); return result; } @@ -1216,6 +1249,7 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult appendToJson(result, "mpeg4_url", object->mpeg4Url); appendToJson(result, "mpeg4_width", object->mpeg4Width); appendToJson(result, "mpeg4_height", object->mpeg4Height); + appendToJson(result, "mpeg4_duration", object->mpeg4Duration); appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; @@ -1539,6 +1573,204 @@ std::string TgTypeParser::parseInputContactMessageContent(const InputContactMess return result; } +Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const { + auto result(make_shared<Invoice>()); + result->title = data.get<string>("title"); + result->description = data.get<string>("description"); + result->startParameter = data.get<string>("start_parameter"); + result->currency = data.get<string>("currency"); + result->totalAmount = data.get<int32_t>("total_amount"); + return result; +} + +std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const { + if (!object) { + return " "; + } + string result; + result += '{'; + appendToJson(result, "title", object->title); + appendToJson(result, "description", object->description); + appendToJson(result, "start_parameter", object->startParameter); + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +LabeledPrice::Ptr TgTypeParser::parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const { + auto result(make_shared<LabeledPrice>()); + result->label = data.get<string>("label"); + result->amount = data.get<int32_t>("amount"); + return result; +} + +string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "label", object->label); + appendToJson(result, "amount", object->amount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const { + auto result(make_shared<OrderInfo>()); + result->name = data.get<string>("name", ""); + result->phoneNumber = data.get<string>("phone_number", ""); + result->email = data.get<string>("email", ""); + result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + return result; +} + +string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const { + if (!object) { + return " "; + } + std::string result; + result += '{'; + if (!object->name.empty()) { + appendToJson(result, "name", object->name); + } + if (!object->phoneNumber.empty()) { + appendToJson(result, "phone_number", object->phoneNumber); + } + if (!object->email.empty()) { + appendToJson(result, "email", object->email); + } + if (!object->shippingAddress) { + result += R"("shipping_address":)"; + result += parseShippingAddress(object->shippingAddress); + result += ","; + } + result.erase(result.length() - 1); + result += '}'; + return result; +} + +PreCheckoutQuery::Ptr TgTypeParser::parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const { + auto result(make_shared<PreCheckoutQuery>()); + result->id = data.get<string>("id"); + result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->currency = data.get<string>("currency"); + result->totalAmount = data.get<int32_t>("total_amount"); + return result; +} + +string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "id", object->id); + result += R"("user":)"; + result += parseUser(object->from); + result += ","; + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ShippingAddress::Ptr TgTypeParser::parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const { + ShippingAddress::Ptr result; + result->countryCode = data.get<string>("country_code"); + result->state = data.get<string>("state", ""); + result->city = data.get<string>("city"); + result->streetLine1 = data.get<string>("street_line1"); + result->streetLine2 = data.get<string>("street_line2"); + result->postCode = data.get<string>("post_code"); + return result; +} + +string TgTypeParser::parseShippingAddress(const ShippingAddress::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "country_code", object->countryCode); + if (!object->state.empty()) { + appendToJson(result, "state", object->state); + } + appendToJson(result, "city", object->city); + appendToJson(result, "street_line1", object->streetLine1); + appendToJson(result, "street_line2", object->streetLine2); + appendToJson(result, "post_code", object->postCode); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ShippingOption::Ptr TgTypeParser::parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const { + auto result(make_shared<ShippingOption>()); + result->id = data.get<string>("id"); + result->title = data.get<string>("title"); + result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices"); + return result; +} + +string TgTypeParser::parseShippingOption(const ShippingOption::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "id", object->id); + appendToJson(result, "title", object->title); + result.erase(result.length() - 1); + result += R"("prices":)"; + result += parseArray(&TgTypeParser::parseLabeledPrice, object->prices); + result += '}'; + return result; +} + +ShippingQuery::Ptr TgTypeParser::parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const { + auto result(make_shared<ShippingQuery>()); + result->id = data.get<string>("id"); + result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->invoicePayload = data.get<string>("invoice_payload"); + result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + return result; +} + +string TgTypeParser::parseShippingQuery(const ShippingQuery::Ptr& object) const { + string result; + result += '{'; + appendToJson(result, "id", object->id); + result += R"("from":)"; + result += parseUser(object->from); + result += ","; + appendToJson(result, "invoice_payload", object->invoicePayload); + result += R"("shipping_address":)"; + result += parseShippingAddress(object->shippingAddress); + result += ","; + result.erase(result.length() - 1); + result += '}'; + return result; +} + +SuccessfulPayment::Ptr TgTypeParser::parseJsonAndGetSucessfulPayment(const boost::property_tree::ptree& data) const { + auto result(make_shared<SuccessfulPayment>()); + result->currency = data.get<string>("currency"); + result->totalAmount = data.get<int32_t>("total_amount"); + result->invoicePayload = data.get<string>("invoice_payload"); + result->shippingOptionId = data.get<string>("shipping_option_id"); + result->orderInfo = tryParseJson(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info"); + return result; +} + +std::string TgTypeParser::parseSucessfulPayment(const SuccessfulPayment::Ptr& object) const { + string result; + result += '{'; + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + appendToJson(result, "invoice_payload", object->invoicePayload); + appendToJson(result, "shipping_option_id", object->shippingOptionId); + result += R"("order_info":)"; + result += parseOrderInfo(object->orderInfo); + result += ","; + result.erase(result.length() - 1); + result += '}'; + return result; +} + + void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const { if (value.empty()) { return; |