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 
44  void sendPhoto(std::string, Json::Int64);
45  void sendPhoto(std::string, std::string);
46 
48  std::map<std::string, TCommand> getCommandMap();
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
std::string command
The command, e.g. /help.
Definition: TelegramBot.h:26
Telegram::Message * msg
Definition: TelegramBot.h:52
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:147
std::map< std::string, TCommand > getCommandMap()
Definition: TelegramBot.cc:133
void sendPhoto(std::string, Json::Int64)
Definition: TelegramBot.cc:110
std::string processCommand(std::string)
Definition: TelegramBot.cc:211
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:53
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:128
Json::Int64 chat_id
Definition: TelegramBot.h:54
void apiRequestJson(std::string, std::map< std::string, std::string >)
Definition: TelegramBot.cc:184
std::string api_url
Definition: TelegramBot.h:51