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

 
Andrey Voytenko:

ok. But if you are working with a private channel, use the Channel ID, not the Channel Name.

Hello Andrey


your library for mt5 seems cannot work under Asynchronous MODE with telegram


when mt5 bot  send two message at the same seconds , one of the mesages will be lost .


I tested many times . could you look into this issue ?

 

Hi andrey


Thank you very much first of all for your time and for your article has helped me a lot and I have read all the publications.

Reading between them I have finally been able to work with the "Telegram_Bot_EA" in to MT5.

Trying "Telegram_Signal_EA" in to MT5, I have not managed to send any signal with either "MA" or "MACD" or with a custom indicator.

The compilation works well but does not send an alert or message.However I know that it is well configured since I have been able to work with "Telegram_Bot_EA".

I have reviewed the code both the EA and the telegram.mqh I do not see where the fault may be and I am stuck.The EA( Telegram_Signal_EA) cant be send any text info.

Could you help me?Its same files that original article.

In this forum i see this code but i think its not my problem:

   //+------------------------------------------------------------------+
   int SendMessage(const string _channel_name,
                   const string _text,
                   const bool   _as_HTML=false,
                   const bool   _silently=false)
     {
      //--- check token
      if(m_token==NULL)
         return(ERR_TOKEN_ISEMPTY);

      string name=StringTrim(_channel_name);
      if(StringGetCharacter(name,0)!='@')
         name="@"+name;

      string out;
      string url=StringFormat("%s/bot%s/sendMessage",TELEGRAM_BASE_URL,m_token);
      string params=StringFormat("chat_id=%s&text=%s",name,UrlEncode(_text));
      if(_as_HTML)
         params+="&parse_mode=HTML";
      if(_silently)
         params+="&disable_notification=true";
      //      Print(params);
      int res=PostRequest(out,url,params,WEB_TIMEOUT);
      return(res);
     }

   //+------------------------------------------------------------------+


 Note:I´m sure that work because "Telegram_Bot_EA" can be run well.


Another one: 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN && 
      lparam=='Q')
     {
         
         bot.SendMessage(InpChannelName,"ee\nAt:100\nDDDD");
     }
  }

Note:i press "Q" in to bot chat or channel chat and dont work....i think if you press the key,bot send you text...right?Well, this option cant work.I dont understand... I dont have any error´s or warnings to compile all mql5 code.


Resume: i like send to telegram text signal(buy/sell) about your example indicators or my custom indicators rules but i dont understant why not work me.


Thank you and nice day.


UPDATE1(solved):


I check logs and get this info:

HL 0 06:24:00.729 Telegram_Signal_EAEVO (DE30,M1) Error: Bad Request

LH 0 06:40:00.916 Telegram_Signal_EAEVO (DE30,M1) {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

RG 0 06:40:00.916 Telegram_Signal_EAEVO (DE30,M1) Error: Bad Request

KQ 0 07:31:00.442 Telegram_Signal_EAEVO (DE30,M1) {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

MO 0 07:31:00.442 Telegram_Signal_EAEVO (DE30,M1) Error: Bad Request

I´m add a new father and resolve the last error,  but again cant be send message the bot...

EF    0    12:26:44.372    Telegram_Signal_EAEVO (DE30,H1) NAME_bot: NAMEsignalsbot 


UPDATE2(solved):

I check this link http://usefulmix.com/send-message-telegram-channel-bot-http-api/


In the text :


So we need to make the channel private, however in doing so our above HTTP API call will stop working and this is what trying to prublish a message will look like:


{
  "ok": false,
  "error_code": 400,
  "description": "Bad Request: chat not found"
}

i check with the url sample and get this:

        
ok      false
error_code      404
description     "Not Found"


In common.mqh list this error but i´m very lost with this....I research more.

The "problem" its with a convert token, i write and type this code to test and the bot write me:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//Original code:

// {
// 
//  if(id==CHARTEVENT_KEYDOWN &&   lparam=="Q")
//bot.SendMessage(InpChannelName,"ee\nAt:100\nDDDD");
//}

//Test code:

 {

  
   if(id==CHARTEVENT_KEYDOWN && 
      lparam=="Q")
   
      //--- set token
   bot.Token(InpToken);
    bot.SendMessage("ID CHAT OR USER","ITS A TEST!");

}
     

Image:

I read again the general post because one people talk about this.


TO UPDATE 3!:

How to send a message to a Telegram channel using the HTTP bot sendMessage API
How to send a message to a Telegram channel using the HTTP bot sendMessage API
  • 2018.10.08
  • admin
  • usefulmix.com
Here’s a practical example how to send a message to a Telegram channel using a Telegram Bot and the HTTP bot sendMessage API. In order to be able to do so, you will have to the following: Create a Telegram public channel (we’ll make this private later) Create a Telegram BOT via BotFather Set the bot as administrator in your channel After...
 

Hello make sure to import telegram.mqh and see here : 

https://www.mql5.com/en/forum/285054/page2#comment_11220261

MT4 to Telegram
MT4 to Telegram
  • 2019.04.04
  • www.mql5.com
Can anyone code or have any idea how to send trade details from MT4 to a Telegram channel. This is the sort of thing I am talking about. Thanks...
 
Marco vd Heijden:

Hola, asegúrese de importar telegram.mqh y vea aquí: 

https://www.mql5.com/en/forum/285054/page2#comment_11220261

I check...i need take time...later i write you.Thanks!!!!!
 

Thanks a lot Nguyen Van Tuan,
Now, it works with private channels. Before, my bot was working only in public channels.

Best Regards,
Junior


Nguyen Van Tuan:

Hi,

When i have tested with this Library of  Andrey Voytenkoon MT5, It not work well so i have some more simple step. Any people hit same error can try to change like me:

1. Confirm add https://api.telegram.org to Allow WebRequest for listed URL

2. When you using chat_id (like "-1001301234105") instead @channel_name, you will hit some error with this code so i have change it

And now I confirm after i have do two things above, this library work well in MT5.

Thanks Andrey Voytenko again.

 

Right!!! Same problem!!!!



Junior:

Thanks a lot Nguyen Van Tuan,
Now, it works with private channels. Before, my bot was working only in public channels.

Best Regards,
Junior


 
Hi

I got a script to send messages from MT4 to Telegram, I tried to convert to MQL5 but failed, through this discussion forum I ask for help to convert from MQ4 file format to MQL5 for further study material .....

the file I included


I thank those who are willing to help



 

Hi, I update metatrader v and compile the code again, but report me a warning:


MT5 5.00 build: 2170 4 / OCT / 2019:

"" Obsolete behavior, calls to hidden methods will be disabled in a future version of the MQL Telegram.mqh compiler ""


The reference call to: " StringReplace "


I am looking for any alternative but for the moment I did not find it. In the future rev ..... any ideas?


Thank you!!


Code:


 //+------------------------------------------------------------------+
   void UserNameFilter( const string username_list)
     {
      m_users_filter.Clear();

       //--- parsing
       string text=StringTrim(username_list);
       if (text== "" )
         return ;

       //---
       while ( StringReplace (text, "  " , " " )> 0 );
       StringReplace (text, ";" , " " );
       StringReplace (text, "," , " " );
      

       //---
       string array[];
       int amount= StringSplit (text, ' ' ,array);
       for ( int i= 0 ; i<amount; i++)
        {
         string username=StringTrim(array[i]);
         if (username!= "" )
           {
             //--- remove first @
             if ( StringGetCharacter (username, 0 )== '@' )
               username= StringSubstr (username, 1 );

            m_users_filter.Add(username);
           }
        }

     }
   //+------------------------------------------------------------------+ 
 
satrifx7:
Hi

I got a script to send messages from MT4 to Telegram, I tried to convert to MQL5 but failed, through this discussion forum I ask for help to convert from MQ4 file format to MQL5 for further study material .....

the file I included


I thank those who are willing to help



You dont needed convert the code.This code can be run in both version, see again the post or code.
 
odlambda:

Hi, I update metatrader v and compile the code again, but report me a warning:

Please only use English in the forum.

I have edited and translated your post with the site's tool this time