mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Telegram Button
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
// #include "esp_camera.h"
|
// #include "esp_camera.h"
|
||||||
|
|
||||||
#include <FastBot.h>
|
#include <FastBot.h>
|
||||||
#include <vector>
|
#include <map>
|
||||||
|
|
||||||
// FastBot _myBot;
|
// FastBot _myBot;
|
||||||
FastBot *_myBot = nullptr;
|
FastBot *_myBot = nullptr;
|
||||||
@@ -28,6 +28,17 @@ String _chatID;
|
|||||||
bool _autos;
|
bool _autos;
|
||||||
bool _initSD;
|
bool _initSD;
|
||||||
|
|
||||||
|
struct ButtonMenu
|
||||||
|
{
|
||||||
|
String message = "";
|
||||||
|
String getId = "";
|
||||||
|
String setId = "";
|
||||||
|
String value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
std::map<String, ButtonMenu *> mapBtnMenu; // <btnName, ID>
|
||||||
|
std::map<String, ButtonMenu *> mapBtnInline; // <btnName, ID>
|
||||||
|
|
||||||
class Telegram_v2 : public IoTItem
|
class Telegram_v2 : public IoTItem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -43,6 +54,7 @@ public:
|
|||||||
jsonRead(parameters, "receiveMsg", _receiveMsg);
|
jsonRead(parameters, "receiveMsg", _receiveMsg);
|
||||||
jsonRead(parameters, "chatID", _chatID);
|
jsonRead(parameters, "chatID", _chatID);
|
||||||
instanceBot();
|
instanceBot();
|
||||||
|
// _myBot->setTextMode(FB_MARKDOWN);
|
||||||
_myBot->attach(telegramMsgParse);
|
_myBot->attach(telegramMsgParse);
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@@ -69,9 +81,13 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
//=============++====== Обработка команд сценария =============================
|
||||||
|
//=============================================================================
|
||||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||||
{
|
{
|
||||||
if (!isNetworkActive()) return {};
|
if (!isNetworkActive())
|
||||||
|
return {};
|
||||||
if (command == "sendMsg")
|
if (command == "sendMsg")
|
||||||
{
|
{
|
||||||
if (param.size())
|
if (param.size())
|
||||||
@@ -108,9 +124,14 @@ public:
|
|||||||
_myBot->sendMessage(strTmp, _chatID);
|
_myBot->sendMessage(strTmp, _chatID);
|
||||||
_myBot->pinMessage(_myBot->lastBotMsg());
|
_myBot->pinMessage(_myBot->lastBotMsg());
|
||||||
|
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ",pin msg: " + strTmp);
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", pin msg: " + strTmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (command == "unpinAllMsg")
|
||||||
|
{
|
||||||
|
_myBot->unpinAll(_chatID);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", unpin all message");
|
||||||
|
}
|
||||||
else if (command == "editMsg")
|
else if (command == "editMsg")
|
||||||
{
|
{
|
||||||
if (param.size())
|
if (param.size())
|
||||||
@@ -121,7 +142,7 @@ public:
|
|||||||
else
|
else
|
||||||
strTmp = param[0].valS;
|
strTmp = param[0].valS;
|
||||||
_myBot->editMessage(_myBot->lastBotMsg(), strTmp);
|
_myBot->editMessage(_myBot->lastBotMsg(), strTmp);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ",edit msg: " + strTmp);
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", edit msg: " + strTmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "sendFile")
|
else if (command == "sendFile")
|
||||||
@@ -139,10 +160,9 @@ public:
|
|||||||
// selectToMarkerLast(msg.text, "_")
|
// selectToMarkerLast(msg.text, "_")
|
||||||
uint8_t res = _myBot->sendFile(file, (FB_FileType)param[1].valD, selectToMarkerLast(param[0].valS, "/"), _chatID);
|
uint8_t res = _myBot->sendFile(file, (FB_FileType)param[1].valD, selectToMarkerLast(param[0].valS, "/"), _chatID);
|
||||||
file.close();
|
file.close();
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", sendFile: " + param[0].valS + " res: " + String(res));
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", sendFile: " + param[0].valS + " res: " + String(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == "editFile")
|
else if (command == "editFile")
|
||||||
{
|
{
|
||||||
if (param.size() && !param[0].isDecimal)
|
if (param.size() && !param[0].isDecimal)
|
||||||
@@ -158,28 +178,297 @@ public:
|
|||||||
// selectToMarkerLast(msg.text, "_")
|
// selectToMarkerLast(msg.text, "_")
|
||||||
uint8_t res = _myBot->editFile(file, (FB_FileType)param[1].valD, selectToMarkerLast(param[0].valS, "/"), _myBot->lastBotMsg(), _chatID);
|
uint8_t res = _myBot->editFile(file, (FB_FileType)param[1].valD, selectToMarkerLast(param[0].valS, "/"), _myBot->lastBotMsg(), _chatID);
|
||||||
file.close();
|
file.close();
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", editFile: " + param[0].valS + " res: " + String(res));
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", editFile: " + param[0].valS + " res: " + String(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (command == "btnMenu")
|
||||||
|
{
|
||||||
|
mapBtnMenu[param[0].valS] = new ButtonMenu;
|
||||||
|
if (param.size() == 3) // btnMenu("Name", message, getId);
|
||||||
|
{
|
||||||
|
// if (IoTItems.find(param[2].valS) != IoTItems.end())
|
||||||
|
// {
|
||||||
|
mapBtnMenu[param[0].valS]->message = param[1].valS;
|
||||||
|
mapBtnMenu[param[0].valS]->getId = param[2].valS;
|
||||||
|
// mapBtnMenu[param[0].valS] = btn;
|
||||||
|
SerialPrint("i", F("Telegram"), "add button menu: " + param[0].valS + ", get id: " + param[2].valS);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else if (param.size() == 5) // btnMenu("Name", message, getId, setId, value);
|
||||||
|
{
|
||||||
|
// if (IoTItems.find(param[2].valS) != IoTItems.end())
|
||||||
|
// {
|
||||||
|
mapBtnMenu[param[0].valS]->message = param[1].valS;
|
||||||
|
mapBtnMenu[param[0].valS]->getId = param[2].valS;
|
||||||
|
mapBtnMenu[param[0].valS]->setId = param[3].valS;
|
||||||
|
mapBtnMenu[param[0].valS]->value = param[4].valS;
|
||||||
|
// mapBtnMenu[param[0].valS] = btn;
|
||||||
|
SerialPrint("i", F("Telegram"), "add button menu: " + param[0].valS + ",get id: " + param[2].valS + ",set id: " + param[3].valS + "=" + param[4].valS);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command == "showMenu")
|
||||||
|
{
|
||||||
|
String out;
|
||||||
|
// перебирвем весь мап и строим меню
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
for (auto it = mapBtnMenu.begin(); it != mapBtnMenu.end(); it++)
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
if (cnt % 2 == 0)
|
||||||
|
{
|
||||||
|
out += " \t " + it->first;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (it == mapBtnMenu.begin())
|
||||||
|
out = it->first;
|
||||||
|
else
|
||||||
|
out += " \n " + it->first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_myBot->showMenuText("Menu", out, true);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", show menu: \n" + out);
|
||||||
|
}
|
||||||
|
else if (command == "btnInline")
|
||||||
|
{
|
||||||
|
mapBtnInline[param[0].valS] = new ButtonMenu;
|
||||||
|
if (param.size() == 3) // btnMenu("Name", message, getId);
|
||||||
|
{
|
||||||
|
// if (IoTItems.find(param[2].valS) != IoTItems.end())
|
||||||
|
// {
|
||||||
|
mapBtnInline[param[0].valS]->message = param[1].valS;
|
||||||
|
mapBtnInline[param[0].valS]->getId = param[2].valS;
|
||||||
|
// mapBtnMenu[param[0].valS] = btn;
|
||||||
|
SerialPrint("i", "Telegram", "add button inline: " + param[0].valS + ", get id: " + param[2].valS);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else if (param.size() == 5) // btnMenu("Name", message, getId, setId, value);
|
||||||
|
{
|
||||||
|
// if (IoTItems.find(param[2].valS) != IoTItems.end())
|
||||||
|
// {
|
||||||
|
mapBtnInline[param[0].valS]->message = param[1].valS;
|
||||||
|
mapBtnInline[param[0].valS]->getId = param[2].valS;
|
||||||
|
mapBtnInline[param[0].valS]->setId = param[3].valS;
|
||||||
|
mapBtnInline[param[0].valS]->value = param[4].valS;
|
||||||
|
// mapBtnMenu[param[0].valS] = btn;
|
||||||
|
SerialPrint("i", "Telegram", "add button inline: " + param[0].valS + ",get id: " + param[2].valS + ",set id: " + param[3].valS + "=" + param[4].valS);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command == "showInline")
|
||||||
|
{
|
||||||
|
String out;
|
||||||
|
// перебирвем весь мап и строим меню
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
for (auto it = mapBtnInline.begin(); it != mapBtnInline.end(); it++)
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
if (cnt % 2 == 0)
|
||||||
|
{
|
||||||
|
out += " \t " + it->first;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (it == mapBtnInline.begin())
|
||||||
|
out = it->first;
|
||||||
|
else
|
||||||
|
out += " \n " + it->first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_myBot->inlineMenu("inline_menu", out);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", show inline: \n" + out);
|
||||||
|
}
|
||||||
|
else if (command == "clearInline")
|
||||||
|
{
|
||||||
|
clearMapMenuInline();
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", clear inline menu ");
|
||||||
|
}
|
||||||
|
else if (command == "clearMenu")
|
||||||
|
{
|
||||||
|
clearMapMenu();
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", clear menu ");
|
||||||
|
}
|
||||||
|
else if (command == "closeMenu")
|
||||||
|
{
|
||||||
|
_myBot->closeMenu();
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", closeMenu ");
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
//=================== Обработка сообщений из чата =============================
|
||||||
|
//=============================================================================
|
||||||
void static telegramMsgParse(FB_msg &msg)
|
void static telegramMsgParse(FB_msg &msg)
|
||||||
{
|
{
|
||||||
// FB_msg msg;
|
// FB_msg msg;
|
||||||
SerialPrint("->", F("Telegram"), "chat ID: " + msg.chatID + ", msg: " + msg.text);
|
SerialPrint("i", F("Telegram"), "chat ID: " + msg.chatID + ", msg: " + msg.text);
|
||||||
// _myBot->setChatID(_chatID);
|
// _myBot->setChatID(_chatID);
|
||||||
if (_autos)
|
if (_autos)
|
||||||
{
|
{
|
||||||
_chatID = msg.chatID;
|
_chatID = msg.chatID;
|
||||||
}
|
}
|
||||||
if (msg.text.indexOf("set") != -1)
|
// -------------- Обработка кнопок меню созданного в сценарии --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
if (auto search = mapBtnMenu.find(msg.text); search != mapBtnMenu.end())
|
||||||
|
{
|
||||||
|
String outMsg;
|
||||||
|
outMsg = mapBtnMenu[msg.text]->message;
|
||||||
|
if (mapBtnMenu[msg.text]->getId != "")
|
||||||
|
{
|
||||||
|
IoTItem *item = findIoTItem(mapBtnMenu[msg.text]->getId);
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
outMsg += ": " + item->getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mapBtnMenu[msg.text]->setId != "")
|
||||||
|
{
|
||||||
|
//outMsg += ", " + mapBtnMenu[msg.text]->setId + "=" + mapBtnMenu[msg.text]->value;
|
||||||
|
generateOrder(mapBtnMenu[msg.text]->setId, mapBtnMenu[msg.text]->value);
|
||||||
|
}
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(outMsg));
|
||||||
|
_myBot->sendMessage(outMsg, _chatID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------- Обработка нажатия на пользовательском инлайн меню --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("inline_menu") != -1)
|
||||||
|
{
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", data: " + String(msg.data));
|
||||||
|
if (auto search = mapBtnInline.find(msg.data); search != mapBtnInline.end())
|
||||||
|
{
|
||||||
|
|
||||||
|
String outMsg;
|
||||||
|
outMsg = mapBtnInline[msg.data]->message;
|
||||||
|
if (mapBtnInline[msg.data]->getId != "")
|
||||||
|
{
|
||||||
|
IoTItem *item = findIoTItem(mapBtnInline[msg.data]->getId);
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
outMsg += ": " + item->getValue();
|
||||||
|
//SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(msg.data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mapBtnInline[msg.data]->setId != "")
|
||||||
|
{
|
||||||
|
//outMsg += ", " + mapBtnInline[msg.data]->setId + "=" + mapBtnInline[msg.data]->value;
|
||||||
|
generateOrder(mapBtnInline[msg.data]->setId, mapBtnInline[msg.data]->value);
|
||||||
|
}
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(outMsg));
|
||||||
|
_myBot->sendMessage(outMsg, _chatID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// -------------- Вызов (повторный вызов) меню созданного в сценарии --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("menu") != -1)
|
||||||
|
{
|
||||||
|
String out;
|
||||||
|
// перебирвем весь мап и строим меню
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
for (auto it = mapBtnMenu.begin(); it != mapBtnMenu.end(); it++)
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
if (cnt % 2 == 0)
|
||||||
|
{
|
||||||
|
out += " \t " + it->first;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (it == mapBtnMenu.begin())
|
||||||
|
out = it->first;
|
||||||
|
else
|
||||||
|
out += " \n " + it->first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_myBot->showMenuText("Menu", out, true);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", show menu: \n" + out);
|
||||||
|
}
|
||||||
|
// -------------- вывод нижнего меню всех юнитов --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("allMenu") != -1)
|
||||||
|
{
|
||||||
|
// String list = returnListOfParams();
|
||||||
|
String out;
|
||||||
|
// std::vector<float> vctr;
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
||||||
|
{
|
||||||
|
if ((*it)->iAmLocal)
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
if (cnt % 2 == 0)
|
||||||
|
{
|
||||||
|
out += " \t get_" + (*it)->getID();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (it == IoTItems.begin())
|
||||||
|
out = "get_" + (*it)->getID();
|
||||||
|
else
|
||||||
|
out += " \n get_" + (*it)->getID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_myBot->showMenuText("select Id", out, true);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + "\n" + out);
|
||||||
|
// _myBot->sendMessage(CharPlot<LINE_X2>(&vctr[0], vctr.size(), 5), _chatID);
|
||||||
|
// SerialPrint("<-", F("Telegram"), CharPlot<LINE_X2>(&vctr[0], vctr.size(), 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------- Обработка нажатия в инлайн меню all (всех юнитов) --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("all_inline") != -1 && msg.data.indexOf("get") != -1)
|
||||||
|
{
|
||||||
|
String out = deleteBeforeDelimiter(msg.data, "_");
|
||||||
|
IoTItem *item = findIoTItem(out);
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
_myBot->sendMessage(item->getID() + ": " + item->getValue(), _chatID);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// -------------- вывод инлайн меню всех юнитов --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("all") != -1)
|
||||||
|
{
|
||||||
|
// String list = returnListOfParams();
|
||||||
|
String out;
|
||||||
|
// std::vector<float> vctr;
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
||||||
|
{
|
||||||
|
if ((*it)->iAmLocal)
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
if (cnt % 2 == 0)
|
||||||
|
{
|
||||||
|
out += " \t get_" + (*it)->getID();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (it == IoTItems.begin())
|
||||||
|
out = "get_" + (*it)->getID();
|
||||||
|
else
|
||||||
|
out += " \n get_" + (*it)->getID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_myBot->inlineMenu("all_inline", out);
|
||||||
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + "\n" + out);
|
||||||
|
}
|
||||||
|
// -------------- обработка команды /set_ID_VALUE --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
else if (msg.text.indexOf("set") != -1)
|
||||||
{
|
{
|
||||||
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
||||||
generateOrder(selectToMarker(msg.text, "_"), selectToMarkerLast(msg.text, "_"));
|
generateOrder(selectToMarker(msg.text, "_"), selectToMarkerLast(msg.text, "_"));
|
||||||
_myBot->replyMessage("order done", msg.messageID, _chatID);
|
_myBot->replyMessage("order done", msg.messageID, _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(msg.text));
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(msg.text));
|
||||||
}
|
}
|
||||||
|
// -------------- обработка команды /get_ID --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
else if (msg.text.indexOf("get") != -1)
|
else if (msg.text.indexOf("get") != -1)
|
||||||
{
|
{
|
||||||
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
||||||
@@ -187,41 +476,15 @@ public:
|
|||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
_myBot->replyMessage(item->getValue(), msg.messageID, _chatID);
|
_myBot->replyMessage(item->getValue(), msg.messageID, _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(msg.text));
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + String(msg.text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// -------------- обработка запроса пользователя на скачивание файла --------------
|
||||||
else if (msg.text.indexOf("all") != -1)
|
// -------------------------------------------------------------------------
|
||||||
{
|
|
||||||
// String list = returnListOfParams();
|
|
||||||
String out;
|
|
||||||
std::vector<float> vctr;
|
|
||||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
|
||||||
{
|
|
||||||
if ((*it)->iAmLocal)
|
|
||||||
{
|
|
||||||
if (it == IoTItems.begin())
|
|
||||||
{
|
|
||||||
out = "get_" + (*it)->getID();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out = out + " \n " + "get_" + (*it)->getID();
|
|
||||||
}
|
|
||||||
vctr.push_back(atoff((*it)->getValue().c_str()));
|
|
||||||
// _myBot->sendMessage((*it)->getID() + ": " + (*it)->getValue(), _chatID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_myBot->showMenuText("select Id", out, true);
|
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + "\n" + out);
|
|
||||||
// _myBot->sendMessage(CharPlot<LINE_X2>(&vctr[0], vctr.size(), 5), _chatID);
|
|
||||||
// SerialPrint("<-", F("Telegram"), CharPlot<LINE_X2>(&vctr[0], vctr.size(), 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (msg.text.indexOf("file") != -1 && msg.chatID == _chatID)
|
else if (msg.text.indexOf("file") != -1 && msg.chatID == _chatID)
|
||||||
{
|
{
|
||||||
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
msg.text = deleteBeforeDelimiter(msg.text, "_");
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", get file: " + String(msg.text));
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", get file: " + String(msg.text));
|
||||||
auto file = FileFS.open(selectToMarker(msg.text, "_"), FILE_READ); // /test.png
|
auto file = FileFS.open(selectToMarker(msg.text, "_"), FILE_READ); // /test.png
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
@@ -232,6 +495,8 @@ public:
|
|||||||
_myBot->sendFile(file, (FB_FileType)type, selectToMarker(msg.text, "_"), _chatID);
|
_myBot->sendFile(file, (FB_FileType)type, selectToMarker(msg.text, "_"), _chatID);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
// -------------- обработка файлов загруженных пользователем --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
else if (msg.isFile)
|
else if (msg.isFile)
|
||||||
{
|
{
|
||||||
if (msg.text.indexOf("download") != -1 && msg.chatID == _chatID)
|
if (msg.text.indexOf("download") != -1 && msg.chatID == _chatID)
|
||||||
@@ -240,32 +505,41 @@ public:
|
|||||||
}
|
}
|
||||||
else if (msg.text.indexOf("nextion") != -1 && msg.chatID == _chatID)
|
else if (msg.text.indexOf("nextion") != -1 && msg.chatID == _chatID)
|
||||||
{
|
{
|
||||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
||||||
if ((*it)->getSubtype() == "NextionUpload") {
|
{
|
||||||
(*it)->uploadNextionTlgrm(msg.fileUrl);
|
if ((*it)->getSubtype() == "NextionUpload" || (*it)->getSubtype() == "Nextion")
|
||||||
|
{
|
||||||
|
(*it)->uploadNextionTlgrm(msg.fileUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// -------------- обработка остальных команд --------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
else if (msg.text.indexOf("help") != -1)
|
else if (msg.text.indexOf("help") != -1)
|
||||||
{
|
{
|
||||||
_myBot->sendMessage("ID: " + chipId, _chatID);
|
_myBot->sendMessage("ID: " + chipId, _chatID);
|
||||||
_myBot->sendMessage("chatID: " + _chatID, _chatID);
|
_myBot->sendMessage("chatID: " + _chatID, _chatID);
|
||||||
_myBot->sendMessage(F("Wrong order, use /all to get all values, /get_id to get value, /set_id_value to set value, or /file_name_type or send file msg=download"), _chatID);
|
_myBot->sendMessage("Command: /help - this text \n /all - inline menu get all values \n /allMenu - bottom menu get all values \n /menu - bottom USER menu from scenario \n /get_id - get value by ID \n /set_id_value - set value in ID \n /file_name_type - take file from esp \n /file_type - support file type \n send file and write download - \"download\" file to esp \n send tft file and write \"nextion\" - flash file.tft to Nextion", _chatID);
|
||||||
|
}
|
||||||
|
else if (msg.text.indexOf("file_type") != -1)
|
||||||
|
{
|
||||||
|
_myBot->sendMessage("Support file type download: \n 0-foto \n 1-audio \n 2-doc \n 3-video \n 4-gif \n 5-voice", _chatID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// setValue(msg.text);
|
_myBot->sendMessage("Wrong order, use /help", _chatID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendTelegramMsg(bool often, String msg)
|
void sendTelegramMsg(bool often, String msg)
|
||||||
{
|
{
|
||||||
if (!isNetworkActive()) return;
|
if (!isNetworkActive())
|
||||||
|
return;
|
||||||
if (often)
|
if (often)
|
||||||
{
|
{
|
||||||
_myBot->sendMessage(msg, _chatID);
|
_myBot->sendMessage(msg, _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -273,23 +547,25 @@ public:
|
|||||||
{
|
{
|
||||||
_prevMsg = msg;
|
_prevMsg = msg;
|
||||||
_myBot->sendMessage(msg, _chatID);
|
_myBot->sendMessage(msg, _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendFoto(uint8_t *buf, uint32_t length, const String &name)
|
void sendFoto(uint8_t *buf, uint32_t length, const String &name)
|
||||||
{
|
{
|
||||||
if (!isNetworkActive()) return;
|
if (!isNetworkActive())
|
||||||
|
return;
|
||||||
_myBot->sendFile(buf, length, FB_PHOTO, name, _chatID);
|
_myBot->sendFile(buf, length, FB_PHOTO, name, _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", send foto from esp-cam");
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", send foto from esp-cam");
|
||||||
}
|
}
|
||||||
|
|
||||||
void editFoto(uint8_t *buf, uint32_t length, const String &name)
|
void editFoto(uint8_t *buf, uint32_t length, const String &name)
|
||||||
{
|
{
|
||||||
if (!isNetworkActive()) return;
|
if (!isNetworkActive())
|
||||||
|
return;
|
||||||
_myBot->editFile(buf, length, FB_PHOTO, name, _myBot->lastBotMsg(), _chatID);
|
_myBot->editFile(buf, length, FB_PHOTO, name, _myBot->lastBotMsg(), _chatID);
|
||||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", edit foto from esp-cam");
|
SerialPrint("i", F("Telegram"), "chat ID: " + _chatID + ", edit foto from esp-cam");
|
||||||
}
|
}
|
||||||
|
|
||||||
int static downloadFile(FB_msg &msg)
|
int static downloadFile(FB_msg &msg)
|
||||||
@@ -325,7 +601,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SerialPrint("<-", F("Telegram"), "download from: " + _chatID + ", file: " + msg.fileName + " size = " + String(_size) + " byte");
|
SerialPrint("i", F("Telegram"), "download from: " + _chatID + ", file: " + msg.fileName + " size = " + String(_size) + " byte");
|
||||||
_myBot->sendMessage("Download Ok, size = " + String(_size) + " byte", _chatID);
|
_myBot->sendMessage("Download Ok, size = " + String(_size) + " byte", _chatID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,9 +617,31 @@ public:
|
|||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
void clearMapMenu()
|
||||||
|
{
|
||||||
|
for (auto it = mapBtnMenu.begin(); it != mapBtnMenu.end(); it++)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
mapBtnMenu.clear();
|
||||||
|
for (auto it = mapBtnInline.begin(); it != mapBtnInline.end(); it++)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
mapBtnInline.clear();
|
||||||
|
}
|
||||||
|
void clearMapMenuInline()
|
||||||
|
{
|
||||||
|
for (auto it = mapBtnInline.begin(); it != mapBtnInline.end(); it++)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
mapBtnInline.clear();
|
||||||
|
}
|
||||||
~Telegram_v2()
|
~Telegram_v2()
|
||||||
{
|
{
|
||||||
|
clearMapMenu();
|
||||||
|
clearMapMenuInline();
|
||||||
tlgrmItem = nullptr;
|
tlgrmItem = nullptr;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
"token": "",
|
"token": "",
|
||||||
"autos": 1,
|
"autos": 1,
|
||||||
"receiveMsg": 0,
|
"receiveMsg": 1,
|
||||||
"chatID": ""
|
"chatID": ""
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"authorGit": "https://github.com/Mit4el",
|
"authorGit": "https://github.com/Mit4el",
|
||||||
"specialThanks": "",
|
"specialThanks": "",
|
||||||
"moduleName": "Telegram_v2",
|
"moduleName": "Telegram_v2",
|
||||||
"moduleVersion": "1.0",
|
"moduleVersion": "3.0",
|
||||||
"usedRam": {
|
"usedRam": {
|
||||||
"esp32_4mb": 37,
|
"esp32_4mb": 37,
|
||||||
"esp8266_4mb": 37
|
"esp8266_4mb": 37
|
||||||
@@ -45,14 +45,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sendOftenMsg",
|
"name": "sendOftenMsg",
|
||||||
"descr": "Отправить сообщение в любом случае, даж если отправляли такое ранее.",
|
"descr": "Отправить сообщение в любом случае, даже если отправляли такое ранее.",
|
||||||
"params": ["Сообщение, может быть строкой, числом или ИД другого элемента для получения значения"]
|
"params": ["Сообщение, может быть строкой, числом или ИД другого элемента для получения значения"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sendPinMsg",
|
"name": "sendPinMsg",
|
||||||
"descr": "Отправить закрепленное сообщение в любом случае, даж если отправляли такое ранее.",
|
"descr": "Отправить закрепленное сообщение в любом случае, даже если отправляли такое ранее.",
|
||||||
"params": ["Сообщение, может быть строкой, числом или ИД другого элемента для получения значения"]
|
"params": ["Сообщение, может быть строкой, числом или ИД другого элемента для получения значения"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "unpinAllMsg",
|
||||||
|
"descr": "Открепить все сообщения в чате.",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "editMsg",
|
"name": "editMsg",
|
||||||
"descr": "Отредактировать последнее отправленное ботом сообщение.",
|
"descr": "Отредактировать последнее отправленное ботом сообщение.",
|
||||||
@@ -67,6 +72,51 @@
|
|||||||
"name": "editFile",
|
"name": "editFile",
|
||||||
"descr": "Отредактировать последний отправленный файл, с указанием типа файла: 0-фото, 1-аудио, 2-документ, 3-видео, 4-анимация, 5-голос",
|
"descr": "Отредактировать последний отправленный файл, с указанием типа файла: 0-фото, 1-аудио, 2-документ, 3-видео, 4-анимация, 5-голос",
|
||||||
"params": ["Путь к файлу (/test.png)", "Тип файла/информации (число)"]
|
"params": ["Путь к файлу (/test.png)", "Тип файла/информации (число)"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "btnMenu",
|
||||||
|
"descr": "Описание кнопки меню выводит запросит значение ID и выведит сообщение => Произвольное сообщение(message): значение. Пример: btnMenu(Темп.Дома, Текущая температура, IDbme280)",
|
||||||
|
"params": ["Name - название кнопки отображается ботом", "message - Произвольное сообщения присылается в ответ на кнопку", "Id - Вернет значение элемента"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "btnMenu",
|
||||||
|
"descr": "Описание кнопки меню выводит запросит значение getID,установит значение value в setID и выведит сообщение => Произвольное сообщение(message): значение, IDrele=1. ВСЁ УКАЗЫВАТЬ В КАВЫЧКАХ, значение не обязательно! Пример: btnMenu(\"Обогрев\", \"Текущая температура\", \"IDbme280\", \"IDrele\", 1), btnMenu(Свет, Вклбчил свет, \"\", IDrele, 1)",
|
||||||
|
"params": ["Name - название кнопки отображается ботом", "message - Произвольное сообщения присылается в ответ на кнопку", "getId - Вернет значение элемента", "setId - Установит значение элементу", "value - Устанавливаемое значение"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "showMenu",
|
||||||
|
"descr": "Отобразить меню, созданное в сценарии",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "closeMenu",
|
||||||
|
"descr": "Закрыть мменю",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "btnInline",
|
||||||
|
"descr": "Описание кнопки встроенного (inline) меню выводит запросит значение ID и выведит сообщение => Произвольное сообщение(message): значение. Пример: btnMenu(Темп.Дома, Текущая температура, IDbme280)",
|
||||||
|
"params": ["Name - название кнопки отображается ботом", "message - Произвольное сообщения присылается в ответ на кнопку", "Id - Вернет значение элемента"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "btnInline",
|
||||||
|
"descr": "Описание кнопки встроенного (inline) меню выводит запросит значение getID,установит значение value в setID и выведит сообщение => Произвольное сообщение(message): значение, IDrele=1. ВСЁ УКАЗЫВАТЬ В КАВЫЧКАХ, значение не обязательно! Пример: btnMenu(\"Обогрев\", \"Текущая температура\", \"IDbme280\", \"IDrele\", 1), btnMenu(Свет, Вклбчил свет, \"\", IDrele, 1)",
|
||||||
|
"params": ["Name - название кнопки отображается ботом", "message - Произвольное сообщения присылается в ответ на кнопку", "getId - Вернет значение элемента", "setId - Установит значение элементу", "value - Устанавливаемое значение"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "showInline",
|
||||||
|
"descr": "Отобразить встроенное (inline) меню, созданное в сценарии",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "clearInline",
|
||||||
|
"descr": "Очистить встроенное (inline) меню, вызвать перед для язменения, перед созданием новых кнопок",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "clearMenu",
|
||||||
|
"descr": "Очистить меню, вызвать перед для язменения, перед созданием новых кнопок",
|
||||||
|
"params": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user