used Hashmap for telegram api request

This commit is contained in:
Lukas-Heiligenbrunner 2019-05-10 08:30:08 +02:00
parent a890cf687e
commit b599626bbf
2 changed files with 18 additions and 9 deletions

View File

@ -33,7 +33,6 @@ API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &ma
std::string readString;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, myurl.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
@ -55,17 +54,21 @@ API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &ma
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, poststring.str().c_str());
} else {
std::string getstring;
for (int i = 0; i < map.size(); i++) {
getstring += map.getKey(i) + "=" + map.getValue(i);
if (i < map.size() - 1) {
getstring += "&";
if (map.size() > 0) {
std::string getstring;
for (int i = 0; i < map.size(); i++) {
getstring += map.getKey(i) + "=" + map.getValue(i);
if (i < map.size() - 1) {
getstring += "&";
}
}
}
myurl += "?" + getstring;
myurl += "?" + getstring;
}
}
curl_easy_setopt(curl, CURLOPT_URL, myurl.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readString);

View File

@ -5,6 +5,12 @@
#include "TelegramAPI.h"
void TelegramAPI::sendMessage(std::string text) {
std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage?chat_id=" + chatid + "&text=" + text);
Hashmap<std::string, std::string> args;
args.add("chat_id", chatid);
args.add("text", text);
std::vector<std::string> headers;
std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers);
std::cout << "[DEBUG] " << reply << std::endl;
}