2026-09-22 17:06:21 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| MainAPI.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_MAIN_API_MQH
|
| | | #define TELEGRAMBYLEO_SRC_MAIN_API_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "Base\\Bases.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // Notas:
|
| | | // DOCS: C:\Users\leoxd\Documents\test\Telegram Bot API.html
|
| | | // 1. Para audio etc el mime para el "tumbail" en los send esos creo qeu es "image/jpeg"
|
| | | //
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| TODO |
|
| | | //+------------------------------------------------------------------+
|
| | | // (ninguno pendiente por ahora)
|
| | |
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #define TELEGRAMBYLEO_COMMONS_CAMPS \
|
| | | if(reply_markup_s>-1) \
|
| | | m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup \
|
| | | ,reply_markup_s); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(base.allow_paid_broadcast!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("allow_paid_broadcast").Val( \
|
| | | (base.allow_paid_broadcast==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("disable_notification").Val( \
|
| | | (base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("protect_content").Val( \
|
| | | (base.protect_content==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(base.message_thread_id != -1 && base.message_thread_id != 1) \
|
| | | m_js_builder.KeyWV("message_thread_id").Val(base.message_thread_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
|
2026-09-23 21:33:46 -05:00 | | | m_js_builder.KeyWV("reply_parameters").Obj(); \
|
2026-09-22 17:06:21 -05:00 | | | int obj = m_js_builder.m_pos; \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(rp.poll_option_id.Length()) \
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.quote.Length()) \
|
| | | m_js_builder.KeyWV("quote").ValS(rp.quote); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.quote_parse_mode != WRONG_VALUE) \
|
| | | m_js_builder.KeyWV("quote_parse_mode") \
|
2026-09-26 11:29:53 -05:00 | | | .ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, \
|
| | | g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.message_id != -1) \
|
| | | m_js_builder.KeyWV("message_id").Val(rp.message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.ephemeral_message_id != -1) \
|
| | | m_js_builder.KeyWV("ephemeral_message_id") \
|
| | | .Val(rp.ephemeral_message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.allow_sending_without_reply!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("allow_sending_without_reply").Val( \
|
| | | (rp.allow_sending_without_reply==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.quote_position != -1) \
|
| | | m_js_builder.KeyWV("quote_position").Val(rp.quote_position); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(rp.checklist_task_id != -1) \
|
| | | m_js_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(obj < m_js_builder.m_pos) \
|
| | | m_js_builder.EndObj(); \
|
| | | else \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.ApplySnapshot(m_jsonbuilder_lock); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.KeyWV("ephemeral_message_parameters").Obj(); \
|
| | | obj = m_js_builder.m_pos; \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(ep.callback_query_id.Length()) \
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.KeyWV("callback_query_id").ValS(ep.callback_query_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(ep.receiver_user_id!=-1) \
|
| | | m_js_builder.KeyWV("receiver_user_id").Val(ep.receiver_user_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(ep.replace_callback_query_message!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("replace_callback_query_message").Val( \
|
| | | (ep.replace_callback_query_message==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-22 17:06:21 -05:00 | | | if(obj < m_js_builder.m_pos) \
|
| | | m_js_builder.EndObj(); \
|
| | | else \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.ApplySnapshot(m_jsonbuilder_lock);
|
2026-09-22 17:06:21 -05:00 | | |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-26 11:29:53 -05:00 | | | //| |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //- options[] (TlgInputPollOption), usado tambien en las versiones basicas
|
| | | #define TELEGRAMBYLEO_POLL_OPTIONS \
|
| | | m_js_builder.KeyWV("options").Arr(); \
|
| | | for(int __i = 0; __i < ArraySize(options); __i++) \
|
| | | { \
|
| | | m_js_builder.Obj(); \
|
| | | m_js_builder.KeyWV("text").ValS(options[__i].text); \
|
| | | if(options[__i].text_parse_mode != WRONG_VALUE) \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.KeyWV("text_parse_mode") \
|
| | | .ValUWV(g_telegram_parse_mode_str[options[__i].text_parse_mode].raw, \
|
| | | g_telegram_parse_mode_str[options[__i].text_parse_mode].len); \
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj(); \
|
| | | } \
|
| | | m_js_builder.EndArr();
|
| | |
|
| | | //- TlgPollBoolOps
|
| | | #define TELEGRAMBYLEO_POLL_BOPS \
|
| | | if(bops.is_anonymous != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("is_anonymous").Val( \
|
| | | (bops.is_anonymous==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(bops.allows_multiple_answers != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("allows_multiple_answers").Val( \
|
| | | (bops.allows_multiple_answers==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(bops.shuffle_options != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("shuffle_options").Val( \
|
| | | (bops.shuffle_options==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(bops.hide_results_until_closes != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("hide_results_until_closes").Val( \
|
| | | (bops.hide_results_until_closes==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(bops.members_only != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("members_only").Val( \
|
| | | (bops.members_only==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(bops.is_closed != TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("is_closed").Val( \
|
| | | (bops.is_closed==TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //- country_codes[]
|
| | | #define TELEGRAMBYLEO_POLL_COUNTRY_CODES \
|
| | | if(ArraySize(country_codes) > 0) \
|
| | | { \
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.KeyWV("country_codes").Arr(); \
|
2026-09-23 15:26:06 -05:00 | | | for(int __i = 0; __i < ArraySize(country_codes); __i++) \
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.ValSWV(country_codes[__i]); \
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndArr(); \
|
| | | }
|
| | |
|
| | | //- base + rp + reply_markup (sin ep: sendPoll no tiene ephemeral_message_parameters)
|
| | | #define TELEGRAMBYLEO_POLL_COMMONS \
|
| | | if(reply_markup_s>-1) \
|
| | | m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup, \
|
| | | reply_markup_s); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.allow_paid_broadcast!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("allow_paid_broadcast").Val( \
|
| | | (base.allow_paid_broadcast==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("disable_notification").Val( \
|
| | | (base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("protect_content").Val( \
|
2026-09-23 17:35:51 -05:00 | | | (base.protect_content==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.message_thread_id != -1 && base.message_thread_id != 1) \
|
| | | m_js_builder.KeyWV("message_thread_id").Val(base.message_thread_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.KeyWV("reply_parameters").Obj(); \
|
2026-09-23 15:26:06 -05:00 | | | int __obj_rp = m_js_builder.m_pos; \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(rp.poll_option_id.Length()) \
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote.Length()) \
|
| | | m_js_builder.KeyWV("quote").ValS(rp.quote); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote_parse_mode != WRONG_VALUE) \
|
| | | m_js_builder.KeyWV("quote_parse_mode") \
|
2026-09-26 11:29:53 -05:00 | | | .ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, \
|
| | | g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.message_id != -1) \
|
| | | m_js_builder.KeyWV("message_id").Val(rp.message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.ephemeral_message_id != -1) \
|
| | | m_js_builder.KeyWV("ephemeral_message_id") \
|
| | | .Val(rp.ephemeral_message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.allow_sending_without_reply!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_js_builder.KeyWV("allow_sending_without_reply").Val( \
|
| | | (rp.allow_sending_without_reply==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote_position != -1) \
|
| | | m_js_builder.KeyWV("quote_position").Val(rp.quote_position); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.checklist_task_id != -1) \
|
| | | m_js_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(__obj_rp < m_js_builder.m_pos) \
|
| | | m_js_builder.EndObj(); \
|
| | | else \
|
2026-09-26 11:29:53 -05:00 | | | m_js_builder.ApplySnapshot(m_jsonbuilder_lock);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Multipart: solo lo que se repite entre varios Send*. Lo que es |
|
| | | //| propio de un endpoint (caption, mime, thumbnail...) va inline. |
|
| | | //| base/reply_markup van directo; rp/ep se arman en g_json_builder |
|
| | | //| (scratch, no es m_js_builder para no pisar el lock de ChatId()) |
|
| | | //| y se meten al multipart como string. |
|
| | | //+------------------------------------------------------------------+
|
| | | //- TlgSendBase
|
| | | #define TELEGRAMBYLEO_MULTIPART_BASE \
|
| | | if(base.message_thread_id != -1 && base.message_thread_id != 1) \
|
| | | m_multipar_buffer.SetSignedNumber<long, ulong, MULTIPART_TAPPEND>( \
|
| | | "message_thread_id", base.message_thread_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("disable_notification", \
|
| | | (base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("protect_content", \
|
| | | (base.protect_content==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(base.allow_paid_broadcast!=TLGBYLEO_BOOL_UNSET) \
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("allow_paid_broadcast", \
|
| | | (base.allow_paid_broadcast==TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //- reply_markup[]
|
| | | #define TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP \
|
| | | if(reply_markup_s>-1) \
|
| | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("reply_markup", \
|
| | | reply_markup, 0, reply_markup_s);
|
| | |
|
| | | //- TlgReplyParameters
|
| | | #define TELEGRAMBYLEO_MULTIPART_RP \
|
| | | g_json_builder.Clear(); \
|
| | | g_json_builder.Obj(); \
|
| | | int __obj_rp = g_json_builder.m_pos; \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(rp.poll_option_id.Length()) \
|
2026-09-23 15:26:06 -05:00 | | | g_json_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote.Length()) \
|
| | | g_json_builder.KeyWV("quote").ValS(rp.quote); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote_parse_mode != WRONG_VALUE) \
|
| | | g_json_builder.KeyWV("quote_parse_mode") \
|
2026-09-25 22:28:13 -05:00 | | | .ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.message_id != -1) \
|
| | | g_json_builder.KeyWV("message_id").Val(rp.message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.ephemeral_message_id != -1) \
|
| | | g_json_builder.KeyWV("ephemeral_message_id").Val(rp.ephemeral_message_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.allow_sending_without_reply!=TLGBYLEO_BOOL_UNSET) \
|
| | | g_json_builder.KeyWV("allow_sending_without_reply").Val( \
|
| | | (rp.allow_sending_without_reply==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.quote_position != -1) \
|
| | | g_json_builder.KeyWV("quote_position").Val(rp.quote_position); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(rp.checklist_task_id != -1) \
|
| | | g_json_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 15:26:06 -05:00 | | | if(__obj_rp < g_json_builder.m_pos) \
|
| | | { \
|
| | | g_json_builder.EndObj(); \
|
2026-09-23 17:35:51 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("reply_parameters", \
|
| | | g_json_builder.m_buf, 0, g_json_builder.m_pos); \
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //- TlgEphemeralMessageParameters
|
2026-09-23 17:35:51 -05:00 | | | #define TELEGRAMBYLEO_MULTIPART_EP \
|
| | | g_json_builder.Clear(); \
|
| | | g_json_builder.Obj(); \
|
| | | int __obj_ep = g_json_builder.m_pos; \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(ep.callback_query_id.Length()) \
|
| | | g_json_builder.KeyWV("callback_query_id").ValS(ep.callback_query_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(ep.receiver_user_id!=-1) \
|
| | | g_json_builder.KeyWV("receiver_user_id").Val(ep.receiver_user_id); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(ep.replace_callback_query_message!=TLGBYLEO_BOOL_UNSET) \
|
| | | g_json_builder.KeyWV("replace_callback_query_message").Val( \
|
| | | (ep.replace_callback_query_message==TLGBYLEO_BOOL_TRUE)); \
|
2026-09-23 21:33:46 -05:00 | | | \
|
2026-09-23 17:35:51 -05:00 | | | if(__obj_ep < g_json_builder.m_pos) \
|
| | | { \
|
| | | g_json_builder.EndObj(); \
|
| | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("ephemeral_message_parameters", \
|
| | | g_json_builder.m_buf, 0, g_json_builder.m_pos); \
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
2026-09-25 21:10:24 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-26 11:29:53 -05:00 | | | //| |
|
2026-09-25 21:10:24 -05:00 | | | //+------------------------------------------------------------------+
|
| | | #define TELEGRAMBYLEO_LINK_PREVIEW(builder) \
|
2026-09-26 11:29:53 -05:00 | | | builder.GetSnapshot(m_jsonbuilder_lock); \
|
2026-09-25 21:10:24 -05:00 | | | builder.KeyWV("link_preview_options").Obj(); \
|
| | | int __lp_obj = builder.m_pos; \
|
2026-09-26 11:29:53 -05:00 | | | \
|
2026-09-25 21:10:24 -05:00 | | | if(link.is_disabled != TLGBYLEO_BOOL_UNSET) \
|
| | | builder.KeyWV("is_disabled").Val((link.is_disabled == TLGBYLEO_BOOL_TRUE)); \
|
2026-09-26 11:29:53 -05:00 | | | \
|
2026-09-25 21:10:24 -05:00 | | | if(link.url != "") \
|
| | | builder.KeyWV("url").ValS(link.url); \
|
2026-09-26 11:29:53 -05:00 | | | \
|
2026-09-25 21:10:24 -05:00 | | | if(link.prefer_small_media != TLGBYLEO_BOOL_UNSET) \
|
| | | builder.KeyWV("prefer_small_media").Val((link.prefer_small_media == TLGBYLEO_BOOL_TRUE)); \
|
2026-09-26 11:29:53 -05:00 | | | \
|
2026-09-25 21:10:24 -05:00 | | | if(link.prefer_large_media != TLGBYLEO_BOOL_UNSET) \
|
| | | builder.KeyWV("prefer_large_media").Val((link.prefer_large_media == TLGBYLEO_BOOL_TRUE)); \
|
2026-09-26 11:29:53 -05:00 | | | \
|
2026-09-25 21:10:24 -05:00 | | | if(link.show_above_text != TLGBYLEO_BOOL_UNSET) \
|
2026-09-26 11:29:53 -05:00 | | | builder.KeyWV("show_above_text").Val((link.show_above_text == TLGBYLEO_BOOL_TRUE)); \
|
| | | \
|
2026-09-25 21:10:24 -05:00 | | | if(__lp_obj < builder.m_pos) \
|
| | | builder.EndObj(); \
|
| | | else \
|
2026-09-26 11:29:53 -05:00 | | | builder.ApplySnapshot(m_jsonbuilder_lock);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-25 09:59:13 -05:00 | | | class CTelegramAPI : public CTelegramHandler
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | protected:
|
| | | //--- Principal
|
| | | long m_chat_id; // ChatId fijo
|
2026-09-23 16:35:15 -05:00 | | | JsonBuilderSnapshot m_chat_id_snap; // ChatId lock (pos+sp+stack_first)
|
2026-09-22 17:06:21 -05:00 | | | string m_url_method; // URL ya lista
|
| | | string m_token; // Token del bot
|
2026-09-23 21:33:46 -05:00 | | | int m_timeout; // Timeout
|
2026-09-22 17:06:21 -05:00 | | | ENUM_TELEGRAMBYLEO_ERR m_last_err; // Ultimo err
|
| | | int m_last_res_web; // Ultimo err en web
|
| | |
|
2026-09-26 11:29:53 -05:00 | | | //----
|
| | | JsonBuilderSnapshot m_jsonbuilder_lock;
|
| | |
|
2026-09-23 15:26:06 -05:00 | | | //--- Parsing
|
2026-09-24 13:22:43 -05:00 | | | CJsonParser m_json; // Json que se usa para gettters* aqui
|
2026-09-23 15:26:06 -05:00 | | |
|
2026-09-26 16:42:14 -05:00 | | | // unsafe de usar.. si lo tcoas ten cuidado con lo qeu haces (cualquier desincroniacion = JSON Malformado solo para experimentados)
|
2026-09-24 14:00:52 -05:00 | | | CTsnMultipartRaw m_multipar_buffer; // Multipar buffer con lock
|
2026-09-22 17:06:21 -05:00 | | | CJsonBuilder m_js_builder; // Json Builder
|
| | |
|
2026-09-24 14:00:52 -05:00 | | | public:
|
2026-09-25 08:00:55 -05:00 | | | //---
|
2026-09-24 14:00:52 -05:00 | | | CTsnMultipartRaw m_mulipar_dync; // Version dinamica (no lockea)
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | public:
|
2026-09-25 09:59:13 -05:00 | | | CTelegramAPI();
|
2026-09-24 12:18:36 -05:00 | | | ~CTelegramAPI(void) {}
|
2026-09-22 17:06:21 -05:00 | | |
|
2026-09-23 21:33:46 -05:00 | | | //--- Miembros
|
2026-09-22 17:06:21 -05:00 | | | //- token
|
| | | bool Token(string _token);
|
| | | __forceinline string Token() const { return m_token; }
|
| | |
|
| | | //- chat id
|
| | | void ChatId(const long chat_id);
|
| | | __forceinline long ChatId() const { return m_chat_id; }
|
| | |
|
2026-09-23 21:33:46 -05:00 | | | //- timeout
|
| | | void Timeout(int value) { m_timeout = value; }
|
| | | __forceinline int Timeout() const { return m_timeout; }
|
2026-09-23 17:35:51 -05:00 | | |
|
2026-09-23 21:33:46 -05:00 | | | //--- Last Err
|
| | | __forceinline ENUM_TELEGRAMBYLEO_ERR LastErr() const { return m_last_err; }
|
| | | int LastResHttp() const { return m_last_res_web; }
|
| | |
|
2026-09-22 17:06:21 -05:00 | | |
|
2026-09-23 21:33:46 -05:00 | | | //--- Send general
|
2026-09-22 17:06:21 -05:00 | | | bool Send(const string& method, CJsonBuilder &raw);
|
| | | bool Send(const string& method, CTsnMultipartRaw& raw);
|
2026-09-25 09:59:13 -05:00 | | | bool Send(const string& method); // GET
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //--- Send
|
2026-09-26 16:42:14 -05:00 | | | //-- rich
|
| | | // por ahora no media si se reuqiere quizas lo agrego
|
| | | bool SendRichMessageMarkdown(const string& markdown, TLGBYLEO_BOOL is_rtl, TLGBYLEO_BOOL skip_entity_detection);
|
| | | // version completa
|
| | | bool SendRichMessageMarkdown(const string& markdown, TLGBYLEO_BOOL is_rtl, TLGBYLEO_BOOL skip_entity_detection,
|
| | | // common
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp, const TlgEphemeralMessageParameters& ep,
|
| | | uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | //-- Action
|
| | | bool SendChatAction(ENUM_TELEGRAMBYLEO_CHAT_ACTION action, long message_thread_id = -1);
|
| | |
|
| | | //-- Msg
|
| | | bool SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode = WRONG_VALUE);
|
| | | bool SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
|
| | | // common
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp, const TlgEphemeralMessageParameters& ep, const TlgLinkPreviewOptions& link,
|
| | | uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | | //-- Encuenta
|
| | | //- Regular
|
| | | bool SendPollRegular(const string& question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
| | | const TlgInputPollOption& options[], datetime close_date, const string& description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allow_adding_options, TLGBYLEO_BOOL allows_revoting);
|
| | | // Con todo ...
|
| | | bool SendPollRegular(const string& question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
| | | const TlgInputPollOption& options[], datetime close_date, const string& description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allow_adding_options, TLGBYLEO_BOOL allows_revoting,
|
| | | // extra
|
| | | const TlgPollBoolOps& bops, const TlgSendBase& base,
|
| | | const TlgReplyParameters& rp, const string& country_codes[], uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | | //- Quiz
|
| | | // regular
|
| | | bool SendPollQuiz(const string& question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
| | | const TlgInputPollOption& options[], datetime close_date, const string& description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allows_revoting,
|
| | | const string& explanation, ENUM_TELEGRAM_PARSE_MODE explanation_parse_mode, int correct_option_ids);
|
| | | // Con todo ...
|
| | | bool SendPollQuiz(const string& question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
| | | const TlgInputPollOption& options[], datetime close_date, const string& description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allows_revoting,
|
2026-09-23 15:26:06 -05:00 | | | const string& explanation, ENUM_TELEGRAM_PARSE_MODE explanation_parse_mode, int correct_option_ids,
|
2026-09-22 17:06:21 -05:00 | | | // extra
|
| | | const TlgPollBoolOps& bops, const TlgSendBase& base,
|
| | | const TlgReplyParameters& rp, const string& country_codes[], uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | | //-- documentos
|
| | | // basico
|
| | | bool SendDocument(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& document, bool common);
|
| | | // full
|
| | | bool SendDocument(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& document, bool common,
|
| | | // extra
|
| | | const string& mime, const string& thumbnail, bool thumbnail_common, const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | | //-- video
|
| | | // basico
|
| | | bool SendVideo(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& video, bool common);
|
| | | // completo
|
| | | bool SendVideo(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& video, bool common,
|
| | | // extra
|
| | | int duration, int height, int widht,
|
| | | const string& thumbnail, bool thumbnail_common,
|
| | | const string& cover, bool cover_common,
|
| | | int start_timestamp, TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler, TLGBYLEO_BOOL supports_streaming,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | |
|
| | | //-- Audio
|
| | | bool SendAudio(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& audio, bool audio_common,
|
2026-09-23 15:26:06 -05:00 | | | uint duration, const string& performer, const string& title);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | bool SendAudio(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& audio, bool audio_common,
|
2026-09-23 15:26:06 -05:00 | | | uint duration, const string& performer, const string& title,
|
2026-09-22 17:06:21 -05:00 | | | // extra
|
| | | const string& thumbnail, bool thumbnail_common,
|
| | | // common
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | |
|
| | | //-- Voice
|
| | | bool SendVoice(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& voice, bool voice_common);
|
| | |
|
| | | bool SendVoice(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& voice, bool voice_common,
|
| | | // ext
|
| | | int duration,
|
| | | // commmon
|
2026-09-23 15:26:06 -05:00 | | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
2026-09-22 17:06:21 -05:00 | | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
| | | //-- Animacion
|
| | | bool SendAnimation(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& animation, bool animation_common);
|
2026-09-23 15:26:06 -05:00 | | | bool SendAnimation(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& animation, bool animation_common,
|
2026-09-22 17:06:21 -05:00 | | | // extra
|
2026-09-23 15:26:06 -05:00 | | | uint duration, uint height, uint widht,
|
| | | const string& thumbnail, bool thumbnail_common,
|
2026-09-22 17:06:21 -05:00 | | | TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler,
|
| | | // commmon
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2
|
| | | );
|
| | |
|
2026-09-23 15:26:06 -05:00 | | | //-- Foto
|
| | | // basico
|
| | | bool SendPhoto(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& photo, bool common);
|
| | | // completo
|
| | | bool SendPhoto(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& photo, bool common,
|
| | | // extra
|
| | | TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s = -2);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //--- Reacciones
|
| | | bool SetMessageReaction(long message_id, TLGBYLEO_BOOL is_big, const TlgReactionType& reactions[]);
|
| | |
|
| | | //--- Miembros
|
| | | bool BanChatMember(long user_id, datetime until_date, TLGBYLEO_BOOL revoke_messages);
|
| | | bool UnbanChatMember(long user_id, TLGBYLEO_BOOL only_if_banned);
|
| | | bool RestrictChatMember(long user_id, ulong permissions, TLGBYLEO_BOOL use_independent_chat_permissions, datetime until_date);
|
| | | bool PromoteChatMember(long user_id, TLGBYLEO_BOOL is_anonymous, ulong can);
|
| | |
|
2026-09-25 21:10:24 -05:00 | | | //--- Edicion de message
|
| | | bool EditMessageText(long message_id, const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
|
| | | const TlgLinkPreviewOptions& link, uchar& reply_markup[], int reply_markup_s = -2);
|
2026-09-25 21:34:44 -05:00 | | | // version con inline message id
|
2026-09-25 21:10:24 -05:00 | | | bool EditMessageText(const string& inline_message_id, const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
|
| | | const TlgLinkPreviewOptions& link, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
2026-09-26 16:42:14 -05:00 | | | //--- Edicion de solo el reply_markup
|
| | | bool EditMessageReplyMarkup(long message_id, uchar& reply_markup[], int reply_markup_s = -2);
|
| | | // version con inline message id
|
| | | bool EditMessageReplyMarkup(const string& inline_message_id, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | //--- Yo
|
2026-09-24 13:22:43 -05:00 | | | //-- user
|
| | | bool GetMe(TlgUser& info);
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | // foto de perfil
|
| | | // Estilo: multipart con referencia (json + referenca.. luegp)
|
| | | bool SetMyProfilePhoto(const string& photo, bool photo_common);
|
| | | bool RemoveMyProfilePhoto();
|
| | |
|
| | | // name
|
| | | bool SetMyName(const string& name, const string& language_code);
|
| | | bool GetMyName(string& name);
|
| | |
|
| | | // description
|
| | | bool SetMyDescription(const string& description, const string& language_code);
|
| | | bool GetMyDescription(string& description);
|
| | |
|
| | | // short description
|
| | | bool SetMyShortDescription(const string& short_description, const string& language_code);
|
| | | bool GetMyShortDescription(string& short_description);
|
| | |
|
| | | //--- Chat
|
| | | // ?¿
|
| | | bool DeleteChatPhoto();
|
| | | bool SetChatPhoto(const string& photo, bool photo_common);
|
| | | bool SetChatTitle(const string& title);
|
| | | bool SetChatDescription(const string& description);
|
| | |
|
| | | // pin
|
| | | bool PinChatMessage(long message_id, TLGBYLEO_BOOL disable_notification);
|
2026-09-23 15:26:06 -05:00 | | | bool UnpinChatMessage(long message_id);
|
2026-09-22 17:06:21 -05:00 | | | bool UnpinAllChatMessages();
|
| | |
|
| | | // ext
|
| | | bool LeaveChat();
|
| | | bool GetChat();
|
| | | bool GetChatAdministrators(TLGBYLEO_BOOL return_bots);
|
| | | int GetChatMemberCount();
|
| | | bool GetChatMember(long user_id);
|
| | | bool SetChatStickerSet(const string& sticker_set_name);
|
| | | bool DeleteChatStickerSet();
|
| | |
|
| | | //--- Botones (callback qeury response)
|
| | | bool AnswerCallbackQuery(const string& callback_query_id,
|
2026-09-26 08:40:32 -05:00 | | | const string& text, const string& url, TLGBYLEO_BOOL show_alert = TLGBYLEO_BOOL_FALSE, int cache_time = -1);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //--- Poll
|
| | | bool StopPoll(long message_id, uchar& reply_markup[], int reply_markup_s = -2);
|
| | |
|
| | | //--- Delete
|
| | | bool DeleteMessage(long message_id);
|
2026-09-23 17:35:51 -05:00 | | | bool DeleteMessageReaction(long message_id);
|
2026-09-24 13:22:43 -05:00 | | |
|
| | | //---- empty buffers
|
2026-09-26 16:42:14 -05:00 | | | static const uchar EMPTY_BUFFER_JSON[2];
|
2026-09-26 08:40:32 -05:00 | | | static const TlgEphemeralMessageParameters EMPTY_TLG_EPEMERAL;
|
| | | static const TlgReplyParameters EMPTY_TLG_REPLY_PARAMS;
|
| | | static const TlgSendBase EMPTY_TLG_SEND_BASE;
|
| | | static const TlgLinkPreviewOptions EMPTY_LINK_PREVIEW_OPS;
|
2026-09-22 17:06:21 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | CTelegramAPI::CTelegramAPI()
|
2026-09-23 21:33:46 -05:00 | | | : m_token(NULL), m_timeout(5000),
|
2026-09-23 17:35:51 -05:00 | | | // reservamos de golpe 4096 bytes para evitar allocs.... un tamaño decente para empzar en multipar (Documentos)
|
| | | m_multipar_buffer(2, 4096),
|
2026-09-23 21:33:46 -05:00 | | | // en la version dinamico 0 data no la necist como datos apenas unos 512 bytes creo que van sobrado (dado que se usa para coasas pequeñas)
|
| | | m_mulipar_dync(0, 512),
|
2026-09-23 17:35:51 -05:00 | | | m_last_err(TELEGRAMBYLEO_ERR_NOT), m_last_res_web(0), m_url_method(""), m_chat_id(-1)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | }
|
| | |
|
2026-09-24 13:22:43 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-26 16:42:14 -05:00 | | | const uchar CTelegramAPI::EMPTY_BUFFER_JSON[2] = {'{', '}'};
|
2026-09-26 08:40:32 -05:00 | | | const TlgEphemeralMessageParameters CTelegramAPI::EMPTY_TLG_EPEMERAL;
|
| | | const TlgReplyParameters CTelegramAPI::EMPTY_TLG_REPLY_PARAMS;
|
| | | const TlgSendBase CTelegramAPI::EMPTY_TLG_SEND_BASE;
|
| | | const TlgLinkPreviewOptions CTelegramAPI::EMPTY_LINK_PREVIEW_OPS;
|
2026-09-24 13:22:43 -05:00 | | |
|
2026-09-22 17:06:21 -05:00 | | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::Token(string _token)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //---
|
| | | StringTrimRight(_token);
|
| | | StringTrimLeft(_token);
|
| | | if(_token == "")
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_TOKEN_EMPTY;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | m_token = _token;
|
| | | m_url_method = TELEGRAMBYLEO_BASE_URL + "/bot" + m_token + "/";
|
| | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | void CTelegramAPI::ChatId(const long chat_id)
|
2026-09-22 17:06:21 -05:00 | | | {
|
2026-09-23 15:26:06 -05:00 | | | //--- Val
|
2026-09-22 17:06:21 -05:00 | | | m_chat_id = chat_id;
|
| | |
|
2026-09-23 15:26:06 -05:00 | | | //--- Json Builder
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.Clear();
|
| | | m_js_builder.Obj();
|
| | | m_js_builder.KeyWV("chat_id").Val(chat_id);
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.GetSnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- Multipar
|
| | | m_multipar_buffer.Clear();
|
| | | m_multipar_buffer.SetSignedNumber<long, ulong, MULTIPART_TAPPEND>("chat_id", m_chat_id);
|
| | | m_multipar_buffer.Freeze(); // lockea
|
2026-09-22 17:06:21 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::Send(const string &method, CJsonBuilder &raw)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //--- preparativos
|
2026-09-24 13:22:43 -05:00 | | | static string result_headers;
|
2026-09-22 17:06:21 -05:00 | | | raw.Truncate();
|
| | |
|
| | | //--- respuesta vive en el json..
|
2026-09-26 11:41:17 -05:00 | | | #ifdef TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
|
2026-09-25 16:54:01 -05:00 | | | Print(raw.Build());
|
2026-09-26 11:41:17 -05:00 | | | #endif // TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
|
| | |
|
2026-09-24 13:22:43 -05:00 | | | m_last_res_web = WebRequest("POST", m_url_method + method, "Content-Type: application/json\r\n", m_timeout, raw.m_buf, m_json.m_raw, result_headers);
|
2026-09-26 11:41:17 -05:00 | | |
|
| | | #ifdef TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
|
2026-09-26 11:29:53 -05:00 | | | Print(m_last_res_web, " ", CharArrayToString(m_json.m_raw, 0, ArraySize(m_json.m_raw)));
|
2026-09-26 11:41:17 -05:00 | | | #endif // TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | if(m_last_res_web != 200)
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_WEB_REQ;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //--- true..
|
| | | return true;
|
| | | }
|
2026-09-25 22:28:13 -05:00 | | |
|
2026-09-22 17:06:21 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::Send(const string &method, CTsnMultipartRaw &raw)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //--- preparativos
|
2026-09-24 13:22:43 -05:00 | | | static string result_headers;
|
2026-09-25 22:28:13 -05:00 | | |
|
| | | //--- finales
|
| | | raw.Finish();
|
2026-09-22 17:06:21 -05:00 | | | raw.Truncate();
|
| | |
|
| | | //--- respuesta vive en el json..
|
2026-09-24 13:22:43 -05:00 | | | m_last_res_web = WebRequest("POST", m_url_method + method, raw.GetHeaders(), m_timeout, raw.m_raw, m_json.m_raw, result_headers);
|
2026-09-25 22:28:13 -05:00 | | |
|
2026-09-26 08:40:32 -05:00 | | | //Print("resultado raw: ", m_last_res_web);
|
| | | //Print("INICIO: ", DumpBytes(raw.m_raw, 0, 60));
|
| | | //Print("FINAL: ", DumpBytes(raw.m_raw, ArraySize(raw.m_raw) - 60, 60));
|
| | | //Print("TAMAÑO TOTAL: ", ArraySize(raw.m_raw));
|
2026-09-25 22:28:13 -05:00 | | |
|
2026-09-24 13:22:43 -05:00 | | | if(m_last_res_web != 200)
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_WEB_REQ;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //--- true..
|
| | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::Send(const string &method)
|
| | | {
|
| | | //--- preparativos
|
| | | static string result_headers;
|
| | |
|
| | | //--- respuesta vive en el json..
|
2026-09-26 16:42:14 -05:00 | | | m_last_res_web = WebRequest("GET", m_url_method + method, NULL, m_timeout, EMPTY_BUFFER_JSON, m_json.m_raw, result_headers);
|
2026-09-22 17:06:21 -05:00 | | | if(m_last_res_web != 200)
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_WEB_REQ;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //--- true..
|
| | | return true;
|
| | | }
|
| | |
|
2026-09-24 13:22:43 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::GetMe(TlgUser &info)
|
| | | {
|
2026-09-24 14:00:52 -05:00 | | | //---
|
| | | if(!Send(TELEGRAMBYLEO_ENDPOINT_GETME))
|
2026-09-24 13:22:43 -05:00 | | | return false;
|
| | |
|
| | | //---
|
| | | m_json.CalcLen();
|
| | | m_json.CorrectPadding();
|
| | | if(!m_json.Parse())
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_JSON_PARSING;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | CJsonNode root = m_json.GetRoot();
|
| | | if(!root["ok"].ToBool(false))
|
| | | {
|
| | | m_last_err = TELEGRAMBYLEO_ERR_JSON_NOT_OK;
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | CJsonNode result = root["result"];
|
| | |
|
| | | //--- campos basicos
|
| | | info.first_name = result["first_name"].ToString();
|
| | | info.username = result["username"].ToString();
|
| | | info.last_name = result["last_name"].ToString();
|
| | | info.id = result["id"].ToInt(0);
|
| | |
|
| | | //--- flags
|
| | | uint f = 0;
|
| | | f |= result["is_bot"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_IS_BOT) : 0U;
|
| | | f |= result["is_premium"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_IS_PREMIUM) : 0U;
|
| | | f |= result["added_to_attachment_menu"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_ADDED_TO_ATTACHMENT_MENU) : 0U;
|
| | | f |= result["can_join_groups"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_CAN_JOIN_GROUPS) : 0U;
|
| | | f |= result["can_read_all_group_messages"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_CAN_READ_ALL_GROUP_MESSAGES) : 0U;
|
| | | f |= result["supports_guest_queries"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_SUPPORTS_GUEST_QUERIES) : 0U;
|
| | | f |= result["supports_inline_queries"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_SUPPORTS_INLINE_QUERIES) : 0U;
|
| | | f |= result["can_connect_to_business"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_CAN_CONNECT_TO_BUSINESS) : 0U;
|
| | | f |= result["has_main_web_app"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_HAS_MAIN_WEB_APP) : 0U;
|
| | | f |= result["has_topics_enabled"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_HAS_TOPICS_ENABLED) : 0U;
|
| | | f |= result["allows_users_to_create_topics"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_ALLOWS_USERS_TO_CREATE_TOPICS) : 0U;
|
| | | f |= result["can_manage_bots"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_CAN_MANAGE_BOTS) : 0U;
|
| | | f |= result["supports_join_request_queries"].ToBool(false) ? TLGBYLEO_USER_FLAG(TLGBYLEO_USER_SUPPORTS_JOIN_REQUEST_QUERIES) : 0U;
|
| | | info.flags = f;
|
| | | return true;
|
| | | }
|
| | |
|
2026-09-22 17:06:21 -05:00 | | |
|
2026-09-26 16:42:14 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::SendRichMessageMarkdown(const string &markdown, TLGBYLEO_BOOL is_rtl, TLGBYLEO_BOOL skip_entity_detection)
|
| | | {
|
| | | //---
|
| | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
| | | m_js_builder.KeyWV("rich_message").Obj();
|
| | | m_js_builder.KeyWV("markdown").ValS(markdown);
|
| | |
|
| | | //---
|
| | | if(is_rtl != TLGBYLEO_BOOL_TRUE)
|
| | | m_js_builder.KeyWV("is_rtl").Val((is_rtl == TLGBYLEO_BOOL_TRUE));
|
| | | if(skip_entity_detection != TLGBYLEO_BOOL_TRUE)
|
| | | m_js_builder.KeyWV("skip_entity_detection").Val((skip_entity_detection == TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDRICHMESSAGE, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::SendRichMessageMarkdown(const string &markdown, TLGBYLEO_BOOL is_rtl, TLGBYLEO_BOOL skip_entity_detection,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp, const TlgEphemeralMessageParameters& ep,
|
| | | uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
| | | m_js_builder.KeyWV("rich_message").Obj();
|
| | | m_js_builder.KeyWV("markdown").ValS(markdown);
|
| | |
|
| | | //---
|
| | | if(is_rtl != TLGBYLEO_BOOL_TRUE)
|
| | | m_js_builder.KeyWV("is_rtl").Val((is_rtl == TLGBYLEO_BOOL_TRUE));
|
| | | if(skip_entity_detection != TLGBYLEO_BOOL_TRUE)
|
| | | m_js_builder.KeyWV("skip_entity_detection").Val((skip_entity_detection == TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | |
|
| | | //---
|
| | | TELEGRAMBYLEO_COMMONS_CAMPS
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDRICHMESSAGE, m_js_builder);
|
| | | }
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.KeyWV("text").ValS(text);
|
| | |
|
| | | //---
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
2026-09-23 15:26:06 -05:00 | | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDMESSAGE, m_js_builder);
|
2026-09-22 17:06:21 -05:00 | | | }
|
| | |
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode, const TlgSendBase& base,
|
2026-09-23 16:35:15 -05:00 | | | const TlgReplyParameters& rp, const TlgEphemeralMessageParameters& ep, const TlgLinkPreviewOptions& link,
|
| | | uchar& reply_markup[], int reply_markup_s)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-22 17:06:21 -05:00 | | | m_js_builder.KeyWV("text").ValS(text);
|
| | |
|
| | | //-- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-22 17:06:21 -05:00 | | |
|
2026-09-25 21:10:24 -05:00 | | | //-- link_preview_options
|
| | | TELEGRAMBYLEO_LINK_PREVIEW(m_js_builder)
|
2026-09-23 16:35:15 -05:00 | | |
|
2026-09-22 17:06:21 -05:00 | | | //---
|
| | | TELEGRAMBYLEO_COMMONS_CAMPS
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
2026-09-23 15:26:06 -05:00 | | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDMESSAGE, m_js_builder);
|
2026-09-22 17:06:21 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendChatAction(ENUM_TELEGRAMBYLEO_CHAT_ACTION action, long message_thread_id)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("action").ValUWV(g_telegram_chat_action[action].raw, g_telegram_chat_action[action].len);
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //---
|
| | | if(message_thread_id != -1)
|
| | | m_js_builder.KeyWV("message_thread_id").Val(message_thread_id);
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
2026-09-23 15:26:06 -05:00 | | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDCHATACTION, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPollRegular(const string &question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
2026-09-23 15:26:06 -05:00 | | | const TlgInputPollOption &options[], datetime close_date, const string &description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allow_adding_options, TLGBYLEO_BOOL allows_revoting)
|
| | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("question").ValS(question);
|
| | | if(question_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("question_parse_mode").ValUWV(g_telegram_parse_mode_str[question_parse_mode].raw, g_telegram_parse_mode_str[question_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- options
|
| | | TELEGRAMBYLEO_POLL_OPTIONS
|
| | |
|
| | | //--- type fijo
|
| | | m_js_builder.KeyWV("type").ValSWV("regular");
|
| | |
|
| | | //---
|
| | | if(allow_adding_options != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allow_adding_options").Val((allow_adding_options == TLGBYLEO_BOOL_TRUE));
|
| | | if(allows_revoting != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allows_revoting").Val((allows_revoting == TLGBYLEO_BOOL_TRUE));
|
| | | if(close_date != 0)
|
| | | m_js_builder.KeyWV("close_date").Val((long)close_date);
|
2026-09-26 08:40:32 -05:00 | | | if(description.Length())
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | m_js_builder.KeyWV("description").ValS(description);
|
| | | if(description_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("description_parse_mode").ValUWV(g_telegram_parse_mode_str[description_parse_mode].raw, g_telegram_parse_mode_str[description_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPollRegular(const string &question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
2026-09-23 15:26:06 -05:00 | | | const TlgInputPollOption &options[], datetime close_date, const string &description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allow_adding_options, TLGBYLEO_BOOL allows_revoting,
|
| | | const TlgPollBoolOps& bops, const TlgSendBase& base,
|
| | | const TlgReplyParameters& rp, const string &country_codes[], uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("question").ValS(question);
|
| | | if(question_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("question_parse_mode").ValUWV(g_telegram_parse_mode_str[question_parse_mode].raw, g_telegram_parse_mode_str[question_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- options
|
| | | TELEGRAMBYLEO_POLL_OPTIONS
|
| | |
|
| | | //--- type fijo
|
| | | m_js_builder.KeyWV("type").ValSWV("regular");
|
| | |
|
| | | //---
|
| | | if(allow_adding_options != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allow_adding_options").Val((allow_adding_options == TLGBYLEO_BOOL_TRUE));
|
| | | if(allows_revoting != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allows_revoting").Val((allows_revoting == TLGBYLEO_BOOL_TRUE));
|
| | | if(close_date != 0)
|
| | | m_js_builder.KeyWV("close_date").Val((long)close_date);
|
2026-09-26 08:40:32 -05:00 | | | if(description.Length())
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | m_js_builder.KeyWV("description").ValS(description);
|
| | | if(description_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("description_parse_mode").ValUWV(g_telegram_parse_mode_str[description_parse_mode].raw, g_telegram_parse_mode_str[description_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //--- flags de la encuesta
|
| | | TELEGRAMBYLEO_POLL_BOPS
|
| | |
|
| | | //--- paises
|
| | | TELEGRAMBYLEO_POLL_COUNTRY_CODES
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_POLL_COMMONS
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPollQuiz(const string &question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
2026-09-23 15:26:06 -05:00 | | | const TlgInputPollOption &options[], datetime close_date, const string &description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allows_revoting,
|
| | | const string &explanation, ENUM_TELEGRAM_PARSE_MODE explanation_parse_mode, int correct_option_ids)
|
| | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("question").ValS(question);
|
| | | if(question_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("question_parse_mode").ValUWV(g_telegram_parse_mode_str[question_parse_mode].raw, g_telegram_parse_mode_str[question_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- options
|
| | | TELEGRAMBYLEO_POLL_OPTIONS
|
| | |
|
| | | //--- type fijo
|
| | | m_js_builder.KeyWV("type").ValSWV("quiz");
|
| | |
|
| | | //---
|
| | | if(allows_revoting != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allows_revoting").Val((allows_revoting == TLGBYLEO_BOOL_TRUE));
|
| | | if(close_date != 0)
|
| | | m_js_builder.KeyWV("close_date").Val((long)close_date);
|
2026-09-26 08:40:32 -05:00 | | | if(description.Length())
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | m_js_builder.KeyWV("description").ValS(description);
|
| | | if(description_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("description_parse_mode").ValUWV(g_telegram_parse_mode_str[description_parse_mode].raw, g_telegram_parse_mode_str[description_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | | if(correct_option_ids != -1)
|
2026-09-25 16:54:01 -05:00 | | | m_js_builder.KeyWV("correct_option_ids").Arr().Val(correct_option_ids).EndArr();
|
2026-09-26 08:40:32 -05:00 | | | if(explanation.Length())
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | m_js_builder.KeyWV("explanation").ValS(explanation);
|
| | | if(explanation_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("explanation_parse_mode").ValUWV(g_telegram_parse_mode_str[explanation_parse_mode].raw, g_telegram_parse_mode_str[explanation_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPollQuiz(const string &question, ENUM_TELEGRAM_PARSE_MODE question_parse_mode,
|
2026-09-23 15:26:06 -05:00 | | | const TlgInputPollOption &options[], datetime close_date, const string &description,
|
| | | ENUM_TELEGRAM_PARSE_MODE description_parse_mode, TLGBYLEO_BOOL allows_revoting,
|
| | | const string &explanation, ENUM_TELEGRAM_PARSE_MODE explanation_parse_mode, int correct_option_ids,
|
| | | const TlgPollBoolOps& bops, const TlgSendBase& base,
|
| | | const TlgReplyParameters& rp, const string &country_codes[], uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("question").ValS(question);
|
| | | if(question_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("question_parse_mode").ValUWV(g_telegram_parse_mode_str[question_parse_mode].raw, g_telegram_parse_mode_str[question_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- options
|
| | | TELEGRAMBYLEO_POLL_OPTIONS
|
| | |
|
| | | //--- type fijo
|
| | | m_js_builder.KeyWV("type").ValSWV("quiz");
|
| | |
|
| | | //---
|
| | | if(allows_revoting != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("allows_revoting").Val((allows_revoting == TLGBYLEO_BOOL_TRUE));
|
| | | if(close_date != 0)
|
| | | m_js_builder.KeyWV("close_date").Val((long)close_date);
|
2026-09-26 08:40:32 -05:00 | | | if(description.Length())
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | m_js_builder.KeyWV("description").ValS(description);
|
| | | if(description_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("description_parse_mode").ValUWV(g_telegram_parse_mode_str[description_parse_mode].raw, g_telegram_parse_mode_str[description_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | | if(correct_option_ids != -1)
|
2026-09-25 16:54:01 -05:00 | | | m_js_builder.KeyWV("correct_option_ids").Arr().Val(correct_option_ids).EndArr();
|
2026-09-23 15:26:06 -05:00 | | | if(explanation != NULL && explanation != "")
|
| | | {
|
| | | m_js_builder.KeyWV("explanation").ValS(explanation);
|
| | | if(explanation_parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("explanation_parse_mode").ValUWV(g_telegram_parse_mode_str[explanation_parse_mode].raw, g_telegram_parse_mode_str[explanation_parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //--- flags de la encuesta
|
| | | TELEGRAMBYLEO_POLL_BOPS
|
| | |
|
| | | //--- paises
|
| | | TELEGRAMBYLEO_POLL_COUNTRY_CODES
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_POLL_COMMONS
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
|
2026-09-22 17:06:21 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendDocument(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &document, bool common)
|
2026-09-22 17:06:21 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
2026-09-22 17:06:21 -05:00 | | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-22 17:06:21 -05:00 | | | //--- archivo ultimo
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("document", document, common, "application/octet-stream");
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDDOC, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendDocument(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &document, bool common,
|
2026-09-23 15:26:06 -05:00 | | | const string &mime, const string &thumbnail, bool thumbnail_common, const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- archivo (mime custom si se especifica, si no octet-stream)
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("document", document, common,
|
2026-09-26 08:40:32 -05:00 | | | (mime.Length()) ? "application/octet-stream" : mime);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- thumbnail: campo directo, sin attach:// (todo el request ya es multipart,
|
| | | // no un array JSON como en sendMediaGroup donde attach:// si hace falta)
|
2026-09-26 08:40:32 -05:00 | | | if(thumbnail.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("thumbnail", thumbnail, thumbnail_common, "image/jpeg");
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDDOC, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendVideo(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &video, bool common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- archivo
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("video", video, common, "video/mp4");
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDVIDEO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendVideo(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &video, bool common,
|
2026-09-23 15:26:06 -05:00 | | | int duration, int height, int widht,
|
| | | const string &thumbnail, bool thumbnail_common,
|
| | | const string &cover, bool cover_common,
|
| | | int start_timestamp, TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler, TLGBYLEO_BOOL supports_streaming,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- archivo
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("video", video, common, "video/mp4");
|
| | |
|
| | | //--- dimensiones / duracion / cover offset
|
| | | if(duration > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", (uint)duration);
|
| | | if(widht > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("width", (uint)widht);
|
| | | if(height > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("height", (uint)height);
|
| | | if(start_timestamp > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("start_timestamp", (uint)start_timestamp);
|
| | |
|
| | | //--- thumbnail / cover: campo directo, sin attach:// (ver nota en SendDocument)
|
2026-09-26 08:40:32 -05:00 | | | if(thumbnail.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("thumbnail", thumbnail, thumbnail_common, "image/jpeg");
|
2026-09-26 08:40:32 -05:00 | | | if(cover.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("cover", cover, cover_common, "image/jpeg");
|
| | |
|
| | | //--- flags
|
| | | if(show_caption_above_media != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("show_caption_above_media", (show_caption_above_media == TLGBYLEO_BOOL_TRUE));
|
| | | if(has_spoiler != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("has_spoiler", (has_spoiler == TLGBYLEO_BOOL_TRUE));
|
| | | if(supports_streaming != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("supports_streaming", (supports_streaming == TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDVIDEO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendAudio(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &audio, bool audio_common,
|
2026-09-23 15:26:06 -05:00 | | | uint duration, const string &performer, const string &title)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- duracion / metadata
|
| | | if(duration > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", duration);
|
2026-09-26 08:40:32 -05:00 | | | if(performer.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("performer", performer);
|
2026-09-26 08:40:32 -05:00 | | | if(title.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("title", title);
|
| | |
|
| | | //--- archivo
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("audio", audio, audio_common, "audio/mpeg");
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDAUDIO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendAudio(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &audio, bool audio_common,
|
2026-09-23 15:26:06 -05:00 | | | uint duration, const string &performer, const string &title,
|
| | | const string &thumbnail, bool thumbnail_common,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 08:40:32 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- duracion / metadata
|
| | | if(duration > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", duration);
|
2026-09-26 08:40:32 -05:00 | | | if(performer.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("performer", performer);
|
2026-09-26 08:40:32 -05:00 | | | if(title.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("title", title);
|
| | |
|
| | | //--- archivo
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("audio", audio, audio_common, "audio/mpeg");
|
| | |
|
| | | //--- thumbnail
|
2026-09-26 08:40:32 -05:00 | | | if(thumbnail.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("thumbnail", thumbnail, thumbnail_common, "image/jpeg");
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDAUDIO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendVoice(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &voice, bool voice_common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 08:40:32 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- archivo
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("voice", voice, voice_common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDVOICE, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendVoice(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &voice, bool voice_common,
|
2026-09-23 15:26:06 -05:00 | | | int duration,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 08:40:32 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- duracion
|
| | | if(duration > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", (uint)duration);
|
| | |
|
| | | //--- archivo
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("voice", voice, voice_common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
2026-09-22 17:06:21 -05:00 | | |
|
| | | //--- enviamos
|
2026-09-23 15:26:06 -05:00 | | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDVOICE, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendAnimation(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &animation, bool animation_common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 08:40:32 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- archivo
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("animation", animation, animation_common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDANIMATION, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendAnimation(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &animation, bool animation_common,
|
2026-09-23 15:26:06 -05:00 | | | uint duration, uint height, uint widht,
|
| | | const string &thumbnail, bool thumbnail_common,
|
| | | TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 08:40:32 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- archivo
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("animation", animation, animation_common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- dimensiones / duracion
|
| | | if(duration > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", duration);
|
| | | if(widht > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("width", widht);
|
| | | if(height > 0)
|
| | | m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("height", height);
|
| | |
|
| | | //--- thumbnail
|
2026-09-26 08:40:32 -05:00 | | | if(thumbnail.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("thumbnail", thumbnail, thumbnail_common, "image/jpeg");
|
| | |
|
| | | //--- flags
|
| | | if(show_caption_above_media != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("show_caption_above_media", (show_caption_above_media == TLGBYLEO_BOOL_TRUE));
|
| | | if(has_spoiler != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("has_spoiler", (has_spoiler == TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDANIMATION, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPhoto(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &photo, bool common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | | //--- archivo
|
2026-09-25 21:34:44 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPHOTO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SendPhoto(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &photo, bool common,
|
2026-09-23 15:26:06 -05:00 | | | TLGBYLEO_BOOL show_caption_above_media, TLGBYLEO_BOOL has_spoiler,
|
| | | const TlgSendBase& base, const TlgReplyParameters& rp,
|
| | | const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | |
|
| | | //--- caption
|
2026-09-26 11:29:53 -05:00 | | | if(caption.Length())
|
2026-09-23 15:26:06 -05:00 | | | m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
|
| | | //--- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("parse_mode", g_telegram_parse_mode_str[parse_mode].raw, 0, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- archivo
|
2026-09-25 21:34:44 -05:00 | | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, common, "application/octet-stream");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- flags
|
| | | if(show_caption_above_media != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("show_caption_above_media", (show_caption_above_media == TLGBYLEO_BOOL_TRUE));
|
| | | if(has_spoiler != TLGBYLEO_BOOL_UNSET)
|
| | | m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("has_spoiler", (has_spoiler == TLGBYLEO_BOOL_TRUE));
|
| | |
|
| | | //--- comunes
|
| | | TELEGRAMBYLEO_MULTIPART_BASE
|
| | | TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
|
| | | TELEGRAMBYLEO_MULTIPART_RP
|
| | | TELEGRAMBYLEO_MULTIPART_EP
|
| | |
|
| | | //--- enviamos
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SENDPHOTO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 21:33:46 -05:00 | | | //| |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetMyProfilePhoto(const string &photo, bool photo_common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 21:33:46 -05:00 | | | m_mulipar_dync.Clear();
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- InputProfilePhotoStatic: el archivo va aparte + referencia attach://
|
| | | // (aqui si hace falta el attach://, photo va DENTRO de un json, no es
|
| | | // un campo InputFile de primer nivel como en los Send*)
|
2026-09-23 21:33:46 -05:00 | | | m_mulipar_dync.SetFile<MULTIPART_TAPPEND>("photo_file", photo, photo_common, "image/jpeg");
|
| | | m_mulipar_dync.SetStrAscii<MULTIPART_TAPPEND>("photo", "{\"type\":\"static\",\"photo\":\"attach://photo_file\"}");
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //--- enviamos
|
2026-09-23 21:33:46 -05:00 | | | return Send(TELEGRAMBYLEO_ENDPOINT_SETMYPROFILEPHOTO, m_mulipar_dync);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::RemoveMyProfilePhoto(void)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_REMOVEMYPROFILEPHOTO, g_json_builder);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetMyName(const string &name, const string &language_code)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("name").ValS(name);
|
2026-09-23 15:26:06 -05:00 | | | if(language_code != "")
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("language_code").ValSWV(language_code);
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETMYNAME, g_json_builder);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetMyDescription(const string &description, const string &language_code)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("description").ValS(description);
|
2026-09-23 15:26:06 -05:00 | | | if(language_code != "")
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("language_code").ValSWV(language_code);
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETMYDESCRIPTION, g_json_builder);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetMyShortDescription(const string &short_description, const string &language_code)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("short_description").ValS(short_description);
|
2026-09-23 15:26:06 -05:00 | | | if(language_code != "")
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("language_code").ValSWV(language_code);
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETMYSHORTDESC, g_json_builder);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 21:33:46 -05:00 | | | //| |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::DeleteChatPhoto(void)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_DELCHATPHOTO, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetChatPhoto(const string &photo, bool photo_common)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
| | | m_multipar_buffer.RollBack();
|
| | | m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, photo_common, "image/jpeg");
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATPHOTO, m_multipar_buffer);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetChatTitle(const string &title)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("title").ValS(title);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATTITLE, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetChatDescription(const string &description)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("description").ValS(description);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATDESCRIPTION, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::PinChatMessage(long message_id, TLGBYLEO_BOOL disable_notification)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | | if(disable_notification != TLGBYLEO_BOOL_UNSET)
|
| | | m_js_builder.KeyWV("disable_notification").Val((disable_notification == TLGBYLEO_BOOL_TRUE));
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_PINCHATMESSAGE, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::UnpinChatMessage(long message_id)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | if(message_id != -1)
|
| | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_UNPINCHATMESSAGE, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::UnpinAllChatMessages(void)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_UNPINALLCHATMSGS, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::DeleteMessage(long message_id)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_DELMESSAGE, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::DeleteMessageReaction(long message_id)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_DELMESSAGEREACTION, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::LeaveChat(void)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_LEAVECHAT, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetChatStickerSet(const string &sticker_set_name)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("sticker_set_name").ValS(sticker_set_name);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATSTICKERSET, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::DeleteChatStickerSet(void)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_DELCHATSTICKERSET, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 17:35:51 -05:00 | | | //| Reacciones |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::SetMessageReaction(long message_id, TLGBYLEO_BOOL is_big, const TlgReactionType &reactions[])
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | |
|
| | | //--- reacciones: "type" es de la lib (ValSWV), el valor es input del
|
| | | // usuario (emoji / custom_emoji_id) asi que va con ValS
|
| | | m_js_builder.KeyWV("reaction").Arr();
|
| | | for(int i = 0; i < ArraySize(reactions); i++)
|
| | | {
|
| | | m_js_builder.Obj();
|
| | | m_js_builder.KeyWV("type").ValSWV(g_telegrambyleo_reactiontype[reactions[i].type]);
|
| | | if(reactions[i].type == TELEGRAMBYLEO_REACTION_TYPE_EMOJI)
|
| | | m_js_builder.KeyWV("emoji").ValS(reactions[i].value);
|
| | | else
|
| | | m_js_builder.KeyWV("custom_emoji_id").ValS(reactions[i].value);
|
| | | m_js_builder.EndObj();
|
| | | }
|
| | | m_js_builder.EndArr();
|
| | |
|
| | | //---
|
| | | if(is_big != TLGBYLEO_BOOL_UNSET)
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.KeyWV("is_big").Val((is_big == TLGBYLEO_BOOL_TRUE));
|
2026-09-23 15:26:06 -05:00 | | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_SETMESSAGEREACTION, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Miembros |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::BanChatMember(long user_id, datetime until_date, TLGBYLEO_BOOL revoke_messages)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("user_id").Val(user_id);
|
| | | if(until_date != 0)
|
| | | m_js_builder.KeyWV("until_date").Val((long)until_date);
|
| | | if(revoke_messages != TLGBYLEO_BOOL_UNSET)
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.KeyWV("revoke_messages").Val((revoke_messages == TLGBYLEO_BOOL_TRUE));
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_BANCHATMEMBER, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::UnbanChatMember(long user_id, TLGBYLEO_BOOL only_if_banned)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("user_id").Val(user_id);
|
| | | if(only_if_banned != TLGBYLEO_BOOL_UNSET)
|
2026-09-23 17:35:51 -05:00 | | | m_js_builder.KeyWV("only_if_banned").Val((only_if_banned == TLGBYLEO_BOOL_TRUE));
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_UNBANCHATMEMBER, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Botones (callback query response). No depende de chat_id. |
|
| | | //+------------------------------------------------------------------+
|
2026-09-26 08:40:32 -05:00 | | | bool CTelegramAPI::AnswerCallbackQuery(const string& callback_query_id,
|
| | | const string& text, const string& url, TLGBYLEO_BOOL show_alert, int cache_time)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("callback_query_id").ValS(callback_query_id);
|
2026-09-26 08:40:32 -05:00 | | | if(text.Length())
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("text").ValS(text);
|
2026-09-23 15:26:06 -05:00 | | | if(show_alert != TLGBYLEO_BOOL_UNSET)
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("show_alert").Val((show_alert == TLGBYLEO_BOOL_TRUE));
|
2026-09-26 08:40:32 -05:00 | | | if(url.Length())
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("url").ValS(url);
|
2026-09-23 15:26:06 -05:00 | | | if(cache_time != -1)
|
2026-09-23 17:35:51 -05:00 | | | g_json_builder.KeyWV("cache_time").Val(cache_time);
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_ANSWERCALLBACKQUERY, g_json_builder);
|
2026-09-23 15:26:06 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 17:35:51 -05:00 | | | //| Poll |
|
2026-09-23 15:26:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-24 12:18:36 -05:00 | | | bool CTelegramAPI::StopPoll(long message_id, uchar &reply_markup[], int reply_markup_s)
|
2026-09-23 15:26:06 -05:00 | | | {
|
| | | //---
|
2026-09-23 16:35:15 -05:00 | | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("message_id").Val(message_id);
|
2026-09-23 17:35:51 -05:00 | | | if(reply_markup_s > -1)
|
2026-09-23 15:26:06 -05:00 | | | m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup, reply_markup_s);
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_STOPPOLL, m_js_builder);
|
2026-09-22 17:06:21 -05:00 | | | }
|
| | |
|
2026-09-25 21:10:24 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Edicion de mensaje |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::EditMessageText(long message_id, const string &text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
|
2026-09-25 21:34:44 -05:00 | | | const TlgLinkPreviewOptions& link, uchar& reply_markup[], int reply_markup_s)
|
2026-09-25 21:10:24 -05:00 | | | {
|
| | | //---
|
| | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
| | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | | m_js_builder.KeyWV("text").ValS(text);
|
| | |
|
| | | //-- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-25 21:10:24 -05:00 | | |
|
| | | //-- link_preview_options
|
| | | TELEGRAMBYLEO_LINK_PREVIEW(m_js_builder)
|
| | |
|
| | | //-- reply_markup
|
| | | if(reply_markup_s > -1)
|
| | | m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup, reply_markup_s);
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_EDITMESSAGETEXT, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Version con inline_message_id: no depende de chat_id, asi que |
|
| | | //| usamos g_json_builder (scratch) en vez de m_js_builder. |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::EditMessageText(const string &inline_message_id, const string &text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
|
2026-09-25 21:34:44 -05:00 | | | const TlgLinkPreviewOptions& link, uchar& reply_markup[], int reply_markup_s)
|
2026-09-25 21:10:24 -05:00 | | | {
|
| | | //---
|
| | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("inline_message_id").ValS(inline_message_id);
|
| | | g_json_builder.KeyWV("text").ValS(text);
|
| | |
|
| | | //-- parse mode
|
| | | if(parse_mode != WRONG_VALUE)
|
2026-09-25 22:28:13 -05:00 | | | g_json_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
|
2026-09-25 21:10:24 -05:00 | | |
|
| | | //-- link_preview_options
|
| | | TELEGRAMBYLEO_LINK_PREVIEW(g_json_builder)
|
| | |
|
| | | //-- reply_markup
|
| | | if(reply_markup_s > -1)
|
| | | g_json_builder.KeyWV("reply_markup").ValidJson(reply_markup, reply_markup_s);
|
| | |
|
| | | //---
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_EDITMESSAGETEXT, g_json_builder);
|
| | | }
|
| | |
|
2026-09-26 16:42:14 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Edicion de solo el reply_markup |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::EditMessageReplyMarkup(long message_id, uchar &reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | m_js_builder.ApplySnapshot(m_chat_id_snap);
|
| | | m_js_builder.KeyWV("message_id").Val(message_id);
|
| | |
|
| | | //-- reply_markup
|
| | | if(reply_markup_s > -1)
|
| | | m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup, reply_markup_s);
|
| | |
|
| | | //---
|
| | | m_js_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_EDITMESSAGEREPLYMARKUP, m_js_builder);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Version con inline_message_id: no depende de chat_id, asi que |
|
| | | //| usamos g_json_builder (scratch) en vez de m_js_builder. |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTelegramAPI::EditMessageReplyMarkup(const string &inline_message_id, uchar &reply_markup[], int reply_markup_s)
|
| | | {
|
| | | //---
|
| | | g_json_builder.Clear();
|
| | | g_json_builder.Obj();
|
| | | g_json_builder.KeyWV("inline_message_id").ValS(inline_message_id);
|
| | |
|
| | | //-- reply_markup
|
| | | if(reply_markup_s > -1)
|
| | | g_json_builder.KeyWV("reply_markup").ValidJson(reply_markup, reply_markup_s);
|
| | |
|
| | | //---
|
| | | g_json_builder.EndObj();
|
| | | return Send(TELEGRAMBYLEO_ENDPOINT_EDITMESSAGEREPLYMARKUP, g_json_builder);
|
| | | }
|
| | |
|
2026-09-22 17:06:21 -05:00 | | | //---
|
| | | }
|
| | |
|
| | | //---
|
| | | #endif // TELEGRAMBYLEO_SRC_MAIN_API_MQH
|