This commit is contained in:
Dmitry Borisenko
2020-12-02 04:50:29 +03:00
parent e88718ada0
commit 49f11841be
5 changed files with 58 additions and 21 deletions

View File

@@ -25,17 +25,19 @@ void telegramInit() {
void handleTelegram() {
if (telegramInitBeen) {
if (isTelegramEnabled()) {
TBMessage msg;
static unsigned long prevMillis;
unsigned long currentMillis = millis();
unsigned long difference = currentMillis - prevMillis;
if (difference >= 5000) {
prevMillis = millis();
if (myBot->getNewMessage(msg)) {
SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text));
jsonWriteInt(configSetupJson, "chatId", msg.sender.id);
saveConfig();
telegramMsgParse(String(msg.text));
if (isTelegramInputOn()) {
TBMessage msg;
static unsigned long prevMillis;
unsigned long currentMillis = millis();
unsigned long difference = currentMillis - prevMillis;
if (difference >= 10000) {
prevMillis = millis();
if (myBot->getNewMessage(msg)) {
SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text));
jsonWriteInt(configSetupJson, "chatId", msg.sender.id);
saveConfig();
telegramMsgParse(String(msg.text));
}
}
}
}
@@ -76,16 +78,21 @@ void sendTelegramMsg() {
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
}
} else if (type == "2") {
}
else if (type == "2") {
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
}
}
}
bool isTelegramEnabled() {
return jsonReadBool(configSetupJson, "telegonof");
}
bool isTelegramInputOn() {
return jsonReadBool(configSetupJson, "teleginput");
}
String returnListOfParams() {
String cmdStr = readFile(DEVICE_CONFIG_FILE, 4096);

View File

@@ -229,14 +229,23 @@ void web_init() {
//==============================push settings=============================================
if (request->hasArg("telegramApi")) {
jsonWriteStr(configSetupJson, "telegramApi", request->getParam("telegramApi")->value());
//telegramInit();
saveConfig();
request->send(200);
}
if (request->hasArg("chatId")) {
jsonWriteStr(configSetupJson, "chatId", request->getParam("chatId")->value());
saveConfig();
request->send(200);
}
if (request->hasArg("telegonof")) {
bool value = request->getParam("telegonof")->value().toInt();
jsonWriteBool(configSetupJson, "telegonof", value);
//telegramInit();
saveConfig();
request->send(200);
}
if (request->hasArg("teleginput")) {
bool value = request->getParam("teleginput")->value().toInt();
jsonWriteBool(configSetupJson, "teleginput", value);
saveConfig();
request->send(200);
}