mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
Telegram
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
"scen": "1",
|
"scen": "1",
|
||||||
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
|
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
|
||||||
"telegonof": "0",
|
"telegonof": "0",
|
||||||
|
"teleginput":"0",
|
||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"snaUdp": "0",
|
"snaUdp": "0",
|
||||||
|
|||||||
@@ -21,30 +21,49 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"name": "tel",
|
"name": "telegonof",
|
||||||
"title": "Включить телеграм",
|
"title": "Включить телеграм",
|
||||||
"action": "/set?telegonof=[[tel]]",
|
"action": "/set?telegonof=[[telegonof]]",
|
||||||
"state": "{{telegonof}}"
|
"state": "{{telegonof}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "checkbox",
|
||||||
|
"name": "teleginput",
|
||||||
|
"title": "Включить прием входящих сообщений",
|
||||||
|
"action": "/set?teleginput=[[teleginput]]",
|
||||||
|
"state": "{{teleginput}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hr"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"style": "width:40%;float:left;",
|
"title": "Telegram chat ID"
|
||||||
"title": "Telegram API token:"
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"title": "",
|
||||||
|
"name": "chatId-arg",
|
||||||
|
"state": "{{chatId}}"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "h4",
|
||||||
|
"title": "Telegram API token"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"title": "",
|
"title": "",
|
||||||
"name": "telegramApi-arg",
|
"name": "telegramApi-arg",
|
||||||
"style": "width:60%;float:right",
|
|
||||||
"state": "{{telegramApi}}"
|
"state": "{{telegramApi}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "button",
|
"type": "button",
|
||||||
"title": "{{ButSave}}",
|
"title": "{{ButSave}}",
|
||||||
"action": "set?telegramApi=[[telegramApi-arg]]",
|
"action": "set?telegramApi=[[telegramApi-arg]]&chatId=[[chatId-arg]]",
|
||||||
"class": "btn btn-block btn-default",
|
"class": "btn btn-block btn-default",
|
||||||
"style": "width:100%;display:inline"
|
"style": "width:100%;display:inline"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ extern void sendTelegramMsg();
|
|||||||
extern void telegramInit();
|
extern void telegramInit();
|
||||||
extern void handleTelegram();
|
extern void handleTelegram();
|
||||||
extern bool isTelegramEnabled();
|
extern bool isTelegramEnabled();
|
||||||
|
extern bool isTelegramInputOn();
|
||||||
extern void telegramMsgParse(String msg);
|
extern void telegramMsgParse(String msg);
|
||||||
extern String returnListOfParams();
|
extern String returnListOfParams();
|
||||||
@@ -25,11 +25,12 @@ void telegramInit() {
|
|||||||
void handleTelegram() {
|
void handleTelegram() {
|
||||||
if (telegramInitBeen) {
|
if (telegramInitBeen) {
|
||||||
if (isTelegramEnabled()) {
|
if (isTelegramEnabled()) {
|
||||||
|
if (isTelegramInputOn()) {
|
||||||
TBMessage msg;
|
TBMessage msg;
|
||||||
static unsigned long prevMillis;
|
static unsigned long prevMillis;
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
unsigned long difference = currentMillis - prevMillis;
|
unsigned long difference = currentMillis - prevMillis;
|
||||||
if (difference >= 5000) {
|
if (difference >= 10000) {
|
||||||
prevMillis = millis();
|
prevMillis = millis();
|
||||||
if (myBot->getNewMessage(msg)) {
|
if (myBot->getNewMessage(msg)) {
|
||||||
SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text));
|
SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text));
|
||||||
@@ -40,6 +41,7 @@ void handleTelegram() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void telegramMsgParse(String msg) {
|
void telegramMsgParse(String msg) {
|
||||||
@@ -76,7 +78,8 @@ void sendTelegramMsg() {
|
|||||||
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
||||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + 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);
|
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
||||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
|
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
|
||||||
}
|
}
|
||||||
@@ -86,6 +89,10 @@ bool isTelegramEnabled() {
|
|||||||
return jsonReadBool(configSetupJson, "telegonof");
|
return jsonReadBool(configSetupJson, "telegonof");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTelegramInputOn() {
|
||||||
|
return jsonReadBool(configSetupJson, "teleginput");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
String returnListOfParams() {
|
String returnListOfParams() {
|
||||||
String cmdStr = readFile(DEVICE_CONFIG_FILE, 4096);
|
String cmdStr = readFile(DEVICE_CONFIG_FILE, 4096);
|
||||||
|
|||||||
13
src/Web.cpp
13
src/Web.cpp
@@ -229,14 +229,23 @@ void web_init() {
|
|||||||
//==============================push settings=============================================
|
//==============================push settings=============================================
|
||||||
if (request->hasArg("telegramApi")) {
|
if (request->hasArg("telegramApi")) {
|
||||||
jsonWriteStr(configSetupJson, "telegramApi", request->getParam("telegramApi")->value());
|
jsonWriteStr(configSetupJson, "telegramApi", request->getParam("telegramApi")->value());
|
||||||
//telegramInit();
|
saveConfig();
|
||||||
|
request->send(200);
|
||||||
|
}
|
||||||
|
if (request->hasArg("chatId")) {
|
||||||
|
jsonWriteStr(configSetupJson, "chatId", request->getParam("chatId")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
if (request->hasArg("telegonof")) {
|
if (request->hasArg("telegonof")) {
|
||||||
bool value = request->getParam("telegonof")->value().toInt();
|
bool value = request->getParam("telegonof")->value().toInt();
|
||||||
jsonWriteBool(configSetupJson, "telegonof", value);
|
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();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user