used Hashmap for telegram api request
This commit is contained in:
parent
a890cf687e
commit
b599626bbf
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user