added telegram api support to send message on ip update

This commit is contained in:
2019-05-08 19:19:42 +02:00
parent 3b7e78193a
commit 846a32ee7e
7 changed files with 162 additions and 65 deletions

View File

@ -3,7 +3,7 @@
//
#include "API.h"
#include "Hashmap.h"
#include "../Hashmap.h"
#include <string>
#include <iostream>

View File

@ -7,7 +7,7 @@
#include <string>
#include "Hashmap.h"
#include "../Hashmap.h"
class API {
public:

10
src/api/TelegramAPI.cpp Normal file
View File

@ -0,0 +1,10 @@
//
// Created by lukas on 08.05.19.
//
#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);
std::cout << "[DEBUG] " <<reply << std::endl;
}

22
src/api/TelegramAPI.h Normal file
View File

@ -0,0 +1,22 @@
//
// Created by lukas on 08.05.19.
//
#ifndef IPREFRESHER_TELEGRAMAPI_H
#define IPREFRESHER_TELEGRAMAPI_H
#include <string>
#include "API.h"
class TelegramAPI : API{
public:
void sendMessage(std::string text);
private:
std::string apikey = "717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4";
std::string chatid = "618154204";
};
#endif //IPREFRESHER_TELEGRAMAPI_H

View File

@ -1,8 +1,9 @@
#include <iostream>
#include <ctime>
#include "API.h"
#include "api/API.h"
#include "Logger.h"
#include "api/TelegramAPI.h"
int main(int argc, char *argv[]) {
@ -57,6 +58,9 @@ int main(int argc, char *argv[]) {
if (dynurepl != "{\"statusCode\":200}") {
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
} else{
TelegramAPI tele;
tele.sendMessage(oldip + " moved to " + ip);
}
logger.safeip(ip);