How to Integrate Telegram Bot for Test Report Notifications via TelegramManager in AutomationFrameworkSelenium

To integrate Telegram notifications in AutomationFrameworkSelenium, configure your bot token and chat ID in config.properties, enable the SEND_REPORT_TO_TELEGRAM flag, and let the TestListener automatically trigger TelegramManager.sendReportPath() at suite finish.

The AutomationFrameworkSelenium repository by anhtester provides a built-in TelegramManager utility that automates the delivery of Extent HTML reports and custom messages to Telegram chats. This integration leverages the java-telegram-bot-api library and requires zero additional coding once configured, as the framework handles bot initialization and message dispatch through TestNG lifecycle hooks.

Architecture Overview

The Telegram integration operates through five coordinated layers that decouple configuration from execution logic.

  • Configuration Layer: Stores credentials in src/test/resources/config/config.properties using keys TELEGRAM_TOKEN, TELEGRAM_CHATID, and SEND_REPORT_TO_TELEGRAM.
  • Constants Layer: FrameworkConstants loads these values at runtime (lines 42–44) via PropertiesHelpers.loadAllFiles(), making them globally accessible without repeated I/O.
  • Manager Layer: TelegramManager wraps the com.github.pengrad:java-telegram-bot-api dependency (declared in pom.xml lines 81–87) to instantiate a static TelegramBot and expose sendReportPath(), sendMessageText(), and sendFilePath().
  • Listener Layer: TestListener (line 102) invokes TelegramManager.sendReportPath() during onFinish, ensuring reports dispatch only after the entire suite completes.
  • Dependency Layer: Maven manages the Telegram client library, so the project compiles without manual jar downloads.

Configuration Setup

Setting Up Telegram Bot Credentials

Create or edit src/test/resources/config/config.properties to include your Telegram Bot API token and target chat ID. The framework reads these automatically during static initialization.


# Telegram Bot Configuration

SEND_REPORT_TO_TELEGRAM = yes
TELEGRAM_TOKEN = 123456:ABC-DEF1234ghIkl-zyx57W2v1u1234567890
TELEGRAM_CHATID = 987654321

Replace the token with the string provided by BotFather when you created your bot, and use the numeric chat ID of your personal account or group chat.

Enabling Automatic Notifications

Set SEND_REPORT_TO_TELEGRAM = yes to activate the dispatch trigger. When this flag equals "yes", the sendReportPath() method in TelegramManager (line 40) executes the SendDocument request; any other value skips the transmission silently.

Core Implementation Details

TelegramManager Class

Located at src/main/java/com/anhtester/reports/TelegramManager.java, this utility initializes a static TelegramBot instance using the token from FrameworkConstants.TELEGRAM_TOKEN (lines 16–18). It provides three public static methods:

  • sendReportPath(): Reads FrameworkConstants.EXTENT_REPORT_FILE_PATH and transmits the HTML report as a document (lines 43–45). Logs success or failure via LogUtils (lines 47–53).
  • sendMessageText(String text): Dispatches plain text messages for custom status updates.
  • sendFilePath(String path): Uploads arbitrary files (logs, screenshots) relative to the project root.

FrameworkConstants Integration

FrameworkConstants binds the configuration values to Java constants at line 42–44:

public static final String SEND_REPORT_TO_TELEGRAM = PropertiesHelpers.getValue("SEND_REPORT_TO_TELEGRAM");
public static final String TELEGRAM_TOKEN = PropertiesHelpers.getValue("TELEGRAM_TOKEN");
public static final String TELEGRAM_CHATID = PropertiesHelpers.getValue("TELEGRAM_CHATID");

These constants are populated when the class loads via a static block (line 19) that calls PropertiesHelpers.loadAllFiles(), ensuring credentials are available before any test runs.

TestListener Integration

The TestListener class (located in src/test/java/com/anhtester/listeners/TestListener.java) hooks into TestNG's ISuiteListener. At line 102, inside the onFinish method, it invokes:

TelegramManager.sendReportPath();

This placement guarantees that Telegram receives the final Extent report only after all tests complete and the HTML file is fully written.

Usage Examples

Automatic Report Delivery

Once configured, the framework sends the Extent report automatically. No manual intervention is required because TestListener triggers the dispatch at suite finish.

// No code needed — configured entirely via properties file
// The report at FrameworkConstants.EXTENT_REPORT_FILE_PATH is sent automatically

Sending Custom Text Messages

For on-demand status updates during long-running tests, call the text method directly from any test class:

import com.anhtester.reports.TelegramManager;

public class BuildVerificationTest {
    
    @Test
    public void verifyDeployment() {
        // ... test steps ...
        
        String status = "✅ Build #42 completed — 12 passed, 1 failed.";
        TelegramManager.sendMessageText(status);
    }
}

Uploading Custom Files

To send specific artifacts such as log files or failure screenshots outside the standard Extent report:

TelegramManager.sendFilePath("logs/error-screenshot.png");

The path is resolved relative to the project root directory, and the file transmits as a document to the configured TELEGRAM_CHATID.

Summary

  • Configure your bot token and chat ID in src/test/resources/config/config.properties using the keys TELEGRAM_TOKEN and TELEGRAM_CHATID.
  • Enable the feature by setting SEND_REPORT_TO_TELEGRAM = yes to allow TelegramManager.sendReportPath() to execute.
  • Understand that FrameworkConstants loads these values at startup (lines 42–44) and makes them available to the static bot instance.
  • Rely on TestListener (line 102) to trigger automatic delivery at the end of the TestNG suite, or call TelegramManager methods manually for custom notifications.
  • Verify that pom.xml includes the java-telegram-bot-api dependency (lines 81–87) to ensure the Telegram client is available on the classpath.

Frequently Asked Questions

How do I create a Telegram bot token for AutomationFrameworkSelenium?

Open Telegram and message BotFather with /newbot, then follow the prompts to name your bot. BotFather will return a token resembling 123456:ABC-DEF.... Paste this into config.properties as the TELEGRAM_TOKEN value. No code changes are required in the framework.

Where does the framework store the Telegram configuration?

All credentials and flags reside in src/test/resources/config/config.properties. The FrameworkConstants class reads these at runtime (lines 42–44) via PropertiesHelpers.loadAllFiles(), which executes in a static block (line 19) when the JVM loads the constants class.

Can I send notifications to multiple Telegram chats?

The current TelegramManager implementation uses a single static TELEGRAM_CHATID from FrameworkConstants. To support multiple chats, you would need to modify TelegramManager.java to accept a chat ID parameter in sendMessageText() or sendFilePath(), then loop through a list of IDs before constructing the SendDocument or SendMessage request.

How do I disable Telegram notifications without removing the configuration?

Change SEND_REPORT_TO_TELEGRAM to any value other than "yes" (such as "no" or leaving it blank). The sendReportPath() method checks FrameworkConstants.SEND_REPORT_TO_TELEGRAM.equals("yes") at line 40; if the condition fails, the method returns immediately without initializing the HTTP request to Telegram's servers.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →