LibTgBotPP
 All Classes Namespaces Files Functions Variables Typedefs Macros
TelegramBot.h
Go to the documentation of this file.
1 #ifndef _TELEGRAM_BOT_H_
2 #define _TELEGRAM_BOT_H_
3 
4 #include <string>
5 #include <map>
6 
7 #include <curl/curl.h>
8 #include <json/json.h>
9 
10 #include <Telegram/Message.h>
11 #include <Telegram/User.h>
12 
16 namespace Telegram {
17 
18  class TelegramBot;
19 
20  // Typedef for callbacks
21  typedef std::vector<std::string> TCommandLine;
22  typedef std::string(*CommandCallback)(TelegramBot*, TCommandLine);
23 
26  typedef struct {
27  std::string command;
29  std::string help_text;
30  } TCommand;
31  typedef std::map<std::string, TCommand> TCommandMap;
32 
33  class TelegramBot {
34 
35  public:
36  TelegramBot();
37  TelegramBot(std::string);
38 
39  void addCommand(TCommand);
40  void setWebhook(std::string);
41  void processMessage(std::string);
42 
43  Telegram::User* getMe(void);
44 
45  Telegram::Message* sendMessage(std::string, Json::Int64);
46  Telegram::Message* sendMessage(std::string, std::string);
47 
48  Telegram::Message *sendPhoto(std::string, Json::Int64);
49  Telegram::Message *sendPhoto(std::string, std::string);
50 
52  std::map<std::string, TCommand> getCommandMap();
53 
54  private:
55  std::string api_url;
58  Json::Int64 chat_id;
59 
60  void init();
61  void apiRequest(std::string, std::map<std::string, std::string>);
62  Json::Value apiRequestJson(std::string, std::map<std::string, std::string>);
63  std::string processCommand(std::string);
64  };
65 }
66 
67 #endif
std::string command
The command, e.g. /help.
Definition: TelegramBot.h:27
Telegram::Message * msg
Definition: TelegramBot.h:56
std::string help_text
Help text of the command.
Definition: TelegramBot.h:29
Telegram::User * getMe(void)
Definition: TelegramBot.cc:87
void setWebhook(std::string)
Definition: TelegramBot.cc:60
void processMessage(std::string)
Definition: TelegramBot.cc:74
void apiRequest(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:165
std::map< std::string, TCommand > getCommandMap()
Definition: TelegramBot.cc:151
std::string processCommand(std::string)
Definition: TelegramBot.cc:238
CommandCallback callback
Pointer to the callback function.
Definition: TelegramBot.h:28
std::string(* CommandCallback)(TelegramBot *, TCommandLine)
Definition for a callback routine.
Definition: TelegramBot.h:22
std::map< std::string, TCommand > TCommandMap
Map that stores the known commands.
Definition: TelegramBot.h:31
TCommandMap command_map
Definition: TelegramBot.h:57
std::vector< std::string > TCommandLine
Arguments for the bot's commands.
Definition: TelegramBot.h:18
void addCommand(TCommand)
Definition: TelegramBot.cc:44
Telegram::Message * getMessage()
Definition: TelegramBot.cc:146
Json::Int64 chat_id
Definition: TelegramBot.h:58
Json::Value apiRequestJson(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:202
Telegram::Message * sendPhoto(std::string, Json::Int64)
Definition: TelegramBot.cc:124
Telegram::Message * sendMessage(std::string, Json::Int64)
Definition: TelegramBot.cc:100
std::string api_url
Definition: TelegramBot.h:55