int res=bot.SendMessage(-100135482 xxx,"Running a test " +TimeToString(TimeCurrent()));
int ac=bot.SendChatAction(-100135482 xxx,ACTION_UPLOAD_PHOTO);
int pic=bot.SendPhoto(filepath+"\mypic.gif",-100135482 xxx,filepath);
2020.08.19 15:56:04.830 Moving Average Signal To Alert (RTSRIU0,M1) Error: URL is not allowed forWebRequest.
2020.08.19 15:54:01.332 Moving Average Signal To Alert (RTSRIU0,M1) exit channel https://api.telegram.org/bot1234567:AAHwDJwwrh-m16O0EoIA7--3BG0I5ayk3E0/sendMessage chat_id=@MyTestSignal&text=HELLO
Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to our Bot API. 1. What can I do with bots? To name just a few things, you could use bots to: Get customized notifications and news . A bot can act as a smart...
大家好、
我正在拼命寻找一种通过 MT4 向 Telegram 发送本地截图的解决方案。
快速代码截图
第一段有效,因为即使我使用 @channelname 也能收到消息
第二段代码只适用于 chatID,这没关系,我可以接受
第三个代码会出错:
2020.08.07 21:40:15.175 xxx1: {"ok":false, "error_code":400, "description": "Bad Request: chat not found"}
你知道我做错了什么吗?
大家好
也许你们中有人能帮上忙,我正在拼命寻找通过 MT4 向 Telegram 发送本地截图的解决方案。
快速代码截图
第一段有效,因为即使我使用 @channelname 也能收到消息
第二个代码只对聊天 ID 有效,没关系,我可以接受
第三种方法会让我出错:
2020.08.07 21:40:15.175 xxx1: {"ok":false, "error_code":400, "description": "Bad Request: chat not found"}
你知道我做错了什么吗?
是的,你必须修改 mqh 文件,使其接受负数。
@Marco vd Heijden 谢谢!
这很有趣,我查看了 Telegram.mqh,发现 SendPhoto 有三个函数,我想知道代码是如何知道使用哪个函数的。反正第三个是不可能的。
第一个
第二个:
会不会是代码不知道我要使用哪个函数?我试图触发第一个,但实际上第二个会更好。
其次,我试图在第一个函数中搜索 _chat_id 发生了什么,但我只能看到简单的整数到字符串的转换:
注意第二个参数一个是长字符串,另一个是字符串
而且
这是 mql 基础知识的一部分,你可以有数百万个同名函数,但参数或参数个数各不相同
@Jefferson Metha 是的,我明白,这只是我的想法,因为要找到问题太难了。
我现在使用了 https://www.mql5.com/en/forum/89826/page15#comment_17079865 中描述的提示,但仍然没有任何进展。
我想把重点放在 sendPhoto 功能上,在这个功能中输入的是频道名称,而不是聊天 ID,所以我们只关注一件事。
到目前为止,我在 Telegarm.mqh 中的函数
我修改了下面一行:
基本上删除了 StringTrim 函数,但情况并没有好转。
终于想通了。
更改:
删除:
最后,在 EA 中,就这么简单:
下午好。
感谢您的详细文章。非常有帮助。
我遇到的问题是,WEB 请求不起作用。
它给出了一个错误
2020.08.19 15:56:04.830 Moving Average Signal To Alert (RTSRIU0,M1) Error: URL is not allowed forWebRequest.
经过研究,发现是 /sendmessage 后缺少了 ?(问题)。
这个问题已经解决了吗?有新版本吗?
我会自己修复的。
我正在从指示器向电报发送文本。但我不得不将 POST 类型的请求改为 GET 类型的请求。
如果用 POST 发送,会出现错误 400。如果我从 EA 发送相同的代码(但我使用的是 WebRequest 而不是 _WebRequest),代码就能在 POST 模式下工作。在 GET 方法中,我的请求长度有限制,你能告诉我该从哪里查找吗?
错误,GET 也会出现错误 400...
2020.08.21 08:52:20.138 testWININET GBPUSD,M1: Error loading 'https://api.telegram.org/bot123123123:ываываыукаыва /sendMessage?chat_id=-123123123123&parse_mode=HTML&text=Hello', code 400
如果我通过浏览器发送,请求会通过。
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
//#include <Wininet.mqh
#include <Webrequest_dll.mqh> #define telegramBase.mqh.
#define telegramBaseURL "https://api.telegram.org"
//https://tlgrm.ru/docs/bots/api 阅读如何发送
输入字符串 inpToken="11111212:vapvapYVVAEFfer";//Token
输入字符串 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="" + inpToken + "/endMessage?chat_id="+inpChat_id; if(inpParsMode){
}
// url = url + "&text= " + "<b>1114</b>"
// url = url + "&text= " + "<i>1114</i>";
url = url + "&text=" + "1118";
打印 (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.错误代码 =",GetLastError());
//--- 列表中可能缺少 URL,请打印需要添加 URL 的信息。
MessageBox("It is necessary to add the address '"+url+"' to the list of allowed URLs in the 'Advisors' tab", "Error",MB_ICONINFORMATION);
}
否则
{
if(res==200)
{
//--- 下载成功
PrintFormat("File successfully uploaded, size %d bytes.",ArraySize(result));
//PrintFormat("Server headers: %s",headers);
//--- 将数据保存到文件
int filehandle=FileOpen("url.htm",FILE_WRITE|FILE_BIN);
if(filehandle!=INVALID_HANDLE)
{
//--- 将结果[] 数组的内容保存到文件中
FileWriteArray(filehandle,result,0,ArraySize(result));
//--- 关闭文件
FileClose(filehandle);
}
else
Print("Error in FileOpen.错误代码 =",GetLastError());
}
否则
PrintFormat("Error loading '%s', code %d",url,res);
}
// ReadUrl(url,data);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 自定义指标迭代函数
//+------------------------------------------------------------------+
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[])
{
//---
//--- 为下一次调用返回 prev_calculated 的值
return(rates_total);
}
//+------------------------------------------------------------------+