Sending message from MT5 to Telegram using Webrequest returns 1007 error

 

Hi master MQL coders,

I have been trying my hand on using Telegram to get updates about my expert advisors. Lately I created a Telegram channel where I want to send entries taken by an expert advisor. However, I encounter error 1007. This is the first time I encountered this error, and I could not find helpful resources here or elsewhere online. Are you familiar with this error? 

By the way, here is a snippet of my code:

void ComposeTGMessage(string asset) 
   {

   ENUM_POSITION_TYPE pos = POSITION_TYPE_BUY;
   GetType(asset,pos);
   string positiontype = (pos==POSITION_TYPE_BUY) ? "BUY" : "SELL";
   
   double tpvalues[]; ArrayResize(tpvalues,0); 
   double entryprice = 0;
   double stoploss   = 0;
   double takeprofit = 0;

   for(int i = 0; i < PositionsTotal(); i++)  {
      ulong ticket = PositionGetTicket(i);
      if(ticket==0) continue;
      if(PositionGetString(POSITION_SYMBOL)!=asset) continue;
      ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
      if(type==POSITION_TYPE_BUY || type==POSITION_TYPE_SELL)  {
         entryprice = ND(PositionGetDouble(POSITION_PRICE_OPEN),dig(asset));
         stoploss   = ND(PositionGetDouble(POSITION_SL),dig(asset));
         takeprofit = ND(PositionGetDouble(POSITION_TP),dig(asset));
         ArrayResize(tpvalues,ArraySize(tpvalues)+1);
         tpvalues[ArraySize(tpvalues)-1] = takeprofit;
      }
   }
   ArraySort(tpvalues);   
   ArrayResize(tpvalues,3);
   
   if(pos==POSITION_TYPE_SELL) ArrayReverse(tpvalues);
   
   double tp1 = tpvalues[0];
   double tp2 = tpvalues[1];
   double tp3 = tpvalues[2];
   
   int digit = dig(asset);
   string sms = StringFormat("[%s] [%s] at [%s]\n\nTP1: [%s]\nTP2: [%s]\nTP3: [%s]\n\nSL: [%s]",
                             positiontype,
                             asset,
                             DTS(entryprice,digit),
                             DTS(tp1,digit),
                             DTS(tp2,digit),
                             DTS(tp3,digit),
                             DTS(stoploss,digit));
   SendNotification(sms);
   SendTGMessage(TelegramAPIurl,TelegramToken,TelegramChatID,sms);

  }

bool SendTGMessage(string url,string token,string chat,string txt,string filename="") 
  {

   string headers    = "";
   string requestURL = "";
   char   postData[];
   char   resData[];
   string resHeaders;
   int    timeout = 5000;  //millisecond
   
   int UrlDefinedError = 4014; 
   
   if(filename=="")
      requestURL = StringFormat("%s/bot%s/sendmessage?chat_id=%s&text=%s",url,token,chat,txt);
   else {
      requestURL = StringFormat("%s/bot%s/sendPhoto",url,token);
      if(!GetPostData(postData,headers,chat,txt,filename)) return false;
   }      
   
   ResetLastError();
   int response = WebRequest("POST",requestURL,headers,timeout,postData,resData,resHeaders);
   
   switch(response) {
      case -1: {
         int errorCode = GetLastError();
         Print((string)__LINE__+" Error in webrequest. Error code:",errorCode);
         if(errorCode==UrlDefinedError) {
            PrintFormat("Add the address '%s' in the list of allowed urls",url);
         }
         break;
      }
      case 200:
         Print((string)__LINE__+"The message has been successfully sent.");
         break;
      default: {
         string result = CharArrayToString(resData);
         PrintFormat((string)__LINE__+" Unexpected response '%i', '%s'",response,result);
         break;
      }         
   }
   return (response==200);
}

I was able to get the desired text format when I use the SendNotification function. However, the Telegram message is not sent because Webrequest returns 1007 error.

By the way, here is my desired text output:

[BUY/SELL] [symbol] @ [entryprice]

TP1: [TP1]

TP2: [TP2]

TP3: [TP3]

SL: [SL]