This Telegram module enables communication with Telegram by sending messages via the Telegram Bot API.

The function SendMessageToTelegram takes:

  1. a message, a chat ID, and a bot token as parameters to construct a JSON payload, 
  2. and sends it using an HTTP POST request to the Telegram API.

It uses the WebRequest function to make the request, with a timeout of 5000 milliseconds. If the request is successful (HTTP 200 response), it prints a confirmation message; otherwise, it prints an error message along with the response details.

Application Examples

  • Sending Signal Alerts
  • Other Communication Tasks

Below is an example demonstrating how to use the Telegram.mqh module in an Expert Advisor (EA). I have developed a simple testing EA that sends a greeting message to Telegram upon initialization.

When integrating Telegram messaging into an EA, three key steps are essential:

1. Include the Telegram Module

  • #include <Telegram.mqh>: Imports the module that provides the SendMessageToTelegram function.

2. Declare Telegram Credentials

  • botToken: Input parameter to store your Telegram bot token.
  • chatId: Input parameter to store your Telegram chat ID.

3. Send a Telegram Message

  • Define Message: Create a greeting message string.
  • Function Call: Use SendMessageToTelegram(message, chatId, botToken) within the OnInit() function.
  • Feedback Handling: Print messages indicating success or failure based on the HTTP response.

TelegramSendTesting

The results in the Experts log from the image above show an attempt to send a message to Telegram, which failed due to incorrect credentials.