From e45aed2da8a1d87107bff56437bab3f321032156 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 2 May 2022 00:22:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B2=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=20=D0=B2=20?= =?UTF-8?q?=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D1=83=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/Telegram/Telegram.cpp | 50 +++++++++++++------------- src/modules/exec/Telegram/items.json | 3 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/modules/exec/Telegram/Telegram.cpp b/src/modules/exec/Telegram/Telegram.cpp index 7d7004ec..6e48d84a 100644 --- a/src/modules/exec/Telegram/Telegram.cpp +++ b/src/modules/exec/Telegram/Telegram.cpp @@ -48,10 +48,12 @@ class Telegram : public IoTItem { String list = returnListOfParams(); _myBot.sendMessage(_chatID, list); SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + "\n" + list); - } else { - //_myBot.sendMessage(_chatID, "ID: " + chipId + ", Name: " + jsonReadStr(configSetupJson, F("name"))); + } else if (msg.indexOf("help") != -1) { _myBot.sendMessage(_chatID, "ID: " + chipId); + _myBot.sendMessage(_chatID, "chatID: " + uint64ToString(_chatID)); _myBot.sendMessage(_chatID, F("Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value")); + } else { + setValue(msg); } } @@ -68,19 +70,17 @@ class Telegram : public IoTItem { jsonRead(parameters, "token", _token); jsonRead(parameters, "autos", _autos); jsonRead(parameters, "receiveMsg", _receiveMsg); + + String tmp; + jsonRead(parameters, "chatID", tmp); + _chatID = atoll(tmp.c_str()); #ifdef ESP32 - _myBot.useDNS(true); + _myBot.useDNS(true); #endif _myBot.setTelegramToken(_token); _myBot.enableUTF8Encoding(true); - if (_myBot.testConnection()) { - SerialPrint("I", F("Telegram"), F("Connected")); - } else { - SerialPrint("E", F("Telegram"), F("Not connected")); - } - SerialPrint("I", F("Telegram"), F("Telegram Init")); } void doByInterval() { @@ -94,24 +94,22 @@ class Telegram : public IoTItem { telegramMsgParse(String(msg.text)); } } - - // if (_ticker && (value.valD > 0 || _unfin) && !_pause) regEvent(value.valD, "Telegram tick"); } IoTValue execute(String command, std::vector ¶m) { - // if (command == "stop") { - // _pause = true; - // } else if (command == "reset") { - // _pause = false; - // value.valD = _initValue; - // if (_initValue) value.valD = value.valD + 1; - // } else if (command == "continue") { - // _pause = false; - // } else if (command == "int") { - // if (param.size()) { - // setInterval(param[0].valD); - // } - // } + if (command == "sendMsg") { + if (param.size()) { + String strTmp; + if (param[0].isDecimal) strTmp = param[0].valD; else strTmp = param[0].valS; + sendTelegramMsg(false, strTmp); + } + } else if (command == "sendOftenMsg") { + if (param.size()) { + String strTmp; + if (param[0].isDecimal) strTmp = param[0].valD; else strTmp = param[0].valS; + sendTelegramMsg(true, strTmp); + } + } return {}; } @@ -129,7 +127,9 @@ class Telegram : public IoTItem { } } - ~Telegram() {}; + ~Telegram() { + + }; }; void* getAPI_Telegram(String subtype, String param) { diff --git a/src/modules/exec/Telegram/items.json b/src/modules/exec/Telegram/items.json index 2c8082c3..d083db83 100644 --- a/src/modules/exec/Telegram/items.json +++ b/src/modules/exec/Telegram/items.json @@ -12,6 +12,7 @@ "token": "", "autos": 1, - "receiveMsg": 0 + "receiveMsg": 0, + "chatID": "" } ] \ No newline at end of file