記事"MQL5言語でのTelegram用ボットの作成"についてのディスカッション - ページ 13

 

こんにちは。

ボットはチャンネルを通してメッセージを受信できますか?

ボットを管理者として割り当てました。新しいメッセージは受信できますが、テキストは常に空白行です。

msg.message_text=item["message"]["text"].ToStr();
msg.message_text=StringDecode(msg.message_text);
ここでは常に空白行です。
 
leonerd:

こんにちは。

ボットはチャンネルを通してメッセージを受信できますか?

ボットを管理者として割り当てました。新しいメッセージが表示されますが、テキストは常に空白行です。

ここでは常に空行です。

channel_postフィールドでは、https://core.telegram.org/bots/api#update。

このクラスを改良するのがいいでしょう。CCustomMessageにchannel_post_textフィールドを追加する。そしてそれをGetUpdates()に記入する。

Telegram Bot API
  • core.telegram.org
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ. Recent changes April 14, 2019 Added support for native polls: added the object Poll, the methods sendPoll and stopPoll and the field poll in the Message...
 
            msg.chat_id=item["message"]["chat"]["id"].ToInt();

            msg.chat_first_name=item["message"]["chat"]["first_name"].ToStr();
            msg.chat_first_name=StringDecode(msg.chat_first_name);

            msg.chat_last_name=item["message"]["chat"]["last_name"].ToStr();
            msg.chat_last_name=StringDecode(msg.chat_last_name);

            msg.chat_username=item["message"]["chat"]["username"].ToStr();
            msg.chat_username=StringDecode(msg.chat_username);

            msg.chat_type=item["message"]["chat"]["type"].ToStr();
チャンネルからのチャットだけは、何らかの理由でこれらのフィールドがすべてNULLになっている。
 
leonerd:
チャンネルからのチャットの場合、なぜかこれらのフィールドはすべてnullになります。

チャネルの場合は、messageフィールドではなく、channel_postフィールドを見るべきです。channel_postもMessageタイプです。

テキストは表示される:

msg.channel_post_text=item["channel_post"]["text"].ToStr();
msg.channel_post_text=StringDecode(msg.channel_post_text);

というテキストが表示されますが、他のフィールドは表示されません:

msg.channel_post_chat_id=item["channel_post"]["chat"]["id"].ToInt();
//---
msg.channel_post_from_first_name=item["channel_post"]["from"]["first_name"].ToStr();     
msg.channel_post_from_first_name=StringDecode(msg.channel_post_from_first_name);
 
//---
            msg.channel_post_text=item["channel_post"]["text"].ToStr();
            msg.channel_post_text=StringDecode(msg.channel_post_text);

            long msg_id=item["channel_post"]["message_id"].ToInt();
            long msg_date=item["channel_post"]["date"].ToInt();



            //---
            msg.channel_post_chat_id=item["channel_post"]["chat"]["id"].ToInt();
            //---
            msg.channel_post_from_first_name=item["channel_post"]["from"]["first_name"].ToStr();     
            msg.channel_post_from_first_name=StringDecode(msg.channel_post_from_first_name);

最初の3つのフィールドは値を受け取ります。しかし、最後の3つのフィールド(ChatやFromのようなフィールド)は値を受け取りません。どこを見ればいいのでしょうか?
 

わかった。

channel_post.chat_idは負の値でも良い。

channel_post.from.first_name-from-オプションフィールド。一般的には、すべてここにあるhttps://core.telegram.org/bots/api#message

Telegram Bot API
  • core.telegram.org
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ. Recent changes April 14, 2019 Added support for native polls: added the object Poll, the methods sendPoll and stopPoll and the field poll in the Message...
 

OnInit()でこのコードを試して、チャンネルにメッセージを送ろうとしたのですが、うまくいきません。チャンネルやグループチャットにメッセージを送る方法の例を教えてください。

ありがとうございます。

bot.SendMessage("t.me/BotSignals", "Hello",false,false);

 

アドバイスをお願いします。ターミナル 設定で"https://api.telegram.org " パーミッションを追加しました。ブラウザを通してリクエストは正常に実行されますhttps://api.telegram.org/bot&lt;token>/sendMessage?chat_id=<id>&text=test。

以下のコード行が実行されますが、SendMessageはエラーコード5203(HTTPリクエスト実行の結果としてのエラー)を返します。bot.GetMe()メソッドも同じ5203エラーを返します。

何が問題なのでしょうか?ありがとうございます!

      bot.Token("<token>"); //トークンを設定する
  int _res = bot.SendMessage(<id>, "test"); //あなたのID
Bots: An introduction for developers
Bots: An introduction for developers
  • core.telegram.org
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...
 
みんな、ありがとう!わかったよ。問題はRFとブロッキングだと思う。
 
グループを通じてシグナルを共有するボットを作りました。コードをMetaEditorで編集したのですが、コンパイルできません。多くのエラーが発生しました。
ファイル:
Screenshot_3.jpg  227 kb