Download MetaTrader 5

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

To add comments, please log in or register
Marco vd Heijden
Moderator
6132
Marco vd Heijden  

look in the

<Telegram.mqh>
{ 
   "ok":true,
   "result":[ 
      { 
         "update_id":349778698,
         "message":{ 
            "message_id":2,
            "from":{ 
               "id":198289825,
               "first_name":"Andriy",
               "last_name":"Voitenko",
               "username":"avaticks"
            },
            "chat":{ 
               "id":198289825,
               "first_name":"Andriy",
               "last_name":"Voitenko",
               "username":"avaticks",
               "type":"private"
            },
            "date":1459775817,
            "text":"\/start"
         }
      }
   ]
}
Andrey Voytenko
16433
Andrey Voytenko  

Aimak:

I would appreciate if you could help me finding the error. Thanks in advance.

Switch your channel to public mode. Or using chatID (not channel name) for communication with your private channel.

Aimak
165
Aimak  
Andrey Voytenko:

Switch your channel to public mode. Or using chatID (not channel name) for communication with your private channel.


The channel is public and I getting the same result using channel name or ID. See screenshot

Using Channel ID

Andrey Voytenko
16433
Andrey Voytenko  
Aimak:

The channel is public and I getting the same result using channel name or ID. See screenshot

Do you use the latest release of Telegram.mqh and Jason.mqh?

Aimak
165
Aimak  
Andrey Voytenko:

Do you use the latest release of Telegram.mqh and Jason.mqh?


I worked with the versions from your article. I have downloaded the latest version of jason.mqh v1.09 by Sergeev. I cannot locate the latest version of Telegram.mqh

Yesterday, I added a '?' before 'chat_id' in the code below following the examples found in other websites about telegram bots. Today, I decided to return to your original code by undoing the '?'. Now it works as expected sending the OnInit message to the channel. Thanks.

//+------------------------------------------------------------------+
   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";
      int res=PostRequest(out,url,params,WEB_TIMEOUT);
      return(res);
     }
MarcoLombardo
5
MarcoLombardo  

Dear Andrey, 

thanks a lot for your work. I've installed your files and configured an expert that does the following:

1) the expert sends messages to the bot every x minutes (just for test) ,

2) i read the message on telegram and click "open trade" on the keyboard of telegram client,

3) the metatrader opens the trade (if possible).

Everything works fine but after a while the bot is not anymore reachable; to make it work again i have to wake up him by pressing some command on the keyboard menu (for example charts or /start or account info....). The metatrader says "bad request:chat not found" but if I wake up the bot again it works perfectly for one hour or more but then it stops.

I've created the bot as you have suggested (with botFather). How can I solve this issue?

Thanks again

Files:
error.gif 26 kb
agsapri
9
agsapri  

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq

Haijie Qi
207
Haijie Qi  

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq


Marco vd Heijden
Moderator
6132
Marco vd Heijden  

Maybe they changed the protocol.

Have you checked Telegram API ?

Andrey Voytenko
16433
Andrey Voytenko  
Haijie Qi:

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq

I debugged the 'Telegram_Bot_EA' on your PC using TeamViewer and have found that WebRequest() returned -1. _LastError = 5203.

But I dont know why. Perhaps your firewall blocks TCP packets.

To add comments, please log in or register