|
|
@ -107,22 +107,22 @@ void Telegram::TelegramBot::sendMessage(std::string message, std::string chat_id |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sends a picture from the internet to a chat |
|
|
|
* Sends a picture from the internet to a chat |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Telegram::TelegramBot::sendPhoto(std::string URL, Json::Int64 chat_id) { |
|
|
|
Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, Json::Int64 chat_id) { |
|
|
|
|
|
|
|
|
|
|
|
this->sendPhoto(URL, SSTR(chat_id)); |
|
|
|
return(this->sendPhoto(URL, SSTR(chat_id))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sends a picture from the internet to a chat |
|
|
|
* Sends a picture from the internet to a chat |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Telegram::TelegramBot::sendPhoto(std::string URL, std::string chat_id) { |
|
|
|
Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, std::string chat_id) { |
|
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> params; |
|
|
|
std::map<std::string, std::string> params; |
|
|
|
|
|
|
|
|
|
|
|
params["chat_id"] = chat_id; |
|
|
|
params["chat_id"] = chat_id; |
|
|
|
params["photo"] = URL; |
|
|
|
params["photo"] = URL; |
|
|
|
|
|
|
|
|
|
|
|
this->apiRequestJson("sendPhoto", params); |
|
|
|
return(this->apiRequestJson("sendPhoto", params)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Telegram::Message *Telegram::TelegramBot::getMessage() { |
|
|
|
Telegram::Message *Telegram::TelegramBot::getMessage() { |
|
|
@ -181,8 +181,9 @@ void Telegram::TelegramBot::apiRequest(std::string method, std::map<std::string, |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* An API request, posting JSON data |
|
|
|
* An API request, posting JSON data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::string, std::string> parameters) { |
|
|
|
Telegram::Message* Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::string, std::string> parameters) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::stringstream result; // Stores the result of the api call
|
|
|
|
parameters["method"] = method; |
|
|
|
parameters["method"] = method; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
@ -195,6 +196,8 @@ void Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::str |
|
|
|
handle.setOpt(cURLpp::Options::Timeout(60)); |
|
|
|
handle.setOpt(cURLpp::Options::Timeout(60)); |
|
|
|
handle.setOpt(cURLpp::Options::HttpHeader(header)); |
|
|
|
handle.setOpt(cURLpp::Options::HttpHeader(header)); |
|
|
|
handle.setOpt(cURLpp::Options::PostFields(json_encode(parameters))); |
|
|
|
handle.setOpt(cURLpp::Options::PostFields(json_encode(parameters))); |
|
|
|
|
|
|
|
handle.setOpt(cURLpp::Options::WriteStream(&result)); |
|
|
|
|
|
|
|
|
|
|
|
handle.perform(); // Do the curl request
|
|
|
|
handle.perform(); // Do the curl request
|
|
|
|
} |
|
|
|
} |
|
|
|
catch(cURLpp::LogicError &e) { |
|
|
|
catch(cURLpp::LogicError &e) { |
|
|
@ -206,6 +209,12 @@ void Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::str |
|
|
|
catch(std::exception &e) { |
|
|
|
catch(std::exception &e) { |
|
|
|
Log(e.what()); |
|
|
|
Log(e.what()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Json::Reader jreader; |
|
|
|
|
|
|
|
Json::Value obj; |
|
|
|
|
|
|
|
jreader.parse(result.str(), obj); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (new Telegram::Message(obj["result"])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string Telegram::TelegramBot::processCommand(std::string cmd) { |
|
|
|
std::string Telegram::TelegramBot::processCommand(std::string cmd) { |
|
|
|