telegram bot added (working version)

This commit is contained in:
Dmitry Borisenko
2020-11-04 23:48:21 +03:00
parent aec1d50732
commit 2cad740fc6
32 changed files with 294 additions and 173 deletions

35
src/Telegram.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "Telegram.h"
#include "Global.h"
CTBot* myBot{ nullptr };
void telegramInit() {
String token = jsonReadStr(configSetupJson, "telegramApi");
if (!myBot) {
myBot = new CTBot();
}
myBot->setTelegramToken(token);
if (myBot->testConnection()) {
SerialPrint("I", "Telegram", "Connected");
}
else {
SerialPrint("E", "Telegram", "Not connected");
}
}
void handleTelegram() {
TBMessage msg;
static unsigned long prevMillis;
unsigned long currentMillis = millis();
unsigned long difference = currentMillis - prevMillis;
if (difference >= 1000) {
prevMillis = millis();
if (myBot->getNewMessage(msg)) {
Serial.println(msg.text);
myBot->sendMessage(msg.sender.id, msg.text);
}
}
}