2026-03-18 12:10:30 -05:00
//+------------------------------------------------------------------+
2026-03-17 16:38:37 -05:00
//| Reciber.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
# property copyright " Copyright 2025, Niquel Mendoza. "
# property link " https://www.mql5.com/es/users/nique_372 "
# property strict
# ifndef AIDATATASKRUNNER_BACKEND_TLGM_RECIBER_MQH
# define AIDATATASKRUNNER_BACKEND_TLGM_RECIBER_MQH
2026-07-13 11:22:49 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
# resource "tools.json" as const string g_toos_json_shema_aidata
2026-03-17 16:38:37 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-03-18 12:10:30 -05:00
//--- Tools especficas para la app (todas async)
2026-04-01 13:21:12 -05:00
// Esto a su vez incluye el protocolo de comunicacion con API
// y la clase base de telegram
2026-03-18 12:10:30 -05:00
# include "Tools\\Tools.mqh"
// CChatTelegramBase
2026-07-13 11:22:49 -05:00
namespace TSN
2026-06-03 22:07:50 -05:00
{
2026-03-18 12:10:30 -05:00
class CChatTelegramBaseFully : public CChatTelegramBase
{
private :
2026-03-18 12:55:47 -05:00
void SendMessageToTlg ( const string & res , const string & tool_name , const string & tool_id ) ;
2026-07-13 11:22:49 -05:00
bool OnBeforeSetTools ( ) override final ;
2026-03-18 12:10:30 -05:00
public :
2026-07-15 13:45:36 -05:00
CChatTelegramBaseFully ( ) { }
2026-03-18 12:43:15 -05:00
~ CChatTelegramBaseFully ( void ) { }
2026-03-18 12:10:30 -05:00
//---
void ChartEvent ( const int32_t id , const long & lparam , const double & dparam , const string & sparam ) ;
} ;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-03-18 12:55:47 -05:00
void CChatTelegramBaseFully : : SendMessageToTlg ( const string & res , const string & tool_name , const string & tool_id )
2026-03-18 12:10:30 -05:00
{
2026-03-18 12:55:47 -05:00
SendMessage ( StringFormat ( " <b>AiDataTaskRunner</b> \n <code>[Tool: %s][Tool id: %s]</code>: %s " ,
tool_name , tool_id , res ) , NULL , TELEGRAM_PARSE_MODE_HTML ) ;
2026-03-18 12:10:30 -05:00
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-07-13 11:22:49 -05:00
bool CChatTelegramBaseFully : : OnBeforeSetTools ( )
2026-03-18 12:10:30 -05:00
{
2026-07-13 11:22:49 -05:00
//--- Agregamos
m_tools . AddItemFast ( new CAiTaskRunnerToolAddTask ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolSaveTasksToFile ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolLoadTasksFromFile ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolGetTaskTotal ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolGetTaskByIndex ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolCleanAllTasks ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolExecuteAllTasks ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolLoadConfig ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolSaveConfig ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolGetMainFolder ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolGetTaskFolder ( m_chart_id_padre , m_chart_id ) ) ;
m_tools . AddItemFast ( new CAiTaskRunnerToolIsInCommonFolder ( m_chart_id_padre , m_chart_id ) ) ;
//--- Finalizamos
CJsonParser * parser = m_tools . JsonParser ( ) ;
parser . Assing ( g_toos_json_shema_aidata ) ;
parser . CorrectPadingForSwar ( ) ;
// Luego parsea..
if ( ! m_tools .Init ( ) )
{
LogError ( " Fallo al iniciar tools " , FUNCION_ACTUAL ) ;
return false ;
}
2026-07-13 16:01:06 -05:00
if ( ! CLlmBasictToolsByLeo : : Load ( m_tools ) )
{
LogError ( " Fallo al cargar basic tools " , FUNCION_ACTUAL ) ;
return false ;
}
2026-07-13 11:22:49 -05:00
return true ;
2026-03-18 12:10:30 -05:00
}
2026-03-17 16:38:37 -05:00
2026-03-18 12:10:30 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CChatTelegramBaseFully : : ChartEvent ( const int32_t id , const long & lparam , const double & dparam , const string & sparam )
{
2026-04-01 12:33:57 -05:00
//--- El panel nos envio y nos dijo que cambiaramos parametors del tlgm.. redesitnamos a la clase base
2026-04-01 13:21:12 -05:00
if ( id = = CHARTEVENT_CUSTOM + CHATELGRAM_E_ON_CHANGE_PARAM )
2026-03-18 12:10:30 -05:00
{
2026-04-01 13:21:12 -05:00
// El key solo sirve para telegram con la api es formato abierto
2026-04-01 12:33:57 -05:00
//---
//dparam = key (el ea panel asigna la key y nos la da)
//soaram = valor (valor)
//lparam = parametro (parametros)
2026-03-18 13:28:52 -05:00
2026-03-18 12:10:30 -05:00
//---
2026-04-01 13:21:12 -05:00
// nota: el key se comprueba aqui por eso no lo hago aca
2026-04-01 12:33:57 -05:00
CChatTelegramBase : : ChartEvent ( id , lparam , dparam , sparam ) ;
return ;
}
2026-03-18 12:10:30 -05:00
2026-04-01 12:33:57 -05:00
//--- Recribimos respuesta del panel (por ejecuion de los tools) (esto es de la api)
if ( id = = CHARTEVENT_CUSTOM + AIDATATASKRUNER_API_ON_PARAM_CHANGE )
{
//---
2026-04-01 14:58:38 -05:00
// De salida: (api responde al que le envio datos)
// lparam=evento respondiido
// dparam=resultado
// sparam=info (empaquetada ToolId|Val)
//---
const uint8_t event_id = uint8_t ( lparam ) ;
2026-03-18 13:28:52 -05:00
2026-03-18 12:10:30 -05:00
//---
static string id_tool , val ;
2026-04-07 09:54:22 -05:00
if ( ! AiDataTaskRunnerDesempaquetar ( sparam , id_tool , val ) )
2026-03-18 12:10:30 -05:00
{
2026-04-01 12:33:57 -05:00
FastLog ( FUNCION_ACTUAL , FATAL_ERROR_TEXT , StringFormat ( " Formato invalido de empauqetacion de telegram [event_id=%u], mensaje recibido por UI Panel: \n %s " ,
event_id , sparam ) ) ;
2026-03-18 12:10:30 -05:00
return ;
}
2026-03-18 13:28:52 -05:00
else
{
2026-04-01 12:33:57 -05:00
FastLog ( FUNCION_ACTUAL , WARNING_TEXT , StringFormat ( " id=%u|sparam='%s' " , event_id , sparam ) ) ;
2026-03-18 13:28:52 -05:00
}
2026-03-18 12:10:30 -05:00
//---
2026-04-01 12:33:57 -05:00
// Aqui no hay chek aunque el panel no se equivoca a decir verdad
2026-03-18 12:55:47 -05:00
SendMessageToTlg ( val , g_aidatatask_runner_tools_tlg_names [ event_id ] , id_tool ) ;
2026-03-18 12:10:30 -05:00
}
}
2026-06-03 22:07:50 -05:00
}
2026-03-18 12:10:30 -05:00
# endif // AIDATATASKRUNNER_BACKEND_TLGM_SENDER_MQH
//+------------------------------------------------------------------+