DEV Community

Cover image for Build a Telegram Bot in Java with the N1netails Telegram Client
Shahid Foy
Shahid Foy

Posted on

Build a Telegram Bot in Java with the N1netails Telegram Client

If you’ve ever wanted to send automated alerts, notifications, or rich media messages to Telegram from your Java application, you’ve probably discovered that working directly with the Telegram Bot API can get repetitive fast.

That’s where N1netails Telegram Client comes in. N1netails a lightweight, open-source Java library designed to make sending Telegram messages simple, structured, and production-ready.

In this guide, you’ll learn:

✅ How to create a Telegram bot
✅ How to configure the N1netails client
✅ How to send text, GIFs, images, videos, and media groups
✅ How to add call-to-action buttons


What is N1netails Telegram Client?

N1netails is an open-source project focused on practical alerting and monitoring. The Telegram client module lets you easily send structured Telegram messages from Java applications perfect for:

  • Alerting systems
  • Automation tools
  • Monitoring dashboards
  • DevOps workflows
  • App notifications

Instead of hand-crafting API requests, you work with clean Java objects.

🎥 Watch the full video tutorial:
https://www.youtube.com/watch?v=T7drCapES6U


Step 1 - Set Up Telegram

Before using the client, you need a Telegram bot.

Install Telegram

Download Telegram on your smartphone first:

👉 https://telegram.org/

Telegram requires initial mobile setup before desktop use.


Create Your Telegram Bot

1. Talk to BotFather

Open Telegram and search for:

@BotFather
Enter fullscreen mode Exit fullscreen mode

This is Telegram’s official bot manager.


2. Create a new bot

Send:

/newbot
Enter fullscreen mode Exit fullscreen mode

You’ll be prompted to:

  • Name your bot
  • Choose a username (must end in bot)

Example:

n1netails_alertbot
Enter fullscreen mode Exit fullscreen mode

3. Save your bot token

BotFather will generate something like:

123456789:ABCdefGhIJKlmNoPQRstuVWXyz
Enter fullscreen mode Exit fullscreen mode

⚠ Keep this private — anyone with it controls your bot.


4. Add the bot to a chat

Add your bot to:

  • A group chat
  • Or a direct chat

Ensure it has permission to send messages.


5. Get the chat ID

Option A — Use a helper bot:

@getidsbot
Enter fullscreen mode Exit fullscreen mode

Option B — Use Telegram API:

curl https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
Enter fullscreen mode Exit fullscreen mode

Look for:

"chat":{"id":...}
Enter fullscreen mode Exit fullscreen mode

You now have:

✔ Bot token
✔ Chat ID


Step 2 - Install the Library

Maven

<dependency>
  <groupId>com.n1netails</groupId>
  <artifactId>n1netails-telegram-client</artifactId>
  <version>0.3.0</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Gradle

implementation 'com.n1netails:n1netails-telegram-client:0.3.0'
Enter fullscreen mode Exit fullscreen mode

Step 3 - Configuration

Spring Boot Setup

Create a configuration class:

@Configuration
public class TelegramConfig {

  @Bean
  public BotService botService() {
    return new BotService();
  }

  @Bean
  public TelegramClient telegramClient(BotService service) {
    return new TelegramClientImpl(service);
  }
}
Enter fullscreen mode Exit fullscreen mode

Plain Java Setup

BotService service = new BotService();
TelegramClient client = new TelegramClientImpl(service);
Enter fullscreen mode Exit fullscreen mode

Step 4 - Sending Messages

Simple Text Message

TelegramMessage msg =
  new TelegramMessage("Telegram works!", false);

client.sendMessage(chatId, botToken, msg);
Enter fullscreen mode Exit fullscreen mode

GIF Message

TelegramMessage msg =
  new TelegramMessage(
    "Check this GIF!",
    "https://giphy-url.gif",
    false
  );
Enter fullscreen mode Exit fullscreen mode

CTA Button Message

Button button =
  new Button("Visit Site", "https://example.com");

InlineKeyboardMarkup markup =
  new InlineKeyboardMarkup(List.of(List.of(button)));

TelegramMessage msg =
  new TelegramMessage("Click below!", false, markup);
Enter fullscreen mode Exit fullscreen mode

Image Message

TelegramMessage msg = new TelegramMessage();
msg.setText("Photo alert!");
msg.setImages(List.of("https://image-url.png"));
Enter fullscreen mode Exit fullscreen mode

Video Message

TelegramMessage msg = new TelegramMessage();
msg.setText("Video alert!");
msg.setVideos(List.of("https://video-url.mp4"));
Enter fullscreen mode Exit fullscreen mode

Media Group (Images + Videos)

TelegramMessage msg = new TelegramMessage();
msg.setText("Media bundle!");
msg.setImages(List.of("image1.png", "image2.png"));
msg.setVideos(List.of("video.mp4"));
Enter fullscreen mode Exit fullscreen mode

⚠ Note: Telegram does not allow CTA buttons with media groups.


Important Notes

  • Media must be public URLs
  • CTA buttons only work with single media messages
  • Keep bot tokens secure

Why Use This Client?

Without the library:

❌ Manual API formatting
❌ Boilerplate HTTP calls
❌ Error-prone message building

With N1netails:

✅ Clean Java message models
✅ Structured API calls
✅ Rich media support
✅ Production-ready workflow


Final Thoughts

The N1netails Telegram Client removes friction when integrating Telegram messaging into Java applications. Whether you’re building alerts, automation, or monitoring systems, it gives you a simple and extensible foundation.

If you want fast Telegram integration without wrestling the raw API, this library is a solid choice.

👉 GitHub repository:
https://github.com/n1netails/n1netails-telegram-client

🦊 N1netails:
https://n1netails.com/

Join the Discord:
https://discord.gg/ma9CCw7F2x


If this helped you, consider starring the repo and sharing it with other Java developers. Happy building 🚀

Top comments (0)