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

@@ -15,6 +15,7 @@
"scen": "1",
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
"telegonof": "0",
"teleginput":"0",
"weblogin": "admin",
"webpass": "admin",
"snaUdp": "0",

View File

@@ -21,30 +21,49 @@
},
{
"type": "checkbox",
"name": "tel",
"name": "telegonof",
"title": "Включить телеграм",
"action": "/set?telegonof=[[tel]]",
"action": "/set?telegonof=[[telegonof]]",
"state": "{{telegonof}}"
},
{
"type": "hr"
},
{
"type": "checkbox",
"name": "teleginput",
"title": "Включить прием входящих сообщений",
"action": "/set?teleginput=[[teleginput]]",
"state": "{{teleginput}}"
},
{
"type": "hr"
},
{
"type": "h4",
"style": "width:40%;float:left;",
"title": "Telegram API token:"
"title": "Telegram chat ID"
},
{
"type": "input",
"title": "",
"name": "chatId-arg",
"state": "{{chatId}}"
},
{
"type": "h4",
"title": "Telegram API token"
},
{
"type": "input",
"title": "",
"name": "telegramApi-arg",
"style": "width:60%;float:right",
"state": "{{telegramApi}}"
},
{
"type": "button",
"title": "{{ButSave}}",
"action": "set?telegramApi=[[telegramApi-arg]]",
"action": "set?telegramApi=[[telegramApi-arg]]&chatId=[[chatId-arg]]",
"class": "btn btn-block btn-default",
"style": "width:100%;display:inline"
},

View File

@@ -5,5 +5,6 @@ extern void sendTelegramMsg();
extern void telegramInit();
extern void handleTelegram();
extern bool isTelegramEnabled();
extern bool isTelegramInputOn();
extern void telegramMsgParse(String msg);
extern String returnListOfParams();

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);
}