MQL5 to Telegram

 

Hello guys,

I've found a way to send out trade details from MT5 to telegra using the following function (Sorry I can't find where I got this from!):

void telegram_send(string token, string chat_id, string message)
  {
   string cookie=NULL,headers;
   char post[],result[];
   int res;
  
   string base_url="https://api.telegram.org";
   string url=base_url+"/bot"+token+"/sendMessage?chat_id="+chat_id+"&text="+message;
  
   ResetLastError();
  
   int timeout=2000;
   res=WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers);

   if(res==-1)
     {
      int error_code = GetLastError();
      Print("Error in WebRequest. Error code: ",error_code);
      if(error_code==4060)
        {
         MessageBox("Add the address '"+base_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONERROR);
        }
      else
        {
         MessageBox("Access to the server is not possible.\nCode: "+IntegerToString(error_code),"Error",MB_ICONERROR);
        }
     }
   else
     {
      MessageBox("The message sent successfully.\nResult: "+CharArrayToString(result),"Success",MB_ICONINFORMATION);
     }
  }
  

This works abolutely fine.


The problem however is that "\n" seems to not work when sending to telegram, but works fine with the Send Notification Function;

string message = "Hello" + "\n" + "World";

SendNotification(message); // Works




telegram_send(string token, string chat_id, string message) // does not work

Any ideas why this doesnt work with the telegram function? It is just the "\n" that stops the telegram_send from working

 
Try \r\n instead of just \n.

 
Dominik Christian Egert #:
Try \r\n instead of just \n.

Unfortunately this doesnt work either :(

 
Since you are sending the message as part of the url, you will need to encode the message in base64. At least that's what I would expect. Else you'll need to send it as payload (post data) with the get request.


 
Benjamin David Hardman #:

Unfortunately this doesnt work either :(

use  "%0A" to change "\n"