mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
telegram bot added (working version)
This commit is contained in:
35
src/Telegram.cpp
Normal file
35
src/Telegram.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user