tgbot-cpp
Api.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Oleg Morozenkov
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
23 #ifndef TGBOT_CPP_API_H
24 #define TGBOT_CPP_API_H
25 
26 #include <string>
27 #include <vector>
28 
29 #include <boost/property_tree/ptree.hpp>
30 
31 #include "tgbot/net/HttpReqArg.h"
32 #include "tgbot/types/User.h"
33 #include "tgbot/types/Message.h"
35 #include "tgbot/types/InputFile.h"
37 #include "tgbot/types/Update.h"
39 #include "tgbot/types/Venue.h"
41 #include "tgbot/types/ChatMember.h"
42 #include "tgbot/types/File.h"
43 
44 namespace TgBot {
45 
46 class Bot;
47 
52 class Api {
53 
54 typedef std::shared_ptr<std::vector<std::string>> StringArrayPtr;
55 
56 friend class Bot;
57 
58 public:
59  Api(const std::string& token);
60 
65  User::Ptr getMe() const;
66 
78  Message::Ptr sendMessage(int64_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), const std::string& parseMode = "", bool disableNotification = false) const;
79 
88  Message::Ptr forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification = false) const;
89 
100  Message::Ptr sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const std::string& caption = "", int32_t replyToMessageId = 0,
101  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
102 
113  Message::Ptr sendPhoto(int64_t chatId, const std::string& photoId, const std::string& caption = "", int32_t replyToMessageId = 0,
114  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
115 
129  Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, const std::string &caption = "", int32_t duration = 0,
130  const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0,
131  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
132 
146  Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, const std::string &caption = "", int32_t duration = 0,
147  const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0,
148  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
149 
160  Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr& document, const std::string &caption = "", int32_t replyToMessageId = 0,
161  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
162 
173  Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, const std::string &caption = "", int32_t replyToMessageId = 0,
174  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
175 
185  Message::Ptr sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId = 0,
186  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
187 
197  Message::Ptr sendSticker(int64_t chatId, const std::string& stickerId, int32_t replyToMessageId = 0,
198  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
199 
213  Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "",
214  int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
215 
229  Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "",
230  int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
231 
243  Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr& voice, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0,
244  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
245 
257  Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0,
258  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
259 
270  Message::Ptr sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0,
271  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const;
272 
286  Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::string foursquareId = "",
287  bool disableNotification = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
288 
300  Message::Ptr sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName = "", bool disableNotification = false,
301  int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
302 
310  void sendChatAction(int64_t chatId, const std::string& action) const;
311 
319  UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const;
320 
326  File::Ptr getFile(int32_t fileId) const;
327 
333  bool leaveChat(int64_t chatId) const;
334 
340  Chat::Ptr getChat(int64_t chatId) const;
341 
347  std::vector<ChatMember::Ptr> getChatAdministrators(int64_t chatId) const;
348 
354  int32_t getChatMembersCount(int64_t chatId) const;
355 
362  ChatMember::Ptr getChatMember(int64_t chatId, int32_t userId) const;
363 
373  bool answerCallbackQuery(const std::string & callbackQueryId, const std::string & text="", bool showAlert=false, const std::string &url="", int32_t cacheTime=0) const;
374 
386  Message::Ptr editMessageText(const std::string& text, int64_t chatId=0, int32_t messageId=0, const std::string& inlineMessageId="",
387  const std::string& parseMode = "", bool disableWebPagePreview = false, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
388 
398  Message::Ptr editMessageCaption(int64_t chatId = 0, int32_t messageId = 0, const std::string& caption = "",
399  const std::string& inlineMessageId = "", const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
400 
409  Message::Ptr editMessageReplyMarkup(int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "",
410  const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const;
411 
422  std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0, const StringArrayPtr &allowedUpdates = nullptr) const;
423 
432  void setWebhook(const std::string& url = "", const InputFile::Ptr& certificate = nullptr, int32_t maxConnection = 40, const StringArrayPtr &allowedUpdates = nullptr) const;
433 
438  bool deleteWebhook() const;
439 
446 
459  bool answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
460  int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="", const std::string& switchPmText="", const std::string& switchPmParameter="") const;
461 
468  bool kickChatMember(int64_t chatId, int32_t userId) const;
469 
476  bool unbanChatMember(int64_t chatId, int32_t userId) const;
477 
478 private:
479  boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
480 
481  const std::string _token;
482 };
483 
484 }
485 
486 #endif //TGBOT_CPP_API_H
Chat::Ptr getChat(int64_t chatId) const
Message::Ptr sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
std::shared_ptr< File > Ptr
Definition: File.h:24
std::vector< Update::Ptr > getUpdates(int32_t offset=0, int32_t limit=100, int32_t timeout=0, const StringArrayPtr &allowedUpdates=nullptr) const
Definition: Api.h:44
Message::Ptr editMessageText(const std::string &text, int64_t chatId=0, int32_t messageId=0, const std::string &inlineMessageId="", const std::string &parseMode="", bool disableWebPagePreview=false, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr()) const
bool answerCallbackQuery(const std::string &callbackQueryId, const std::string &text="", bool showAlert=false, const std::string &url="", int32_t cacheTime=0) const
Definition: Api.h:52
std::shared_ptr< Message > Ptr
Definition: Message.h:52
Message::Ptr sendPhoto(int64_t chatId, const InputFile::Ptr &photo, const std::string &caption="", int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr &document, const std::string &caption="", int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
User::Ptr getMe() const
Message::Ptr sendSticker(int64_t chatId, const InputFile::Ptr &sticker, int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
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
std::shared_ptr< UserProfilePhotos > Ptr
Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr &voice, const std::string &caption="", int duration=0, int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
Message::Ptr sendMessage(int64_t chatId, const std::string &text, bool disableWebPagePreview=false, int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), const std::string &parseMode="", bool disableNotification=false) const
std::shared_ptr< WebhookInfo > Ptr
Definition: WebhookInfo.h:20
WebhookInfo::Ptr getWebhookInfo() const
void setWebhook(const std::string &url="", const InputFile::Ptr &certificate=nullptr, int32_t maxConnection=40, const StringArrayPtr &allowedUpdates=nullptr) const
Definition: Bot.h:38
bool unbanChatMember(int64_t chatId, int32_t userId) const
int32_t getChatMembersCount(int64_t chatId) const
std::shared_ptr< GenericReply > Ptr
Definition: GenericReply.h:37
Message::Ptr editMessageReplyMarkup(int64_t chatId=0, int32_t messageId=0, const std::string &inlineMessageId="", const GenericReply::Ptr &replyMarkup=GenericReply::Ptr()) const
std::shared_ptr< InputFile > Ptr
Definition: InputFile.h:39
Message::Ptr forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification=false) const
std::shared_ptr< Chat > Ptr
Definition: Chat.h:38
bool kickChatMember(int64_t chatId, int32_t userId) const
bool leaveChat(int64_t chatId) const
void sendChatAction(int64_t chatId, const std::string &action) const
bool answerInlineQuery(const std::string &inlineQueryId, const std::vector< InlineQueryResult::Ptr > &results, int32_t cacheTime=300, bool isPersonal=false, const std::string &nextOffset="", const std::string &switchPmText="", const std::string &switchPmParameter="") const
ChatMember::Ptr getChatMember(int64_t chatId, int32_t userId) const
bool deleteWebhook() const
Api(const std::string &token)
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
std::vector< ChatMember::Ptr > getChatAdministrators(int64_t chatId) const
UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset=0, int32_t limit=100) const
std::shared_ptr< ChatMember > Ptr
Definition: ChatMember.h:21
Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr &audio, const std::string &caption="", int32_t duration=0, const std::string &performer="", const std::string &title="", int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
Message::Ptr editMessageCaption(int64_t chatId=0, int32_t messageId=0, const std::string &caption="", const std::string &inlineMessageId="", const GenericReply::Ptr &replyMarkup=GenericReply::Ptr()) const
Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr &video, int32_t duration=0, int32_t width=0, int32_t height=0, const std::string &caption="", int32_t replyToMessageId=0, const GenericReply::Ptr &replyMarkup=GenericReply::Ptr(), bool disableNotification=false) const
File::Ptr getFile(int32_t fileId) const
std::shared_ptr< User > Ptr
Definition: User.h:38