236 lines
9.8 KiB
MQL5
236 lines
9.8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Def.mqh |
|
|
//| Copyright 2026, Niquel Mendoza. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
|
#property link "https://www.mql5.com"
|
|
#property strict
|
|
|
|
#ifndef TELEGRAMBYLEO_SRC_BASE_DEF_MQH
|
|
#define TELEGRAMBYLEO_SRC_BASE_DEF_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include <TSN\\Json\\Json.mqh>
|
|
#include <TSN\\WebUtils\\Multipart.mqh>
|
|
#include "..\\..\\EnumReg\\Main.mqh"
|
|
#include <TSN\\MQLArticles\\Utils\\FA\\Str\\Fixed.mqh>
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
namespace TSN
|
|
{
|
|
//+------------------------------------------------------------------+
|
|
//| End points |
|
|
//+------------------------------------------------------------------+
|
|
#define TELEGRAMBYLEO_BASE_URL "https://api.telegram.org"
|
|
|
|
//- Updates
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETUPDATES "getUpdates"
|
|
|
|
//- Me
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETME "getMe"
|
|
|
|
//- Send
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDMESSAGE "sendMessage"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDRICHMESSAGE "sendRichMessage"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDCHATACTION "sendChatAction"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDPOLL "sendPoll"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDDOC "sendDocument"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDVIDEO "sendVideo"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDAUDIO "sendAudio"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDVOICE "sendVoice"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDANIMATION "sendAnimation"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SENDPHOTO "sendPhoto"
|
|
|
|
//- Reacciones
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETMESSAGEREACTION "setMessageReaction"
|
|
#define TELEGRAMBYLEO_ENDPOINT_DELMESSAGEREACTION "deleteMessageReaction"
|
|
|
|
//- Miembros
|
|
#define TELEGRAMBYLEO_ENDPOINT_BANCHATMEMBER "banChatMember"
|
|
#define TELEGRAMBYLEO_ENDPOINT_UNBANCHATMEMBER "unbanChatMember"
|
|
#define TELEGRAMBYLEO_ENDPOINT_RESTRICTCHATMEMBER "restrictChatMember"
|
|
#define TELEGRAMBYLEO_ENDPOINT_PROMOTECHATMEMBER "promoteChatMember"
|
|
|
|
//- Yo (perfil del bot)
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETMYPROFILEPHOTO "setMyProfilePhoto"
|
|
#define TELEGRAMBYLEO_ENDPOINT_REMOVEMYPROFILEPHOTO "removeMyProfilePhoto"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETMYNAME "setMyName"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETMYNAME "getMyName"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETMYDESCRIPTION "setMyDescription"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETMYDESCRIPTION "getMyDescription"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETMYSHORTDESC "setMyShortDescription"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETMYSHORTDESC "getMyShortDescription"
|
|
|
|
//- Chat
|
|
#define TELEGRAMBYLEO_ENDPOINT_DELCHATPHOTO "deleteChatPhoto"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETCHATPHOTO "setChatPhoto"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETCHATTITLE "setChatTitle"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETCHATDESCRIPTION "setChatDescription"
|
|
#define TELEGRAMBYLEO_ENDPOINT_PINCHATMESSAGE "pinChatMessage"
|
|
#define TELEGRAMBYLEO_ENDPOINT_UNPINCHATMESSAGE "unpinChatMessage"
|
|
#define TELEGRAMBYLEO_ENDPOINT_UNPINALLCHATMSGS "unpinAllChatMessages"
|
|
#define TELEGRAMBYLEO_ENDPOINT_LEAVECHAT "leaveChat"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETCHAT "getChat"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETCHATADMINS "getChatAdministrators"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETCHATMEMBERCOUNT "getChatMemberCount"
|
|
#define TELEGRAMBYLEO_ENDPOINT_GETCHATMEMBER "getChatMember"
|
|
#define TELEGRAMBYLEO_ENDPOINT_SETCHATSTICKERSET "setChatStickerSet"
|
|
#define TELEGRAMBYLEO_ENDPOINT_DELCHATSTICKERSET "deleteChatStickerSet"
|
|
|
|
//- Botones / callback
|
|
#define TELEGRAMBYLEO_ENDPOINT_ANSWERCALLBACKQUERY "answerCallbackQuery"
|
|
|
|
//- Poll
|
|
#define TELEGRAMBYLEO_ENDPOINT_STOPPOLL "stopPoll"
|
|
|
|
//- Delete
|
|
#define TELEGRAMBYLEO_ENDPOINT_DELMESSAGE "deleteMessage"
|
|
|
|
//- Edicion
|
|
#define TELEGRAMBYLEO_ENDPOINT_EDITMESSAGETEXT "editMessageText"
|
|
#define TELEGRAMBYLEO_ENDPOINT_EDITMESSAGEREPLYMARKUP "editMessageReplyMarkup"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Eventos |
|
|
//+------------------------------------------------------------------+
|
|
enum ENUM_TELEGRAMBYLEO_GETUPT_KEYVALUE
|
|
{
|
|
//---
|
|
TELEGRAMBYLEO_GETUPT_K_UPDATEID,
|
|
|
|
//---
|
|
TELEGRAMBYLEO_GETUPT_K_MESSAGE,
|
|
TELEGRAMBYLEO_GETUPT_K_EDITED_MESSAGE,
|
|
TELEGRAMBYLEO_GETUPT_K_CHANNEL_POST,
|
|
TELEGRAMBYLEO_GETUPT_K_EDITED_CHANNEL_POST,
|
|
TELEGRAMBYLEO_GETUPT_K_BUSINESS_CONNECTION,
|
|
TELEGRAMBYLEO_GETUPT_K_BUSINESS_MESSAGE,
|
|
TELEGRAMBYLEO_GETUPT_K_EDITED_BUSINESS_MESSAGE,
|
|
TELEGRAMBYLEO_GETUPT_K_DELETED_BUSINESS_MESSAGES,
|
|
TELEGRAMBYLEO_GETUPT_K_GUEST_MESSAGE,
|
|
TELEGRAMBYLEO_GETUPT_K_MESSAGE_REACTION,
|
|
TELEGRAMBYLEO_GETUPT_K_MESSAGE_REACTION_COUNT,
|
|
TELEGRAMBYLEO_GETUPT_K_INLINE_QUERY,
|
|
TELEGRAMBYLEO_GETUPT_K_CHOSEN_INLINE_RESULT,
|
|
TELEGRAMBYLEO_GETUPT_K_CALLBACK_QUERY,
|
|
TELEGRAMBYLEO_GETUPT_K_SHIPPING_QUERY,
|
|
TELEGRAMBYLEO_GETUPT_K_PRE_CHECKOUT_QUERY,
|
|
TELEGRAMBYLEO_GETUPT_K_PURCHASED_PAID_MEDIA,
|
|
TELEGRAMBYLEO_GETUPT_K_POLL,
|
|
TELEGRAMBYLEO_GETUPT_K_POLL_ANSWER,
|
|
TELEGRAMBYLEO_GETUPT_K_MY_CHAT_MEMBER,
|
|
TELEGRAMBYLEO_GETUPT_K_CHAT_MEMBER,
|
|
TELEGRAMBYLEO_GETUPT_K_CHAT_JOIN_REQUEST,
|
|
TELEGRAMBYLEO_GETUPT_K_CHAT_BOOST,
|
|
TELEGRAMBYLEO_GETUPT_K_REMOVED_CHAT_BOOST,
|
|
TELEGRAMBYLEO_GETUPT_K_MANAGED_BOT,
|
|
TELEGRAMBYLEO_GETUPT_K_SUBSCRIPTION,
|
|
TELEGRAMBYLEO_GETUPT_K_STOPPED_MESSAGE_GENERATION,
|
|
|
|
//---
|
|
TELEGRAMBYLEO_GETUPT_K_TOTAL
|
|
};
|
|
|
|
//---
|
|
const string g_tlgbyleo_getupt_kstr[TELEGRAMBYLEO_GETUPT_K_TOTAL - 1] =
|
|
{
|
|
"message",
|
|
"edited_message",
|
|
"channel_post",
|
|
"edited_channel_post",
|
|
"business_connection",
|
|
"business_message",
|
|
"edited_business_message",
|
|
"deleted_business_messages",
|
|
"guest_message",
|
|
"message_reaction",
|
|
"message_reaction_count",
|
|
"inline_query",
|
|
"chosen_inline_result",
|
|
"callback_query",
|
|
"shipping_query",
|
|
"pre_checkout_query",
|
|
"purchased_paid_media",
|
|
"poll",
|
|
"poll_answer",
|
|
"my_chat_member",
|
|
"chat_member",
|
|
"chat_join_request",
|
|
"chat_boost",
|
|
"removed_chat_boost",
|
|
"managed_bot",
|
|
"subscription",
|
|
"stopped_message_generation"
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Basicos |
|
|
//+------------------------------------------------------------------+
|
|
enum ENUM_TELEGRAMBYLEO_CHAT_ACTION
|
|
{
|
|
TELEGRAMBYLEO_CHAT_ACTION_TYPING,
|
|
TELEGRAMBYLEO_CHAT_ACTION_UPLOAD_PHOTO,
|
|
TELEGRAMBYLEO_CHAT_ACTION_RECORD_VIDEO,
|
|
TELEGRAMBYLEO_CHAT_ACTION_UPLOAD_VIDEO,
|
|
TELEGRAMBYLEO_CHAT_ACTION_RECORD_AUDIO,
|
|
TELEGRAMBYLEO_CHAT_ACTION_UPLOAD_AUDIO,
|
|
TELEGRAMBYLEO_CHAT_ACTION_UPLOAD_DOCUMENT,
|
|
TELEGRAMBYLEO_CHAT_ACTION_CHOOSE_STIKER,
|
|
TELEGRAMBYLEO_CHAT_ACTION_FIND_LOCATION,
|
|
TELEGRAMBYLEO_CHAT_ACTION_RECORD_VIDEO_NOTE,
|
|
TELEGRAMBYLEO_CHAT_ACTION_UPLOAD_VIDEO_NOTE
|
|
};
|
|
|
|
//---
|
|
enum ENUM_TELEGRAM_PARSE_MODE
|
|
{
|
|
TELEGRAM_PARSE_MODE_HTML = 0,
|
|
TELEGRAM_PARSE_MODE_MD = 1,
|
|
TELEGRAM_PARSE_MODE_MD_2 = 2
|
|
};
|
|
|
|
|
|
//---
|
|
const CStringFixed<MQLA_B(16)> g_telegram_parse_mode_str[3] =
|
|
{
|
|
{{'H', 'T', 'M', 'L'}, 4}, // HTML
|
|
{{'M', 'a', 'r', 'k', 'd', 'o', 'w', 'n'}, 8}, // Markdown
|
|
{{'M', 'a', 'r', 'k', 'd', 'o', 'w', 'n', 'V', '2'}, 10} // MarkdownV2
|
|
};
|
|
|
|
//---
|
|
const CStringFixed<MQLA_B(32)> g_telegram_chat_action[] =
|
|
{
|
|
{{'t', 'y', 'p', 'i', 'n', 'g'}, 6}, // typing
|
|
{{'u', 'p', 'l', 'o', 'a', 'd', '_', 'p', 'h', 'o', 't', 'o'}, 12}, // upload_photo
|
|
{{'r', 'e', 'c', 'o', 'r', 'd', '_', 'v', 'i', 'd', 'e', 'o'}, 12}, // record_video
|
|
{{'u', 'p', 'l', 'o', 'a', 'd', '_', 'v', 'i', 'd', 'e', 'o'}, 12}, // upload_video
|
|
{{'r', 'e', 'c', 'o', 'r', 'd', '_', 'v', 'o', 'i', 'c', 'e'}, 12}, // record_voice
|
|
{{'u', 'p', 'l', 'o', 'a', 'd', '_', 'v', 'o', 'i', 'c', 'e'}, 12}, // upload_voice
|
|
{{'u', 'p', 'l', 'o', 'a', 'd', '_', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't'}, 15}, // upload_document
|
|
{{'c', 'h', 'o', 'o', 's', 'e', '_', 's', 't', 'i', 'c', 'k', 'e', 'r'}, 14}, // choose_sticker
|
|
{{'f', 'i', 'n', 'd', '_', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n'}, 13}, // find_location
|
|
{{'r', 'e', 'c', 'o', 'r', 'd', '_', 'v', 'i', 'd', 'e', 'o', '_', 'n', 'o', 't', 'e'}, 17}, // record_video_note
|
|
{{'u', 'p', 'l', 'o', 'a', 'd', '_', 'v', 'i', 'd', 'e', 'o', '_', 'n', 'o', 't', 'e'}, 17} // upload_video_note
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Error |
|
|
//+------------------------------------------------------------------+
|
|
enum ENUM_TELEGRAMBYLEO_ERR
|
|
{
|
|
TELEGRAMBYLEO_ERR_NOT,
|
|
TELEGRAMBYLEO_ERR_TOKEN_EMPTY,
|
|
TELEGRAMBYLEO_ERR_JSON_PARSING,
|
|
TELEGRAMBYLEO_ERR_JSON_NOT_OK,
|
|
TELEGRAMBYLEO_ERR_WEB_REQ,
|
|
};
|
|
|
|
//---
|
|
}
|
|
#endif // TELEGRAMBYLEO_SRC_BASE_DEF_MQH
|