2019-05-08 19:19:42 +02:00
|
|
|
//
|
|
|
|
// Created by lukas on 08.05.19.
|
|
|
|
//
|
|
|
|
|
2019-08-01 21:19:02 +02:00
|
|
|
#include "api/TelegramAPI.h"
|
2019-05-08 19:19:42 +02:00
|
|
|
|
2020-04-30 19:37:11 +02:00
|
|
|
#include <Logger.h>
|
|
|
|
|
|
|
|
int TelegramAPI::sendMessage(const std::string& text) {
|
2019-05-10 08:30:08 +02:00
|
|
|
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);
|
2020-04-30 19:37:11 +02:00
|
|
|
|
|
|
|
unsigned const long ULONG_MAX = -1;
|
|
|
|
if (reply.find("\"error_code\"") != ULONG_MAX) {
|
|
|
|
Logger::error("failed to refresh the ip (Dynu API)");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
2019-05-08 19:19:42 +02:00
|
|
|
}
|
2019-08-02 22:44:42 +02:00
|
|
|
|
2020-04-30 19:37:11 +02:00
|
|
|
void TelegramAPI::init(const std::string apikey, const std::string chatid) {
|
2019-08-02 22:44:42 +02:00
|
|
|
this->apikey = apikey;
|
|
|
|
this->chatid = chatid;
|
|
|
|
}
|