Discussão do artigo "Como criar bots para Telegram em MQL5" - página 13

 

Boa tarde.

O bot pode receber mensagens pelo canal?

Atribuí o bot como administrador. Ele vê as novas mensagens, mas o texto é sempre uma linha em branco.

msg.message_text=item["message"]["text"].ToStr();
msg.message_text=StringDecode(msg.message_text);
Aqui, é sempre uma linha em branco.
 
leonerd:

Boa tarde.

O bot pode receber mensagens pelo canal?

Atribuí o bot como administrador. Ele vê novas mensagens, mas o texto é sempre uma linha em branco.

Aqui, é sempre uma linha em branco.

No campo channel_post, tudo vem em https://core.telegram.org/bots/api#update.

Seria bom refinar a classe. Adicionarei o campo channel_post_text ao CCustomMessage. E preenchê-lo em 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();
Só que, por algum motivo, para o bate-papo do canal, todos esses campos são nulos.
 
leonerd:
Só que, por algum motivo, todos esses campos são nulos para o bate-papo de um canal.

Para um canal, você deve examinar o campo channel_post, não o campo message. O channel_post também é do tipo Mensagem.

Eu recebo o texto:

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

Mas os outros campos não são:

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);

Os três primeiros campos recebem o valor. Mas os três últimos campos (para campos como Chat e From) não recebem o valor. Onde procurar?
 

Descobri o problema.

channel_post.chat_id - pode ser negativo, e eu o interpretei como um valor incorreto.

channel_post.from.first_name - from - campo opcional, pode ficar sem ele. Em geral, tudo está aqui 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...
 

Tentei esse código em OnInit() para enviar uma mensagem ao meu canal, mas ele não funciona. Você pode me dar um exemplo de como enviar uma mensagem a um canal ou bate-papo em grupo?

obrigado

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

 

Por favor, me ajude com uma orientação. Adicionei a permissãoconfigurações do terminal. Por meio do navegador, a solicitação é executada com êxito https://api.telegram.org/bot&lt;token>/sendMessage?chat_id=<id>&text=test.

As linhas de código abaixo são executadas, mas SendMessage retorna o código de erro 5203 (Erro como resultado da execução da solicitação HTTP). O método bot.GetMe() retorna o mesmo erro 5203.

Qual poderia ser o problema? Obrigado!

      bot.Token("<token>"); //definir token
  int _res = bot.SendMessage(<id>, "test"); //sua 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...
 
Obrigado a todos! Já descobri o que é. Acho que o problema é a RF e o bloqueio.
 
Olá, criei um bot que compartilha sinais por meio de um grupo. Executei o código no MetaEditor, alterei-o e não consigo compilá-lo. Recebi muitos erros
Arquivos anexados:
Screenshot_3.jpg  227 kb