Добавлем в телеграм обработку произвольных команд в сценарии и отправку сообщений

This commit is contained in:
2022-05-02 00:22:28 +03:00
parent 8bbea0c2cb
commit e45aed2da8
2 changed files with 27 additions and 26 deletions

View File

@@ -48,10 +48,12 @@ class Telegram : public IoTItem {
String list = returnListOfParams(); String list = returnListOfParams();
_myBot.sendMessage(_chatID, list); _myBot.sendMessage(_chatID, list);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + "\n" + list); SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + "\n" + list);
} else { } else if (msg.indexOf("help") != -1) {
//_myBot.sendMessage(_chatID, "ID: " + chipId + ", Name: " + jsonReadStr(configSetupJson, F("name")));
_myBot.sendMessage(_chatID, "ID: " + chipId); _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")); _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);
} }
} }
@@ -69,18 +71,16 @@ class Telegram : public IoTItem {
jsonRead(parameters, "autos", _autos); jsonRead(parameters, "autos", _autos);
jsonRead(parameters, "receiveMsg", _receiveMsg); jsonRead(parameters, "receiveMsg", _receiveMsg);
String tmp;
jsonRead(parameters, "chatID", tmp);
_chatID = atoll(tmp.c_str());
#ifdef ESP32 #ifdef ESP32
_myBot.useDNS(true); _myBot.useDNS(true);
#endif #endif
_myBot.setTelegramToken(_token); _myBot.setTelegramToken(_token);
_myBot.enableUTF8Encoding(true); _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() { void doByInterval() {
@@ -94,24 +94,22 @@ class Telegram : public IoTItem {
telegramMsgParse(String(msg.text)); telegramMsgParse(String(msg.text));
} }
} }
// if (_ticker && (value.valD > 0 || _unfin) && !_pause) regEvent(value.valD, "Telegram tick");
} }
IoTValue execute(String command, std::vector<IoTValue> &param) { IoTValue execute(String command, std::vector<IoTValue> &param) {
// if (command == "stop") { if (command == "sendMsg") {
// _pause = true; if (param.size()) {
// } else if (command == "reset") { String strTmp;
// _pause = false; if (param[0].isDecimal) strTmp = param[0].valD; else strTmp = param[0].valS;
// value.valD = _initValue; sendTelegramMsg(false, strTmp);
// if (_initValue) value.valD = value.valD + 1; }
// } else if (command == "continue") { } else if (command == "sendOftenMsg") {
// _pause = false; if (param.size()) {
// } else if (command == "int") { String strTmp;
// if (param.size()) { if (param[0].isDecimal) strTmp = param[0].valD; else strTmp = param[0].valS;
// setInterval(param[0].valD); sendTelegramMsg(true, strTmp);
// } }
// } }
return {}; return {};
} }
@@ -129,7 +127,9 @@ class Telegram : public IoTItem {
} }
} }
~Telegram() {}; ~Telegram() {
};
}; };
void* getAPI_Telegram(String subtype, String param) { void* getAPI_Telegram(String subtype, String param) {

View File

@@ -12,6 +12,7 @@
"token": "", "token": "",
"autos": 1, "autos": 1,
"receiveMsg": 0 "receiveMsg": 0,
"chatID": ""
} }
] ]