DynuIPRefresher/src/api/TelegramAPI.cpp
2020-05-08 16:45:27 +02:00

26 lines
675 B
C++

#include "api/TelegramAPI.h"
#include "Logger.h"
#include <climits>
int TelegramAPI::sendMessage(const std::string &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);
if (reply.find("\"error_code\"") != ULONG_MAX) {
Logger::error("failed to refresh the ip (Dynu API)");
return -1;
}
return 1;
}
void TelegramAPI::init(const std::string apikey, const std::string chatid) {
this->apikey = apikey;
this->chatid = chatid;
}