Discusión sobre el artículo "Cómo crear un bot para Telegram en el lenguaje MQL5" - página 13

 

Buenas tardes.

¿Puede el bot recibir mensajes a través del canal?

He asignado el bot como administrador. Ve los mensajes nuevos, pero el texto es siempre una línea en blanco.

msg.message_text=item["message"]["text"].ToStr();
msg.message_text=StringDecode(msg.message_text);
Aquí es siempre una línea en blanco.
 
leonerd:

Buenas tardes.

¿Puede el bot recibir mensajes a través del canal?

He asignado el bot como administrador. Ve los mensajes nuevos, pero el texto es siempre una línea en blanco.

Aquí siempre es una línea en blanco.

En el campo channel_post todo viene en https://core.telegram.org/bots/api#update.

Estaría bien refinar la clase. Añadiré el campo channel_post_text a CCustomMessage. Y rellenarlo en GetUpdates().

Telegram Bot API
  • core.telegram.org
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ. Recent changes April 14, 2019 Added support for native polls: added the object Poll, the methods sendPoll and stopPoll and the field poll in the Message...
 
            msg.chat_id=item["message"]["chat"]["id"].ToInt();

            msg.chat_first_name=item["message"]["chat"]["first_name"].ToStr();
            msg.chat_first_name=StringDecode(msg.chat_first_name);

            msg.chat_last_name=item["message"]["chat"]["last_name"].ToStr();
            msg.chat_last_name=StringDecode(msg.chat_last_name);

            msg.chat_username=item["message"]["chat"]["username"].ToStr();
            msg.chat_username=StringDecode(msg.chat_username);

            msg.chat_type=item["message"]["chat"]["type"].ToStr();
Solo que por alguna razón para el chat del canal todos estos campos son nulos.
 
leonerd:
Sólo que por alguna razón todos estos campos son nulos para el chat de un canal.

Para un canal debes mirar el campo channel_post, no el campo message. channel_post también es de tipo Mensaje.

Me sale el texto:

msg.channel_post_text=item["channel_post"]["text"].ToStr();
msg.channel_post_text=StringDecode(msg.channel_post_text);

Pero los otros campos no:

msg.channel_post_chat_id=item["channel_post"]["chat"]["id"].ToInt();
//---
msg.channel_post_from_first_name=item["channel_post"]["from"]["first_name"].ToStr();     
msg.channel_post_from_first_name=StringDecode(msg.channel_post_from_first_name);
 
//---
            msg.channel_post_text=item["channel_post"]["text"].ToStr();
            msg.channel_post_text=StringDecode(msg.channel_post_text);

            long msg_id=item["channel_post"]["message_id"].ToInt();
            long msg_date=item["channel_post"]["date"].ToInt();



            //---
            msg.channel_post_chat_id=item["channel_post"]["chat"]["id"].ToInt();
            //---
            msg.channel_post_from_first_name=item["channel_post"]["from"]["first_name"].ToStr();     
            msg.channel_post_from_first_name=StringDecode(msg.channel_post_from_first_name);

Los tres primeros campos reciben el valor. Pero los tres últimos campos (para campos como Chat y De) no reciben el valor. ¿Dónde buscar?
 

Me di cuenta.

channel_post.chat_id - puede ser negativo, y lo tomé por un valor torcido.

channel_post.from.first_name - de - campo opcional, puede ser sin ella. En general, todo está aquí https://core.telegram.org/bots/api#message

Telegram Bot API
  • core.telegram.org
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ. Recent changes April 14, 2019 Added support for native polls: added the object Poll, the methods sendPoll and stopPoll and the field poll in the Message...
 

He intentado este código en OnInit() para enviar un mensaje a mi canal. pero no funciona, ¿puedes darme ejemplo de cómo enviar mensaje a un canal o chat de grupo?

gracias

bot.SendMessage("t.me/BotSignals", "Hello",false,false);

 

Por favor, ayúdame con un consejo. He añadido el permisoconfiguración del terminal. A través del navegador la petición se ejecuta correctamente https://api.telegram.org/bot&lt;token>/sendMessage?chat_id=<id>&text=test.

Las siguientes líneas de código se ejecutan, pero SendMessage devuelve el código de error 5203 (Error como resultado de la ejecución de la petición HTTP). El método bot.GetMe() devuelve el mismo error 5203.

¿Cuál podría ser el problema? Gracias.

      bot.Token("<token>"); //set token
  int _res = bot.SendMessage(<id>, "test"); //tu ID
Bots: An introduction for developers
Bots: An introduction for developers
  • core.telegram.org
Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to our bot API. 1. What can I do with bots? To name just a few things, you could use bots to: Get customized notifications and news. A bot can act as a smart...
 
Gracias a todos. Ya lo he resuelto. Supongo que el problema es la radiofrecuencia y el bloqueo.
 
Hola, he tomado un bot que compartirá las señales a través de un grupo. Pasé el código por MetaEditor, lo cambié y no puedo compilarlo. Tengo muchos errores
Archivos adjuntos:
Screenshot_3.jpg  227 kb