From 9ba69d7e87c9b8ff9997294b68550852ef0274b8 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 17 Apr 2016 22:09:52 +0200 Subject: Added new type: Venue, MessageEntity Update Message type Added new method: sendVenue, sendContact, kickChatMember, unbanChatMember --- include/tgbot/Api.h | 45 +++++++++++++++++++++++++++++++++++ include/tgbot/types/Message.h | 47 ++++++++++++++++++++++++++++++------- include/tgbot/types/MessageEntity.h | 43 +++++++++++++++++++++++++++++++++ include/tgbot/types/Venue.h | 45 +++++++++++++++++++++++++++++++++++ include/tgbot/types/Voice.h | 43 +++++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 include/tgbot/types/MessageEntity.h create mode 100644 include/tgbot/types/Venue.h create mode 100644 include/tgbot/types/Voice.h (limited to 'include') diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index d7cfc0e..b6be878 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -36,6 +36,7 @@ #include "tgbot/types/UserProfilePhotos.h" #include "tgbot/types/Update.h" #include "tgbot/types/InlineQueryResult.h" +#include "tgbot/types/Venue.h" namespace TgBot { @@ -250,6 +251,36 @@ public: Message::Ptr sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + /** + * Use this method to send information about a venue. On success, the sent Message is returned. + * @param chatId Unique identifier for the target chat. + * @param latitude Latitude of location. + * @param longitude Longitude of location. + * @param title Name of the venue. + * @param address Address of the venue. + * @param foursquare_id Foursquare identifier of the venue. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * @param disableNotification Optional. Sends the message silenty. + * @return On success, the sent message is returned. + */ + Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::string foursquareId = "", + bool disableNotification = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + + /** + * Use this method to send phone contacts. On success, the sent Message is returned. + * @param chatId Unique identifier for the target chat. + * @param phoneNumber Contact's phone number. + * @param firstName Contact's first name. + * @param lastName Contact's last name. + * @param disableNotification Optional. Sends the message silenty. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * @return On success, the sent message is returned. + */ + Message::Ptr sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName = "", bool disableNotification = false, + int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + /** * 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. @@ -301,6 +332,20 @@ public: void answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="") const; + /** + * Use this method to kick a user from a group or a supergroup. + * @param chatId Unique identifier for the target group. + * @param userId Unique identifier of the target user. + */ + void kickChatMember(int64_t chatId, int32_t userId) const; + + /** + * Use this method to unban a previously kicked user in a supergroup. + * @param chatId Unique identifier for the target group. + * @param userId Unique identifier of the target user. + */ + void unbanChatMember(int64_t chatId, int32_t userId) const; + private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index ea53cf3..be1d313 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -37,6 +37,9 @@ #include "tgbot/types/Contact.h" #include "tgbot/types/Location.h" #include "tgbot/types/PhotoSize.h" +#include "tgbot/types/MessageEntity.h" +#include "tgbot/types/Venue.h" +#include "tgbot/types/Voice.h" namespace TgBot { @@ -45,10 +48,18 @@ namespace TgBot { * @ingroup types */ class Message { - public: typedef std::shared_ptr Ptr; + Message(){ + deleteChatPhoto = false; + groupChatCreated = false; + supergroupChatCreated = false; + channelChatCreated = false; + migrateToChatId = 0; + migrateFromChatId = 0; + } + /** * Unique message identifier. */ @@ -89,6 +100,11 @@ public: */ std::string text; + /** + * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. + */ + std::vector entities; + /** * Optional. Message is an audio file, information about the file. */ @@ -114,7 +130,15 @@ public: */ Video::Ptr video; - // TODO voice + /** + * Optional. Message is a voice message, information about the file. + */ + Voice::Ptr voice; + + /** + * Optional. Caption for the document, photo or video, 0-200 characters. + */ + std::string caption; /** * Optional. Message is a shared contact, information about the contact. @@ -126,15 +150,20 @@ public: */ Location::Ptr location; + /** + * Optional. Message is a venue, information about the venue. + */ + Venue::Ptr venue; + /** * Optional. A new member was added to the group, information about them (this member may be bot itself). */ - User::Ptr newChatParticipant; + User::Ptr newChatMember; /** * Optional. A member was removed from the group, information about them (this member may be bot itself). */ - User::Ptr leftChatParticipant; + User::Ptr leftChatMember; /** * Optional. A group title was changed to this value. @@ -156,11 +185,6 @@ public: */ bool groupChatCreated; - /** - * Optional. Text description of the photo or the video. - */ - std::string caption; - /** * Optional. Service message: the supergroup has been created. */ @@ -181,6 +205,11 @@ public: */ int64_t migrateFromChatId; + /** + * Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. + */ + Message::Ptr pinnedMessage; + }; } diff --git a/include/tgbot/types/MessageEntity.h b/include/tgbot/types/MessageEntity.h new file mode 100644 index 0000000..befcb3e --- /dev/null +++ b/include/tgbot/types/MessageEntity.h @@ -0,0 +1,43 @@ +// +// Created by Andrea Giove on 17/04/16. +// + +#ifndef TGBOT_MESSAGEENTITY_H +#define TGBOT_MESSAGEENTITY_H + +#include +#include + +namespace TgBot { + +/** + * This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. + * @ingroup types + */ +class MessageEntity { +public: + std::shared_ptr Ptr; + + /** + * Type of the entity. One of mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs). + */ + std::string type; + + /** + * Offset in UTF-16 code units to the start of the entity. + */ + int32_t offset; + + /** + * Length of the entity in UTF-16 code units + */ + int32_t length; + + /** + * Optional. For “text_link” only, url that will be opened after user taps on the text + */ + std::string url; +}; +} + +#endif //TGBOT_MESSAGEENTITY_H diff --git a/include/tgbot/types/Venue.h b/include/tgbot/types/Venue.h new file mode 100644 index 0000000..5040cce --- /dev/null +++ b/include/tgbot/types/Venue.h @@ -0,0 +1,45 @@ +// +// Created by Andrea Giove on 17/04/16. +// + +#ifndef TGBOT_VENUE_H +#define TGBOT_VENUE_H + +#include +#include + +#include "tgbot/types/Location.h" + +namespace TgBot { + +/** + * This object represents a venue. + * @ingroup types + */ +class Venue { +public: + typedef std::shared_ptr Ptr; + + /** + * Venue location. + */ + Location::Ptr location; + + /** + * Name of the venue. + */ + std::string title; + + /** + * Address of the venue. + */ + std::string address; + + /** + * Optional. Foursquare identifier of the venue. + */ + std::string foursquare_id; +}; +} + +#endif //TGBOT_VENUE_H diff --git a/include/tgbot/types/Voice.h b/include/tgbot/types/Voice.h new file mode 100644 index 0000000..385257d --- /dev/null +++ b/include/tgbot/types/Voice.h @@ -0,0 +1,43 @@ +// +// Created by Andrea Giove on 17/04/16. +// + +#ifndef TGBOT_VOICE_H +#define TGBOT_VOICE_H + +#include +#include + +namespace TgBot { + +/** + * This object represents a voice note. + * @ingroup types + */ +class Voice { +public: + std::shared_ptr Ptr; + + /** + * Unique identifier for this file. + */ + std::string file_id; + + /** + * Duration of the audio in seconds as defined by sender. + */ + int32_t duration; + + /** + * Optional. MIME type of the file as defined by sender; + */ + std::string mime_type; + + /** + * Optional. File size. + */ + int32_t file_size; +}; +} + +#endif //TGBOT_VOICE_H -- cgit v1.2.3