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 
12 namespace Telegram {
13 
14  class TelegramBot;
15 
16  // Typedef for callbacks
17  typedef std::vector<std::string> TCommandLine;
18  typedef std::string(*CommandCallback)(TelegramBot*, TCommandLine);
19  typedef struct {
20  std::string command;
22  std::string help_text;
23  } TCommand;
24  typedef std::map<std::string, TCommand> TCommandMap;
25 
26  class TelegramBot {
27 
28  public:
29  TelegramBot();
30  TelegramBot(std::string);
31 
32  void addCommand(TCommand);
33  void setWebhook(std::string);
34  void processMessage(std::string);
35  void sendMessage(std::string, Json::Int64);
36  void sendMessage(std::string, std::string);
37 
39  std::map<std::string, TCommand> getCommandMap();
40 
41  // Callback methods
42  /*
43  std::string start(Telegram::TelegramBot, tvCommandLine);
44  std::string help(tvCommandLine);
45  std::string whoami(tvCommandLine);
46  std::string loadavg(tvCommandLine);
47  std::string proc(tvCommandLine);
48  */
49 
50  private:
51  std::string api_url;
54  Json::Int64 chat_id;
55 
56  void init();
57  void apiRequest(std::string, std::map<std::string, std::string>);
58  void apiRequestJson(std::string, std::map<std::string, std::string>);
59  std::string processCommand(std::string);
60  };
61 }
62 
63 #endif
void init()
Definition: TelegramBot.cc:94
std::string command
Definition: TelegramBot.h:20
Telegram::Message * msg
Definition: TelegramBot.h:52
Definition: Message.h:27
void sendMessage(std::string, Json::Int64)
Definition: TelegramBot.cc:69
std::string help_text
Definition: TelegramBot.h:22
void setWebhook(std::string)
Definition: TelegramBot.cc:46
void processMessage(std::string)
Definition: TelegramBot.cc:55
void apiRequest(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:100
std::map< std::string, TCommand > getCommandMap()
Definition: TelegramBot.cc:88
std::string processCommand(std::string)
Definition: TelegramBot.cc:162
Definition: TelegramBot.h:19
TelegramBot()
Definition: TelegramBot.cc:20
CommandCallback callback
Definition: TelegramBot.h:21
std::string(* CommandCallback)(TelegramBot *, TCommandLine)
Definition: TelegramBot.h:18
std::map< std::string, TCommand > TCommandMap
Definition: TelegramBot.h:24
TCommandMap command_map
Definition: TelegramBot.h:53
std::vector< std::string > TCommandLine
Definition: TelegramBot.h:14
void addCommand(TCommand)
Definition: TelegramBot.cc:32
Telegram::Message * getMessage()
Definition: TelegramBot.cc:83
Json::Int64 chat_id
Definition: TelegramBot.h:54
void apiRequestJson(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:135
std::string api_url
Definition: TelegramBot.h:51
Definition: TelegramBot.h:26