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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all,
Maybe some of you can help, I'm desperately trying to find a solution to send a local screenshot via MT4 to Telegram.
Quick code snipped
First one works, as I'm getting the message, even if I use @channelname
Second one works only with chatID, which is ok, I can live with it
Third one is throwing me the error:
2020.08.07 21:40:15.175 xxx1: {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
Any idea, what I'm doing wrong?
Hi all,
Maybe some of you can help, I'm desperately trying to find a solution to send a local screenshot via MT4 to Telegram.
Quick code snipped
First one works, as I'm getting the message, even if I use @channelname
Second one works only with chatID, which is ok, I can live with it
Third one is throwing me the error:
2020.08.07 21:40:15.175 xxx1: {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
Any idea, what I'm doing wrong?
yes you have to modify the mqh file so that it accepts that negative number.
@Marco vd Heijden thanks!
This is interesting I had a look at Telegram.mqh and I see three functions for SendPhoto, out of which I'm wondering how the code knows which one to use. The third one is anyway out of the question.
First:
Second:
Could it be that the code does not know which one I want to take? I'm trying to trigger the first one, but actually the second one would be better.
Secondly I tried to search in the first function what is happening with _chat_id, but I can only see a simple integer to string conversion:
notice second parameter one is a long the other is a string
and
this is part of mql basics u can have million functions with the same name with different parameters or number of parameters
@Jefferson Metha yes I do understand that, it was just my thought, as it's been so tough to find the issues.
I used now the tips described in https://www.mql5.com/en/forum/89826/page15#comment_17079865, but still not getting anywhere.
I'd like to focus on the sendPhoto function where the input is Channel name, not chat ID, so let's solely focus on one thing.
What I did so far, in Telegarm.mqh in the function
I've modified the following line:
Basically removing the StringTrim function, but it's not getting better.
Finally figured it out.
Changes:
Removed:
And finally in the EA, as simple as:
Good afternoon.
Thanks for the detailed article. Very helpful.
I encountered that WEB request did not work.
It gives an error
2020.08.19 15:56:04.830 Moving Average Signal To Alert (RTSRIU0,M1) Error: URL is not allowed for WebRequest
After researching it turned out to be missing ?( question) after /sendmessage?
Has this been fixed yet ? Is there a new version ?
I'll fix it myself.
I am sending text to telegram from the indicator. But I had to change POST to GET type of request.
If I send with POST, I get error 400. If I send the same code from the EA (but I use WebRequest instead of _WebRequest), the code works in POST mode. Can you tell me where I should look, as in the GET method I have a limit on the length of the request?
Error and with GET also error 400...
2020.08.21 08:52:20.138 testWININET GBPUSD,M1: Error loading 'https://api.telegram.org/bot123123123:ываываыукаыва /sendMessage?chat_id=-123123123123123&parse_mode=HTML&text=Hello', code 400
If I send it through the browser, the request goes through.
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
//#include <Wininet.mqh>
#include <Webrequest_dll.mqh>
#define telegramBaseURL "https://api.telegram.org"
//https://tlgrm.ru/docs/bots/api to read how to send what
input string inpToken="11111212:vapvapYVVAEFfer";//Token
input string inpChat_id="-3123123123123213";
bool inpParsMode =true;
int OnInit()
{
string data;
string url="https://api.telegram.org/bot" + inpToken + "/sendMessage?chat_id="+inpChat_id;
if(inpParsMode){
url = url + "&parse_mode=HTML"
}
// url = url + "&text= " + "<b>1114</b>"
// url = url + "&text= " + "<i>1114</i>";
url = url + "&text=" + "1118";
Print (url);
string cookie=NULL,headers;
char post[],result[];
int res=_WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);
if(res==-1)
{
Print("Error in WebRequest. Error code =",GetLastError());
//--- the URL is probably missing from the list, print a message about the need to add it.
MessageBox("It is necessary to add the address '"+url+"' to the list of allowed URLs in the 'Advisors' tab", "Error",MB_ICONINFORMATION);
}
else
{
if(res==200)
{
//--- successful download
PrintFormat("File successfully uploaded, size %d bytes.",ArraySize(result));
//PrintFormat("Server headers: %s",headers);
//--- save data to file
int filehandle=FileOpen("url.htm",FILE_WRITE|FILE_BIN);
if(filehandle!=INVALID_HANDLE)
{
//--- save the contents of the result[] array to a file
FileWriteArray(filehandle,result,0,ArraySize(result));
//--- close the file
FileClose(filehandle);
}
else
Print("Error in FileOpen. Error code =",GetLastError());
}
else
PrintFormat("Error loading '%s', code %d",url,res);
}
// ReadUrl(url,data);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+