MT5 to Telegram Error: Error Code 400 Description "Bad request: chat not found"

 

Hi everyone,

I am trying to send a message from MT5 to Telegram using a bot. However, I could not send the message from MT5 to Telegram due to the error: Error Code 400 Description "Bad request: chat not found"

Can you give some reasons why this error might have occurred?

I did a lot of research online, but I could not get the right answers.

 
Cerilo Cabacoy: I am trying to send a message from MT5 to Telegram using a bot. However, I could not send the message from MT5 to Telegram due to the error: Error Code 400 Description "Bad request: chat not found"

Can you give some reasons why this error might have occurred? I did a lot of research online, but I could not get the right answers.

Without any code as a reference we cannot offer any advice. However, given that Telegram is a 3rd party service, that is mostly beyond the scope of this forum.

If your code is in reference to some Article, CodeBase publication or some existing Forum topic, then it would be best to post there and not here in general.

 
Fernando Carreiro #:

Without any code as a reference we cannot offer any advice. However, given that Telegram is a 3rd party service, that is mostly beyond the scope of this forum.

If your code is in reference to some Article, CodeBase publication or some existing Forum topic, then it would be best to post there and not here in general.

Sir, thanks for your reply. Below is the full source code. It is just a simple expert advisor that extracts data from a text file and then attempts to send the data to a Telegram channel. However, it encountered the error mentioned.

#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <Telegram.mqh>
CCustomBot tgbot;

input string TelegramBotToken = "6770842913:AAGcnR666ddL7hCB8HeTNs6HdNe28y3F-ik";
input string TelegramChatID = "-1002063516288";
input string TelegramAPIurl = "https://api.telegram.org";
input string namefile = "WagScores.txt";

datetime h1time = 0;
string channelname = "";
//+------------------------------------------------------------------+
int OnInit() {

   tgbot.Token(TelegramBotToken);
   int res = tgbot.GetMe();      Print("GetMe() results: "+(string)res);
   channelname = tgbot.Name();   Print("bot name: "+channelname);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {

   
}
//+------------------------------------------------------------------+
void OnTick() {

   ChartRedraw();
   if(NewH1Bar()) {
      string data[];
      string output = "";
      GetTxtDataToArray(namefile,data); 
      string message = StringFormat("Time: %s\n",TimeToStr(TimeCurrent()));  
      StringAdd(output,message);   
      for(int i = 0; i < ArraySize(data); i++) {
         string strmsg = StringFormat("%s\n",data[i]);
         StringAdd(output,strmsg);     
      }     
      int res = tgbot.SendMessage(TelegramChatID,output);      Print((string)__LINE__+" "+(string)res);
      SendNotification(output);
   }
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool NewH1Bar() { 
     
   datetime newtime = iTime(Symbol(),PERIOD_H1,0);
   if(newtime==h1time) return false;
   h1time = newtime;                                
   return true;
}
//+------------------------------------------------------------------+   
void GetTxtDataToArray(string filename,string &array[]) { 
             
   if(!FileIsExist(filename)) return;
   int handle = FileOpen(filename,FILE_TXT|FILE_READ|FILE_ANSI);
   if(handle==INVALID_HANDLE) { Print(""+__FUNCTION__+" "+(string)__LINE__+" opening file error"); return; }
   FileSeek(handle,0,SEEK_SET);
   while(!FileIsEnding(handle)) {
      string line = FileReadString(handle); 
      ArrayResize(array,ArraySize(array)+1);         
      array[ArraySize(array)-1] = line;
   }
   FileClose(handle);    
}
 

As I stated, Telegram is beyond the scope of this forum.

You may be lucky and receive an answer from someone that knows the Telegram API well, but for the most part you will probably have to do your own research.

You are also using a 3rd party library "Telegram.mqh", so please ask the authors for advice.

If this is regarding the Article  "How to create bots for Telegram in MQL5", then please post under that articles discussion thread and not here.

 
Fernando Carreiro #:

As I stated, Telegram is beyond the scope of this forum.

You may be lucky and receive an answer from someone that knows the Telegram API well, but for the most part you will probably have to do your own research.

You are also using a 3rd party library "Telegram.mqh", so please ask the authors for advice.

If this is regarding the Article  "How to create bots for Telegram in MQL5", then please post under that articles discussion thread and not here.

Okay sir. Thanks for the direction.