KOSUNI KOREA
Korean News in English
Technology

Node.js Automation: Building a Telegram Notification Bot

Published October 18, 2026 · 1 views
Node.js Automation: Building a Telegram Notification Bot

[Node.JS 자동화] Node.js 자동화 프로그래밍, 반복 작업을 AI와 함께 자동화하는 실전 개발(프롤로그)


Why Do You Need a Notification Bot?

Automation programs typically run continuously on servers.

For example:

  • AI content generation

  • News collection

  • Image creation

  • Data backup

  • Scheduled tasks

These processes run automatically without manual intervention.

However, to check if the program is running correctly,

if an error has occurred,

or if a task has completed,

you need to access the server manually.

This is where a Telegram notification bot comes in handy.


What Is a Telegram Bot?

A Telegram bot is an account used by programs rather than humans.

Your Node.js program can use the bot to:

  • Send messages

  • Send images

  • Transfer files

  • Receive commands

It's one of the most commonly used notification methods in automation systems.


Creating a Bot with BotFather

In Telegram, you create new bots using BotFather.

The process is straightforward:

  1. Search for BotFather in Telegram

  2. Type /newbot

  3. Enter a bot name

  4. Enter a bot ID

  5. Receive the Bot Token

After creation, an API token is generated.

This token functions like a password and should not be shared publicly.


Managing Your Bot Token

In professional settings, you shouldn't hardcode the token in your code.

Using a .env file is recommended.

For example:

TELEGRAM_BOT_TOKEN=123456:xxxxxxxxxxxxxxxxxxxxxxxx
CHAT_ID=123456789

This approach keeps your token secure and makes maintenance easier.


Installing the Library

In Node.js, install the Telegram Bot API library:

npm install node-telegram-bot-api

Once installed, you can use it in your project.


Connecting Your Node.js Bot

First, import the library:

const TelegramBot = require("node-telegram-bot-api");

Then create your bot using the token:

const bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN, {
    polling: false
});

Your Node.js application is now ready to send messages via Telegram.


Sending Your First Message

Here's a simple example:

await bot.sendMessage(
    process.env.CHAT_ID,
    "Hello from your Node.js Telegram bot."
);

When you run the program, a message will arrive in your Telegram inbox.


Finding Your Chat ID

To send messages, you need your Chat ID.

The easiest way to find it is:

  1. Send any message to the bot

  2. Use a Telegram API or ID checking bot

You only need to check this once—it's reusable for all future messages.


Sending HTML and Markdown Messages

You can format your messages in Telegram using HTML or Markdown.

For example:

await bot.sendMessage(chatId,
"<b>Task completed</b>",
{
    parse_mode: "HTML"
});

Or:

await bot.sendMessage(chatId,
"*Task completed*",
{
    parse_mode: "Markdown"
});

This allows you to send formatted messages with emphasis.


Sending Multi-Line Messages

Organize your results neatly in multi-line messages:

const msg = `
AI content generation completed

Title: Node.js Automation
Category: Development
Image: Created

Post published
`;

await bot.sendMessage(chatId, msg);

This format is commonly used in professional settings.


Alerting on Errors

It's crucial to get immediate alerts for errors in automation systems.

try {

    await makePost();

} catch (err) {

    await bot.sendMessage(
        chatId,
        "Error occurred: " + err.message
    );

}

This way, you can spot issues without logging into the server.


Creating a Reusable Function

In your project, create a reusable function for sending notifications:

async function sendTelegram(message) {

    await bot.sendMessage(
        process.env.CHAT_ID,
        message
    );

}

You can then use it like this:

await sendTelegram("AI content generation completed");

This simplifies your code and improves maintainability.


How to Use This in Your Automation Projects

In the project we're building, Telegram notifications will be used for key events:

These notifications help you track progress without manual server checks.


Using with PM2 for 24/7 Operation

Running your program via PM2 ensures it runs continuously on the server.

When combined with Telegram notifications, you can immediately see if:

- The program stops working

- Errors occur

This is the most common operational method used in professional settings.


Avoid Overloading Your Notifications

Beginners often send notifications for every single task.

However, too many alerts can make it harder to spot important messages.

We recommend sending notifications only for:

This is sufficient for most use cases.


Continued Use in Future Projects

The Telegram bot we've built will be reused across multiple projects:

- AI blog auto-posting system

- News collector

- Image generator

- Scheduled tasks manager

- Server management program

One well-built notification system can serve many different automation projects.


Conclusion

In this lesson, we've learned how to create and integrate a Telegram bot with Node.js for real-time notifications in automation systems.

Just as important as running your system is quickly verifying results.

Adding Telegram notifications allows you to monitor completion and errors in real time, making your system more stable and reliable.

In the next lesson, we'll build a practical project: an AI blog auto-posting system that integrates all the Node.js concepts we've learned—Axios, MySQL, OpenAI API, Cron scheduling, file handling, and Telegram notifications—all into one automation workflow.

FAQ

What is BotFather?

BotFather is a Telegram bot that helps you create and manage other Telegram bots. It's used to generate API tokens for your custom bots.

Why use .env files for storing tokens?

.env files keep sensitive information like API tokens secure by not hardcoding them in your source code, making it easier to manage and protect credentials.

Korean Source

This article is an English localization of a Korean-language report from BlogScore. Original: [Node.JS 자동화] 11강. 텔레그램 알림봇 만들기