33 #define WEBHOOK_URL "https://<your-web-server>/cgi-bin/<binary name>" 
   34 #define BOT_TOKEN "<your token>" 
   35 #define SSTR( x ) static_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str() 
   37 std::string 
exec(
const char* cmd) {
 
   39   FILE* pipe = popen(cmd, 
"r");
 
   44   std::string result = 
"";
 
   46     if (fgets(buffer, 128, pipe) != NULL)
 
   54 std::vector<std::string> 
explode( 
const std::string &delimiter, 
const std::string &str) {
 
   56   std::vector<std::string> arr;
 
   58   int strleng = str.length();
 
   59   int delleng = delimiter.length();
 
   67     while ((i+j < strleng) && (j < delleng) && (str[i+j] == delimiter[j]))
 
   70       arr.push_back(str.substr(k, i-k));
 
   77   arr.push_back(str.substr(k, i-k));
 
   84   return(
"I am a simple Bot, written in C++\nHave fun.");
 
   89   std::map<std::string, Telegram::TCommand>::iterator it;
 
   90   std::string help_list = 
"Commands:\n";
 
   93   for (it = command_map.begin(); it != command_map.end(); it++) {
 
   94     help_list = help_list + it->first + 
": " + it->second.help_text + 
"\n";
 
  107   return(
exec(
"cat /proc/loadavg"));
 
  112   return(
exec(
"pstree"));
 
  116 int main(
int argc, 
char** argv) {
 
  117   std::vector<std::string> sExploded = 
explode(
".", argv[0]);
 
  120   if ((sExploded.size() > 1) && (sExploded[1] == 
"cgi")) {
 
  122     std::string line = 
"";
 
  125       std::getline(std::cin, s);
 
  134     sc.
help_text = 
"This is the start command";
 
  139     sc.
help_text = 
"Shows you the commands this bot knows";
 
  144     sc.
help_text = 
"Tells you your Telegram ID";
 
  149     sc.
help_text = 
"Shows average load of the system this bot is running on";
 
  154     sc.
help_text = 
"Shows the process list of the system the bot is running on";
 
  161     std::string user_id = 
""; 
 
  169     while ((c = getopt(argc, argv, 
"u:")) != -1) {
 
  172     user_id = (std::string)optarg;
 
  175     std::cerr << optopt << 
" without argument" << std::endl;
 
  181       std::cerr << 
"No user ID given!" << std::endl;
 
  188     if (tcgetattr(STDIN_FILENO, &t) < 0) {
 
  192     std::getline(std::cin, line);
 
std::string command
The command, e.g. /help. 
 
int main(int argc, char **argv)
 
std::string help(Telegram::TelegramBot *tg, Telegram::TCommandLine args)
 
std::string start(Telegram::TelegramBot *tg, Telegram::TCommandLine args)
 
void sendMessage(std::string, Json::Int64)
 
std::vector< std::string > explode(const std::string &delimiter, const std::string &str)
 
std::string help_text
Help text of the command. 
 
void processMessage(std::string)
 
std::map< std::string, TCommand > getCommandMap()
 
std::string exec(const char *cmd)
 
std::string proc(Telegram::TelegramBot *tg, Telegram::TCommandLine args)
 
CommandCallback callback
Pointer to the callback function. 
 
std::string whoami(Telegram::TelegramBot *tg, Telegram::TCommandLine args)
 
Telegram::Chat * getChat()
 
std::map< std::string, TCommand > TCommandMap
Map that stores the known commands. 
 
std::vector< std::string > TCommandLine
Arguments for the bot's commands. 
 
void addCommand(TCommand)
 
Telegram::Message * getMessage()
 
std::string loadavg(Telegram::TelegramBot *tg, Telegram::TCommandLine args)