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 
15 namespace Telegram {
16 
17  class TelegramBot;
18 
19  // Typedef for callbacks
20  typedef std::vector<std::string> TCommandLine;
21  typedef std::string(*CommandCallback)(TelegramBot*, TCommandLine);
22 
25  typedef struct {
26  std::string command;
28  std::string help_text;
29  } TCommand;
30  typedef std::map<std::string, TCommand> TCommandMap;
31 
32  class TelegramBot {
33 
34  public:
35  TelegramBot();
36  TelegramBot(std::string);
37 
38  void addCommand(TCommand);
39  void setWebhook(std::string);
40  void processMessage(std::string);
41  void sendMessage(std::string, Json::Int64);
42  void sendMessage(std::string, std::string);
43 
45  std::map<std::string, TCommand> getCommandMap();
46 
47  private:
48  std::string api_url;
51  Json::Int64 chat_id;
52 
53  void init();
54  void apiRequest(std::string, std::map<std::string, std::string>);
55  void apiRequestJson(std::string, std::map<std::string, std::string>);
56  std::string processCommand(std::string);
57  };
58 }
59 
60 #endif
std::string command
The command, e.g. /help.
Definition: TelegramBot.h:26
Telegram::Message * msg
Definition: TelegramBot.h:49
void sendMessage(std::string, Json::Int64)
Definition: TelegramBot.cc:90
std::string help_text
Help text of the command.
Definition: TelegramBot.h:28
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:123
std::map< std::string, TCommand > getCommandMap()
Definition: TelegramBot.cc:109
std::string processCommand(std::string)
Definition: TelegramBot.cc:187
CommandCallback callback
Pointer to the callback function.
Definition: TelegramBot.h:27
std::string(* CommandCallback)(TelegramBot *, TCommandLine)
Definition for a callback routine.
Definition: TelegramBot.h:21
std::map< std::string, TCommand > TCommandMap
Map that stores the known commands.
Definition: TelegramBot.h:30
TCommandMap command_map
Definition: TelegramBot.h:50
std::vector< std::string > TCommandLine
Arguments for the bot's commands.
Definition: TelegramBot.h:17
void addCommand(TCommand)
Definition: TelegramBot.cc:44
Telegram::Message * getMessage()
Definition: TelegramBot.cc:104
Json::Int64 chat_id
Definition: TelegramBot.h:51
void apiRequestJson(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:160
std::string api_url
Definition: TelegramBot.h:48