forked from nique_372/TelegramByLeo
1867 lines
88 KiB
MQL5
1867 lines
88 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| 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
| |
{
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// 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)
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#define TELEGRAMBYLEO_COMMONS_CAMPS \
| |
if(reply_markup_s>-1) \
| |
m_js_builder.KeyWV("reply_markup").ValidJson(reply_markup \
| |
,reply_markup_s); \
| |
\
| |
if(base.allow_paid_broadcast!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("allow_paid_broadcast").Val( \
| |
(base.allow_paid_broadcast==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("disable_notification").Val( \
| |
(base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("protect_content").Val( \
| |
(base.protect_content==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.message_thread_id != -1 && base.message_thread_id != 1) \
| |
m_js_builder.KeyWV("message_thread_id").Val(base.message_thread_id); \
| |
\
| |
m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
| |
m_js_builder.KeyWV("reply_parameters").Obj(); \
| |
int obj = m_js_builder.m_pos; \
| |
\
| |
if(rp.poll_option_id.Length()) \
| |
m_js_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
| |
\
| |
if(rp.quote.Length()) \
| |
m_js_builder.KeyWV("quote").ValS(rp.quote); \
| |
\
| |
if(rp.quote_parse_mode != WRONG_VALUE) \
| |
m_js_builder.KeyWV("quote_parse_mode") \
| |
.ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, \
| |
g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
| |
\
| |
if(rp.message_id != -1) \
| |
m_js_builder.KeyWV("message_id").Val(rp.message_id); \
| |
\
| |
if(rp.ephemeral_message_id != -1) \
| |
m_js_builder.KeyWV("ephemeral_message_id") \
| |
.Val(rp.ephemeral_message_id); \
| |
\
| |
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)); \
| |
\
| |
if(rp.quote_position != -1) \
| |
m_js_builder.KeyWV("quote_position").Val(rp.quote_position); \
| |
\
| |
if(rp.checklist_task_id != -1) \
| |
m_js_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
| |
\
| |
if(obj < m_js_builder.m_pos) \
| |
m_js_builder.EndObj(); \
| |
else \
| |
m_js_builder.ApplySnapshot(m_jsonbuilder_lock); \
| |
\
| |
m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
| |
m_js_builder.KeyWV("ephemeral_message_parameters").Obj(); \
| |
obj = m_js_builder.m_pos; \
| |
\
| |
if(ep.callback_query_id.Length()) \
| |
m_js_builder.KeyWV("callback_query_id").ValS(ep.callback_query_id); \
| |
\
| |
if(ep.receiver_user_id!=-1) \
| |
m_js_builder.KeyWV("receiver_user_id").Val(ep.receiver_user_id); \
| |
\
| |
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)); \
| |
\
| |
if(obj < m_js_builder.m_pos) \
| |
m_js_builder.EndObj(); \
| |
else \
| |
m_js_builder.ApplySnapshot(m_jsonbuilder_lock);
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
//- 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) \
| |
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); \
| |
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)); \
| |
\
| |
if(bops.allows_multiple_answers != TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("allows_multiple_answers").Val( \
| |
(bops.allows_multiple_answers==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(bops.shuffle_options != TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("shuffle_options").Val( \
| |
(bops.shuffle_options==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
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)); \
| |
\
| |
if(bops.members_only != TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("members_only").Val( \
| |
(bops.members_only==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
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) \
| |
{ \
| |
m_js_builder.KeyWV("country_codes").Arr(); \
| |
for(int __i = 0; __i < ArraySize(country_codes); __i++) \
| |
m_js_builder.ValSWV(country_codes[__i]); \
| |
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); \
| |
\
| |
if(base.allow_paid_broadcast!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("allow_paid_broadcast").Val( \
| |
(base.allow_paid_broadcast==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("disable_notification").Val( \
| |
(base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
| |
m_js_builder.KeyWV("protect_content").Val( \
| |
(base.protect_content==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.message_thread_id != -1 && base.message_thread_id != 1) \
| |
m_js_builder.KeyWV("message_thread_id").Val(base.message_thread_id); \
| |
\
| |
m_js_builder.GetSnapshot(m_jsonbuilder_lock); \
| |
m_js_builder.KeyWV("reply_parameters").Obj(); \
| |
int __obj_rp = m_js_builder.m_pos; \
| |
\
| |
if(rp.poll_option_id.Length()) \
| |
m_js_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
| |
\
| |
if(rp.quote.Length()) \
| |
m_js_builder.KeyWV("quote").ValS(rp.quote); \
| |
\
| |
if(rp.quote_parse_mode != WRONG_VALUE) \
| |
m_js_builder.KeyWV("quote_parse_mode") \
| |
.ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, \
| |
g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
| |
\
| |
if(rp.message_id != -1) \
| |
m_js_builder.KeyWV("message_id").Val(rp.message_id); \
| |
\
| |
if(rp.ephemeral_message_id != -1) \
| |
m_js_builder.KeyWV("ephemeral_message_id") \
| |
.Val(rp.ephemeral_message_id); \
| |
\
| |
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)); \
| |
\
| |
if(rp.quote_position != -1) \
| |
m_js_builder.KeyWV("quote_position").Val(rp.quote_position); \
| |
\
| |
if(rp.checklist_task_id != -1) \
| |
m_js_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
| |
\
| |
if(__obj_rp < m_js_builder.m_pos) \
| |
m_js_builder.EndObj(); \
| |
else \
| |
m_js_builder.ApplySnapshot(m_jsonbuilder_lock);
| |
| |
//+------------------------------------------------------------------+
| |
//| 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); \
| |
\
| |
if(base.disable_notification!=TLGBYLEO_BOOL_UNSET) \
| |
m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("disable_notification", \
| |
(base.disable_notification==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(base.protect_content!=TLGBYLEO_BOOL_UNSET) \
| |
m_multipar_buffer.SetBool<MULTIPART_TAPPEND>("protect_content", \
| |
(base.protect_content==TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
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; \
| |
\
| |
if(rp.poll_option_id.Length()) \
| |
g_json_builder.KeyWV("poll_option_id").ValS(rp.poll_option_id); \
| |
\
| |
if(rp.quote.Length()) \
| |
g_json_builder.KeyWV("quote").ValS(rp.quote); \
| |
\
| |
if(rp.quote_parse_mode != WRONG_VALUE) \
| |
g_json_builder.KeyWV("quote_parse_mode") \
| |
.ValUWV(g_telegram_parse_mode_str[rp.quote_parse_mode].raw, g_telegram_parse_mode_str[rp.quote_parse_mode].len); \
| |
\
| |
if(rp.message_id != -1) \
| |
g_json_builder.KeyWV("message_id").Val(rp.message_id); \
| |
\
| |
if(rp.ephemeral_message_id != -1) \
| |
g_json_builder.KeyWV("ephemeral_message_id").Val(rp.ephemeral_message_id); \
| |
\
| |
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)); \
| |
\
| |
if(rp.quote_position != -1) \
| |
g_json_builder.KeyWV("quote_position").Val(rp.quote_position); \
| |
\
| |
if(rp.checklist_task_id != -1) \
| |
g_json_builder.KeyWV("checklist_task_id").Val(rp.checklist_task_id); \
| |
\
| |
if(__obj_rp < g_json_builder.m_pos) \
| |
{ \
| |
g_json_builder.EndObj(); \
| |
m_multipar_buffer.SetBuffer<MULTIPART_TAPPEND>("reply_parameters", \
| |
g_json_builder.m_buf, 0, g_json_builder.m_pos); \
| |
}
| |
| |
//- TlgEphemeralMessageParameters
| |
#define TELEGRAMBYLEO_MULTIPART_EP \
| |
g_json_builder.Clear(); \
| |
g_json_builder.Obj(); \
| |
int __obj_ep = g_json_builder.m_pos; \
| |
\
| |
if(ep.callback_query_id.Length()) \
| |
g_json_builder.KeyWV("callback_query_id").ValS(ep.callback_query_id); \
| |
\
| |
if(ep.receiver_user_id!=-1) \
| |
g_json_builder.KeyWV("receiver_user_id").Val(ep.receiver_user_id); \
| |
\
| |
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)); \
| |
\
| |
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); \
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#define TELEGRAMBYLEO_LINK_PREVIEW(builder) \
| |
builder.GetSnapshot(m_jsonbuilder_lock); \
| |
builder.KeyWV("link_preview_options").Obj(); \
| |
int __lp_obj = builder.m_pos; \
| |
\
| |
if(link.is_disabled != TLGBYLEO_BOOL_UNSET) \
| |
builder.KeyWV("is_disabled").Val((link.is_disabled == TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(link.url != "") \
| |
builder.KeyWV("url").ValS(link.url); \
| |
\
| |
if(link.prefer_small_media != TLGBYLEO_BOOL_UNSET) \
| |
builder.KeyWV("prefer_small_media").Val((link.prefer_small_media == TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(link.prefer_large_media != TLGBYLEO_BOOL_UNSET) \
| |
builder.KeyWV("prefer_large_media").Val((link.prefer_large_media == TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(link.show_above_text != TLGBYLEO_BOOL_UNSET) \
| |
builder.KeyWV("show_above_text").Val((link.show_above_text == TLGBYLEO_BOOL_TRUE)); \
| |
\
| |
if(__lp_obj < builder.m_pos) \
| |
builder.EndObj(); \
| |
else \
| |
builder.ApplySnapshot(m_jsonbuilder_lock);
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CTelegramAPI : public CTelegramHandler
| |
{
| |
protected:
| |
//--- Principal
| |
long m_chat_id; // ChatId fijo
| |
JsonBuilderSnapshot m_chat_id_snap; // ChatId lock (pos+sp+stack_first)
| |
string m_url_method; // URL ya lista
| |
string m_token; // Token del bot
| |
int m_timeout; // Timeout
| |
ENUM_TELEGRAMBYLEO_ERR m_last_err; // Ultimo err
| |
int m_last_res_web; // Ultimo err en web
| |
| |
//----
| |
JsonBuilderSnapshot m_jsonbuilder_lock;
| |
| |
//--- Parsing
| |
CJsonParser m_json; // Json que se usa para gettters* aqui
| |
| |
// unsafe de usar.. si lo tcoas ten cuidado con lo qeu haces (cualquier desincroniacion = JSON Malformado solo para experimentados)
| |
CTsnMultipartRaw m_multipar_buffer; // Multipar buffer con lock
| |
CJsonBuilder m_js_builder; // Json Builder
| |
| |
public:
| |
//---
| |
CTsnMultipartRaw m_mulipar_dync; // Version dinamica (no lockea)
| |
| |
public:
| |
CTelegramAPI();
| |
~CTelegramAPI(void) {}
| |
| |
//--- Miembros
| |
//- 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; }
| |
| |
//- timeout
| |
void Timeout(int value) { m_timeout = value; }
| |
__forceinline int Timeout() const { return m_timeout; }
| |
| |
//--- Last Err
| |
__forceinline ENUM_TELEGRAMBYLEO_ERR LastErr() const { return m_last_err; }
| |
int LastResHttp() const { return m_last_res_web; }
| |
| |
| |
//--- Send general
| |
bool Send(const string& method, CJsonBuilder &raw);
| |
bool Send(const string& method, CTsnMultipartRaw& raw);
| |
bool Send(const string& method); // GET
| |
| |
//--- Send
| |
//-- 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);
| |
| |
//-- 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,
| |
const string& explanation, ENUM_TELEGRAM_PARSE_MODE explanation_parse_mode, int correct_option_ids,
| |
// 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,
| |
uint duration, const string& performer, const string& title);
| |
| |
bool SendAudio(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& audio, bool audio_common,
| |
uint duration, const string& performer, const string& title,
| |
// 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
| |
const TlgSendBase& base, const TlgReplyParameters& rp,
| |
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);
| |
bool SendAnimation(const string& caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string& animation, bool animation_common,
| |
// extra
| |
uint duration, uint height, uint widht,
| |
const string& thumbnail, bool thumbnail_common,
| |
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
| |
);
| |
| |
//-- 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);
| |
| |
//--- 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);
| |
| |
//--- 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);
| |
// version con inline message id
| |
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);
| |
| |
//--- 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);
| |
| |
| |
//--- Yo
| |
//-- user
| |
bool GetMe(TlgUser& info);
| |
| |
// 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);
| |
bool UnpinChatMessage(long message_id);
| |
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,
| |
const string& text, const string& url, TLGBYLEO_BOOL show_alert = TLGBYLEO_BOOL_FALSE, int cache_time = -1);
| |
| |
//--- Poll
| |
bool StopPoll(long message_id, uchar& reply_markup[], int reply_markup_s = -2);
| |
| |
//--- Delete
| |
bool DeleteMessage(long message_id);
| |
bool DeleteMessageReaction(long message_id);
| |
| |
//---- empty buffers
| |
static const uchar EMPTY_BUFFER_JSON[2];
| |
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;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CTelegramAPI::CTelegramAPI()
| |
: m_token(NULL), m_timeout(5000),
| |
// reservamos de golpe 4096 bytes para evitar allocs.... un tamaño decente para empzar en multipar (Documentos)
| |
m_multipar_buffer(2, 4096),
| |
// 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),
| |
m_last_err(TELEGRAMBYLEO_ERR_NOT), m_last_res_web(0), m_url_method(""), m_chat_id(-1)
| |
{
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
const uchar CTelegramAPI::EMPTY_BUFFER_JSON[2] = {'{', '}'};
| |
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;
| |
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::Token(string _token)
| |
{
| |
//---
| |
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;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CTelegramAPI::ChatId(const long chat_id)
| |
{
| |
//--- Val
| |
m_chat_id = chat_id;
| |
| |
//--- Json Builder
| |
m_js_builder.Clear();
| |
m_js_builder.Obj();
| |
m_js_builder.KeyWV("chat_id").Val(chat_id);
| |
m_js_builder.GetSnapshot(m_chat_id_snap);
| |
| |
//--- Multipar
| |
m_multipar_buffer.Clear();
| |
m_multipar_buffer.SetSignedNumber<long, ulong, MULTIPART_TAPPEND>("chat_id", m_chat_id);
| |
m_multipar_buffer.Freeze(); // lockea
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::Send(const string &method, CJsonBuilder &raw)
| |
{
| |
//--- preparativos
| |
static string result_headers;
| |
raw.Truncate();
| |
| |
//--- respuesta vive en el json..
| |
#ifdef TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
| |
Print(raw.Build());
| |
#endif // TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
| |
| |
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);
| |
| |
#ifdef TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
| |
Print(m_last_res_web, " ", CharArrayToString(m_json.m_raw, 0, ArraySize(m_json.m_raw)));
| |
#endif // TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
| |
| |
if(m_last_res_web != 200)
| |
{
| |
m_last_err = TELEGRAMBYLEO_ERR_WEB_REQ;
| |
return false;
| |
}
| |
| |
//--- true..
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::Send(const string &method, CTsnMultipartRaw &raw)
| |
{
| |
//--- preparativos
| |
static string result_headers;
| |
| |
//--- finales
| |
raw.Finish();
| |
raw.Truncate();
| |
| |
//--- respuesta vive en el json..
| |
m_last_res_web = WebRequest("POST", m_url_method + method, raw.GetHeaders(), m_timeout, raw.m_raw, m_json.m_raw, result_headers);
| |
| |
//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));
| |
| |
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..
| |
m_last_res_web = WebRequest("GET", m_url_method + method, NULL, m_timeout, EMPTY_BUFFER_JSON, m_json.m_raw, result_headers);
| |
if(m_last_res_web != 200)
| |
{
| |
m_last_err = TELEGRAMBYLEO_ERR_WEB_REQ;
| |
return false;
| |
}
| |
| |
//--- true..
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::GetMe(TlgUser &info)
| |
{
| |
//---
| |
if(!Send(TELEGRAMBYLEO_ENDPOINT_GETME))
| |
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;
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
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_UNSET)
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("text").ValS(text);
| |
| |
//---
| |
if(parse_mode != WRONG_VALUE)
| |
m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDMESSAGE, m_js_builder);
| |
}
| |
| |
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendMessage(const string& text, ENUM_TELEGRAM_PARSE_MODE parse_mode, const TlgSendBase& base,
| |
const TlgReplyParameters& rp, const TlgEphemeralMessageParameters& ep, const TlgLinkPreviewOptions& link,
| |
uchar& reply_markup[], int reply_markup_s)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("text").ValS(text);
| |
| |
//-- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
| |
| |
//-- link_preview_options
| |
TELEGRAMBYLEO_LINK_PREVIEW(m_js_builder)
| |
| |
//---
| |
TELEGRAMBYLEO_COMMONS_CAMPS
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDMESSAGE, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendChatAction(ENUM_TELEGRAMBYLEO_CHAT_ACTION action, long message_thread_id)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("action").ValUWV(g_telegram_chat_action[action].raw, g_telegram_chat_action[action].len);
| |
| |
//---
| |
if(message_thread_id != -1)
| |
m_js_builder.KeyWV("message_thread_id").Val(message_thread_id);
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDCHATACTION, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::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)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("question").ValS(question);
| |
if(question_parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- 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);
| |
if(description.Length())
| |
{
| |
m_js_builder.KeyWV("description").ValS(description);
| |
if(description_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::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,
| |
const TlgPollBoolOps& bops, const TlgSendBase& base,
| |
const TlgReplyParameters& rp, const string &country_codes[], uchar& reply_markup[], int reply_markup_s)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("question").ValS(question);
| |
if(question_parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- 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);
| |
if(description.Length())
| |
{
| |
m_js_builder.KeyWV("description").ValS(description);
| |
if(description_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
| |
//--- 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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::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)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("question").ValS(question);
| |
if(question_parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- 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);
| |
if(description.Length())
| |
{
| |
m_js_builder.KeyWV("description").ValS(description);
| |
if(description_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
if(correct_option_ids != -1)
| |
m_js_builder.KeyWV("correct_option_ids").Arr().Val(correct_option_ids).EndArr();
| |
if(explanation.Length())
| |
{
| |
m_js_builder.KeyWV("explanation").ValS(explanation);
| |
if(explanation_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDPOLL, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::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,
| |
const TlgPollBoolOps& bops, const TlgSendBase& base,
| |
const TlgReplyParameters& rp, const string &country_codes[], uchar& reply_markup[], int reply_markup_s)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("question").ValS(question);
| |
if(question_parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- 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);
| |
if(description.Length())
| |
{
| |
m_js_builder.KeyWV("description").ValS(description);
| |
if(description_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
if(correct_option_ids != -1)
| |
m_js_builder.KeyWV("correct_option_ids").Arr().Val(correct_option_ids).EndArr();
| |
if(explanation != NULL && explanation != "")
| |
{
| |
m_js_builder.KeyWV("explanation").ValS(explanation);
| |
if(explanation_parse_mode != WRONG_VALUE)
| |
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);
| |
}
| |
| |
//--- 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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendDocument(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &document, bool common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- archivo ultimo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("document", document, common, "application/octet-stream");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDDOC, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendDocument(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &document, bool common,
| |
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
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- archivo (mime custom si se especifica, si no octet-stream)
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("document", document, common,
| |
(mime.Length()) ? "application/octet-stream" : mime);
| |
| |
//--- thumbnail: campo directo, sin attach:// (todo el request ya es multipart,
| |
// no un array JSON como en sendMediaGroup donde attach:// si hace falta)
| |
if(thumbnail.Length())
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendVideo(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &video, bool common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("video", video, common, "video/mp4");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDVIDEO, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendVideo(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &video, bool common,
| |
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
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- 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)
| |
if(thumbnail.Length())
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("thumbnail", thumbnail, thumbnail_common, "image/jpeg");
| |
if(cover.Length())
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendAudio(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &audio, bool audio_common,
| |
uint duration, const string &performer, const string &title)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- duracion / metadata
| |
if(duration > 0)
| |
m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", duration);
| |
if(performer.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("performer", performer);
| |
if(title.Length())
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendAudio(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &audio, bool audio_common,
| |
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
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- duracion / metadata
| |
if(duration > 0)
| |
m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", duration);
| |
if(performer.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("performer", performer);
| |
if(title.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("title", title);
| |
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("audio", audio, audio_common, "audio/mpeg");
| |
| |
//--- thumbnail
| |
if(thumbnail.Length())
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendVoice(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &voice, bool voice_common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("voice", voice, voice_common, "application/octet-stream");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDVOICE, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendVoice(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &voice, bool voice_common,
| |
int duration,
| |
const TlgSendBase& base, const TlgReplyParameters& rp,
| |
const TlgEphemeralMessageParameters& ep, uchar& reply_markup[], int reply_markup_s)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- duracion
| |
if(duration > 0)
| |
m_multipar_buffer.SetUnsignedNumber<uint, MULTIPART_TAPPEND>("duration", (uint)duration);
| |
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("voice", voice, voice_common, "application/octet-stream");
| |
| |
//--- comunes
| |
TELEGRAMBYLEO_MULTIPART_BASE
| |
TELEGRAMBYLEO_MULTIPART_REPLY_MARKUP
| |
TELEGRAMBYLEO_MULTIPART_RP
| |
TELEGRAMBYLEO_MULTIPART_EP
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDVOICE, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendAnimation(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &animation, bool animation_common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("animation", animation, animation_common, "application/octet-stream");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDANIMATION, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendAnimation(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &animation, bool animation_common,
| |
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
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("animation", animation, animation_common, "application/octet-stream");
| |
| |
//--- 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
| |
if(thumbnail.Length())
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendPhoto(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &photo, bool common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
| |
//--- caption
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, common, "application/octet-stream");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SENDPHOTO, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SendPhoto(const string &caption, ENUM_TELEGRAM_PARSE_MODE parse_mode, const string &photo, bool 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
| |
if(caption.Length())
| |
m_multipar_buffer.SetStr<MULTIPART_TAPPEND>("caption", caption);
| |
//--- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
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);
| |
| |
//--- archivo
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, common, "application/octet-stream");
| |
| |
//--- 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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetMyProfilePhoto(const string &photo, bool photo_common)
| |
{
| |
//---
| |
m_mulipar_dync.Clear();
| |
| |
//--- 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*)
| |
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\"}");
| |
| |
//--- enviamos
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETMYPROFILEPHOTO, m_mulipar_dync);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::RemoveMyProfilePhoto(void)
| |
{
| |
//---
| |
g_json_builder.Clear();
| |
g_json_builder.Obj();
| |
g_json_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_REMOVEMYPROFILEPHOTO, g_json_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetMyName(const string &name, const string &language_code)
| |
{
| |
//---
| |
g_json_builder.Clear();
| |
g_json_builder.Obj();
| |
g_json_builder.KeyWV("name").ValS(name);
| |
if(language_code != "")
| |
g_json_builder.KeyWV("language_code").ValSWV(language_code);
| |
g_json_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETMYNAME, g_json_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetMyDescription(const string &description, const string &language_code)
| |
{
| |
//---
| |
g_json_builder.Clear();
| |
g_json_builder.Obj();
| |
g_json_builder.KeyWV("description").ValS(description);
| |
if(language_code != "")
| |
g_json_builder.KeyWV("language_code").ValSWV(language_code);
| |
g_json_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETMYDESCRIPTION, g_json_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetMyShortDescription(const string &short_description, const string &language_code)
| |
{
| |
//---
| |
g_json_builder.Clear();
| |
g_json_builder.Obj();
| |
g_json_builder.KeyWV("short_description").ValS(short_description);
| |
if(language_code != "")
| |
g_json_builder.KeyWV("language_code").ValSWV(language_code);
| |
g_json_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETMYSHORTDESC, g_json_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::DeleteChatPhoto(void)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_DELCHATPHOTO, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetChatPhoto(const string &photo, bool photo_common)
| |
{
| |
//---
| |
m_multipar_buffer.RollBack();
| |
m_multipar_buffer.SetFile<MULTIPART_TAPPEND>("photo", photo, photo_common, "image/jpeg");
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATPHOTO, m_multipar_buffer);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetChatTitle(const string &title)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("title").ValS(title);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATTITLE, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetChatDescription(const string &description)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("description").ValS(description);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATDESCRIPTION, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::PinChatMessage(long message_id, TLGBYLEO_BOOL disable_notification)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::UnpinChatMessage(long message_id)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::UnpinAllChatMessages(void)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_UNPINALLCHATMSGS, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::DeleteMessage(long message_id)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("message_id").Val(message_id);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_DELMESSAGE, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::DeleteMessageReaction(long message_id)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("message_id").Val(message_id);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_DELMESSAGEREACTION, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::LeaveChat(void)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_LEAVECHAT, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetChatStickerSet(const string &sticker_set_name)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("sticker_set_name").ValS(sticker_set_name);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETCHATSTICKERSET, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::DeleteChatStickerSet(void)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_DELCHATSTICKERSET, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Reacciones |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::SetMessageReaction(long message_id, TLGBYLEO_BOOL is_big, const TlgReactionType &reactions[])
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
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)
| |
m_js_builder.KeyWV("is_big").Val((is_big == TLGBYLEO_BOOL_TRUE));
| |
| |
//---
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_SETMESSAGEREACTION, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Miembros |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::BanChatMember(long user_id, datetime until_date, TLGBYLEO_BOOL revoke_messages)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
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)
| |
m_js_builder.KeyWV("revoke_messages").Val((revoke_messages == TLGBYLEO_BOOL_TRUE));
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_BANCHATMEMBER, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::UnbanChatMember(long user_id, TLGBYLEO_BOOL only_if_banned)
| |
{
| |
//---
| |
m_js_builder.ApplySnapshot(m_chat_id_snap);
| |
m_js_builder.KeyWV("user_id").Val(user_id);
| |
if(only_if_banned != TLGBYLEO_BOOL_UNSET)
| |
m_js_builder.KeyWV("only_if_banned").Val((only_if_banned == TLGBYLEO_BOOL_TRUE));
| |
m_js_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_UNBANCHATMEMBER, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Botones (callback query response). No depende de chat_id. |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::AnswerCallbackQuery(const string& callback_query_id,
| |
const string& text, const string& url, TLGBYLEO_BOOL show_alert, int cache_time)
| |
{
| |
//---
| |
g_json_builder.Clear();
| |
g_json_builder.Obj();
| |
g_json_builder.KeyWV("callback_query_id").ValS(callback_query_id);
| |
if(text.Length())
| |
g_json_builder.KeyWV("text").ValS(text);
| |
if(show_alert != TLGBYLEO_BOOL_UNSET)
| |
g_json_builder.KeyWV("show_alert").Val((show_alert == TLGBYLEO_BOOL_TRUE));
| |
if(url.Length())
| |
g_json_builder.KeyWV("url").ValS(url);
| |
if(cache_time != -1)
| |
g_json_builder.KeyWV("cache_time").Val(cache_time);
| |
g_json_builder.EndObj();
| |
return Send(TELEGRAMBYLEO_ENDPOINT_ANSWERCALLBACKQUERY, g_json_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Poll |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::StopPoll(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);
| |
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_STOPPOLL, m_js_builder);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Edicion de mensaje |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramAPI::EditMessageText(long message_id, const string &text, ENUM_TELEGRAM_PARSE_MODE parse_mode,
| |
const TlgLinkPreviewOptions& link, uchar& reply_markup[], int reply_markup_s)
| |
{
| |
//---
| |
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)
| |
m_js_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
| |
| |
//-- 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,
| |
const TlgLinkPreviewOptions& link, 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);
| |
g_json_builder.KeyWV("text").ValS(text);
| |
| |
//-- parse mode
| |
if(parse_mode != WRONG_VALUE)
| |
g_json_builder.KeyWV("parse_mode").ValUWV(g_telegram_parse_mode_str[parse_mode].raw, g_telegram_parse_mode_str[parse_mode].len);
| |
| |
//-- 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);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| 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);
| |
}
| |
| |
//---
| |
}
| |
| |
//---
| |
#endif // TELEGRAMBYLEO_SRC_MAIN_API_MQH
|