Discussion of article "How to create bots for Telegram in MQL5" - page 3

 

Andrey, thanks for the article!

Can you tell me how to implement sending messages to a bot in the simplest mode - private chats.

It would be possible to send messages to a specific bot via SendMessage().

I have such implementation in another platform, now I'm moving to mt5 and I want to do everything in a similar way.

In Telegram:

- via @BotFather created a bot and received a token.

- Using @MyTelegramID_bot I found out my ID.

Using this token/ID combination, messages are sent to the bot.

Several bots are created, one receives logs, another receives critical errors, the third receives information on transactions. Simple and convenient.

 
Artem Voytenko:

Tell me, how to implement sending messages to bot in the simplest mode - private chats.

In telegram:

- via @BotFather created a bot and received a token.

- Through @MyTelegramID_bot I found out my ID.

With the help of this token/ID mapping, messages are sent to the bot.

Your task can be solved in the following way:

#include <Telegram.mqh>
CCustomBot bot;
//+------------------------------------------------------------------+
void OnStart()
  {
   bot.Token("44444444:BAEBtZLrOnLW5IxkQaYsNxA5iQimPNEMfRk"); //set token
   bot.SendMessage(1111111,"your text"); //1111111 - this is your ID
  }
//+------------------------------------------------------------------+
 
Andrey Voytenko:

Your problem can be solved like this:

Thank you so much! It worked! I was passing my ID as a term to SendMessage and that's why it didn't work )

 
How I can send trades from my MT4 to a custom PHP 
 
Tatu Francis:
How I can send trades from my MT4 to a custom PHP 
It is easy. Use WebRequest function.
 

Andrew, here's another problem.

I have a file ExpertHelper.mqh.

In which I write my functions. Then I connect it in the Expert Advisor and use these functions.

In case of errors and notifications I use similar constructs Print("Error in function ",__FUNCTION__);

But how can I get away from print and use telegram in functions inside the ExpertHelper.mqh file?

What would make the print string actually turn into bot.SendMessage(1111111, "Error in function "+__FUNCTION__);

I can't connect Telegram.mqh in the mqh file, create an instance and then switch it on via OnStart/OnInit, can I?

 

Artem Voytenko:

I can't connect Telegram.mqh in the mqh file, create an instance and then enable it via OnStart/OnInit, can I?

1.Внутри вашего хэдера ExpertHelper.mqh пишем

#include <Telegram.mqh>
CCustomBot bot;

2.Внутри ваших функций в случае ошибки делаем

if(error)
{
 bot.SendMessage(1111111,"Error in function "+__FUNCTION__);
}

3.В эксперте в OnInit указываем

bot.Token("44444444:BAEBtZLrOnLW5IxkQaYsNxA5iQimPNEMfRk");
 
Andrey Voytenko:
Andrew, thank you very much! It worked!
 

How i can call function in Class in OnCalculate? to send screenshot when i need with a button for example

Thank you  

 

Hello, after executing getme_result=bot.GetMe() it gives 4014. But through the query in the browser it outputs{"ok":true, "result":{"id":262104403, "first_name": "InvestorBOT", "username": "investorinfo_bot"}}

Can you tell me what the problem is?

Corrected: It was necessary to add https://api.telegram.org to the list of allowed URLs