97 lines
3.4 KiB
MQL5
97 lines
3.4 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Ea.mq5 |
|
|
//| Copyright 2025, Niquel Mendoza. |
|
|
//| https://www.mql5.com/es/users/nique_372/news |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/es/users/nique_372/news"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Include |
|
|
//+------------------------------------------------------------------+
|
|
#include "..\\Src\\CommandsApi.mqh"
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
input string InpBotToken = "";
|
|
input long InpBotChatId = 0;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
class CMyBot : public TSN::CTelegramCommandBot
|
|
{
|
|
protected:
|
|
void OnCommand(int command_idx, long chat_id, TSN::CJsonNode& json) override final
|
|
{
|
|
switch(command_idx)
|
|
{
|
|
case 0: // /start
|
|
SendMessage("Hola como estas?¿");
|
|
break;
|
|
case 1: // /ping
|
|
SendMessage("Pong");
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CMyBot g_bot;
|
|
TSN::CTelegramBotUpdater g_tlg_bot_poller;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//---
|
|
g_tlg_bot_poller.Token(InpBotToken);
|
|
g_tlg_bot_poller.RegisterEvent(&g_bot, TSN::TELEGRAMBYLEO_GETUPT_K_MESSAGE);
|
|
g_tlg_bot_poller.Init();
|
|
g_tlg_bot_poller.AllowedUpdates();
|
|
|
|
//---
|
|
g_bot.Token(InpBotToken);
|
|
g_bot.ChatId(InpBotChatId);
|
|
g_bot.SetCommand("start", 0);
|
|
g_bot.SetCommand("ping", 1);
|
|
|
|
|
|
//---
|
|
EventSetMillisecondTimer(1000);
|
|
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
g_tlg_bot_poller.UnregisterEvent(&g_bot, TSN::TELEGRAMBYLEO_GETUPT_K_MESSAGE);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//---
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void OnTimer(void)
|
|
{
|
|
g_tlg_bot_poller.GetUpdates();
|
|
}
|
|
//+------------------------------------------------------------------+
|