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

 
Do you have any idea how to add Inline Keyboard function in this?
 
int OnInit()
  {
   string fileType = "png";
   string fileName = "MewPhoto." + fileType;
   ChartScreenShot(0, fileName, 900, 900, ALIGN_RIGHT);
   Sleep(50);
   bot.Token(Token);
   int result = bot.GetMe();
   bot.GetUpdates();
   Comment("Bot Name ",bot.Name());
   bot.SendChatAction(int(ChatId),ACTION_UPLOAD_PHOTO);
   Sleep(500);
   if(FileIsExist(fileName))
     {
      string photo_id;
      result=bot.SendPhoto(photo_id,ChatId,fileName,"Hello");
     }
   if(!FileIsExist(fileName))
     {Alert("Image not find");}
//   EventSetTimer(60);

//---
   return(INIT_SUCCEEDED);
  }
Anyone SendPhoto success! Please Help me! There no picture send to Telegram
 
Cerilo Cabacoy #:

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"

Has anyone encountered the same problem? 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.


I have just got the same error" Error Code 400 Description "Bad request: chat not found" but everything worked perfectly before. I also did some research & havent found any solution.

Could anyone shed me some light how to fix this problem? Thanks

#include <Telegram.mqh>
//--- input parameters
input string InpToken="7504821711:AAFljwzACG8ezAhRXzDB2iU9BDM5p0VTDKs";
input string InpChannelName="Test_Error_SendMessage";//Channel Name
//--- global variables
CCustomBot bot;
int OnInit()
  {
//--- set token
   bot.Token(InpToken);  
  //--- 
   return(INIT_SUCCEEDED);
  }
////  Press "A" on keyboard to test & get the error: "Error Code 400 Description "Bad request: chat not found"
void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
    {
        if (id== CHARTEVENT_KEYDOWN && lparam == StringGetChar("A",0)){
        const string msg = bot.Name();
        // send msg
        int res=bot.SendMessage(InpChannelName,msg);
        if(res!=0) Print("Error: ",GetErrorDescription(res));  
        }               
    }
void OnTick()
  {
  return;
  }    
void OnDeinit(const int reason)
  {
  return;
  }
// end test
 
aphong #:

I have just got the same error" Error Code 400 Description "Bad request: chat not found" but everything worked perfectly before. I also did some research & havent found any solution.

Could anyone shed me some light how to fix this problem? Thanks

in my case, I just read old posts & know that im trying to send msg to a private channel. So I have just replaced the channel name with chat id & its working perfectly!

Thanks  Andriy & other pro coders <3

Andriy Voitenko
Andriy Voitenko
  • 2023.07.11
  • www.mql5.com
Trader's profile