Alerts & AutomationIntermediate
10 min read

Build a Telegram Alert Bot for Vacant Berths After Chart Preparation

Learn how to monitor Indian Railways chart preparation 4 hours before departure and send instant Telegram push notifications when vacant berths open for Current Booking.

IRCTC Developer Relations
IRCTC Developer Relations
Platform Engineering
Updated 2026-10-25
Prerequisites
  • •Node.js 18+ installed locally or on a cloud server
  • •A Telegram account to create a bot token with @BotFather
  • •Free IRCTC Developer API key from https://irctc.dev/dashboard
Architecture Flow

Cron job polls https://api.irctc.dev/api/v1/trains/:trainNo/chart-vacant every 2 minutes starting 4.5 hours before departure ➔ Checks isChartPrepared === true ➔ Extracts vacant seats in 3A/2A/SL ➔ Sends rich Telegram alert with 1-click booking link.

Implementation Steps

(5 Steps)
1

Create Your Telegram Bot with @BotFather

Open Telegram, search for @BotFather, send /newbot, and follow prompts to name your bot. Save the HTTP API bot token (e.g. 7182938491:AAH...g).

bash
/newbot
# Enter name: IRCTC Vacant Berth Notifier
# Enter username: irctc_vacant_alert_bot
# BotFather returns: Use this token to access the HTTP API:
# 7182938491:AAHk1_example_token_here
Tip:Also get your personal Telegram Chat ID by messaging @userinfobot to receive test alerts.
2

Project Setup & Package Installation

Create a directory and install node-telegram-bot-api for Telegram notifications, irctc-api for real-time vacant berth checking, and node-cron for automated scheduling.

bash
mkdir irctc-telegram-alerts && cd irctc-telegram-alerts
npm init -y
npm install node-telegram-bot-api irctc-api node-cron dotenv
npm install -D typescript @types/node @types/node-telegram-bot-api ts-node
npx tsc --init
Tip:node-cron handles precise periodic polling without heavy external workflow infrastructure.
3

Configure .env Secrets

Store your Telegram credentials and IRCTC API key in .env.

bash
TELEGRAM_BOT_TOKEN=7182938491:AAHk1_example_token_here
TELEGRAM_CHAT_ID=123456789
IRCTC_API_KEY=irctc_live_9a8f2c7e01d4
Tip:Make sure TELEGRAM_CHAT_ID matches your user ID or channel ID where you want alerts delivered.
4

Implement the Chart Vacant Monitoring Engine

Create bot.ts to poll the vacant berth endpoint, filter target travel classes (e.g. 3A, 2A, SL), and dispatch formatted Telegram push alerts.

typescript
import TelegramBot from 'node-telegram-bot-api';
import { IrctcApi } from 'irctc-api';
import cron from 'node-cron';
import dotenv from 'dotenv';
dotenv.config();
const bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN!, { polling: true });
const irctc = new IrctcApi({ apiKey: process.env.IRCTC_API_KEY! });
const CHAT_ID = process.env.TELEGRAM_CHAT_ID!;
// Track alerted state to avoid spamming the user
const alertedTrains = new Set<string>();
interface WatchTarget {
trainNo: string;
boardingStation: string;
desiredClass?: string; // e.g. '3A' or 'ALL'
}
const WATCHLIST: WatchTarget[] = [
{ trainNo: '12557', boardingStation: 'NKE', desiredClass: '3A' },
{ trainNo: '26501', boardingStation: 'BTH', desiredClass: 'ALL' }
];
async function checkVacancies(target: WatchTarget) {
const watchKey = `${target.trainNo}:${target.boardingStation}`;
try {
const chart = await irctc.trains.getChartVacant(target.trainNo, {
boardingStation: target.boardingStation,
class: target.desiredClass || 'ALL'
});
// 1. Chart not ready yet
if (!chart.isChartPrepared) {
console.log(`[⏳ Wait] Train ${target.trainNo}: Chart not prepared yet.`);
return;
}
// 2. Chart prepared and vacancies found
if (chart.totalVacantBerths > 0 && !alertedTrains.has(watchKey)) {
alertedTrains.add(watchKey);
let berthBreakdown = '';
if (chart.classSummary) {
berthBreakdown = Object.entries(chart.classSummary)
.map(([cls, count]) => ` • *${cls}:* ${count} berths`)
.join('\n');
}
const alertMessage = `🚨 *VACANT BERTHS ALERT (Current Booking Open)*
🚆 *Train:* ${chart.trainNumber} - ${chart.trainName}
🚉 *Boarding:* ${chart.boardingStation}
📋 *Chart Status:* Chart Prepared ✅
🎟️ *Total Vacant Berths:* *${chart.totalVacantBerths}*
📊 *Vacancies by Class:*
${berthBreakdown}
⚡ *Action:* Open IRCTC App immediately and book under *Current Booking* before seats sell out!`;
await bot.sendMessage(CHAT_ID, alertMessage, {
parse_mode: 'Markdown',
reply_markup: {
inline_keyboard: [
[
{
text: '📲 Book on IRCTC Portal',
url: 'https://www.irctc.co.in/nget/train-search'
}
]
]
}
});
console.log(`✅ Sent alert for train ${target.trainNo}: ${chart.totalVacantBerths} berths available.`);
}
} catch (error: any) {
console.error(`Error checking train ${target.trainNo}:`, error.message);
}
}
// Poll every 2 minutes
cron.schedule('*/2 * * * *', async () => {
console.log('⏰ Running vacant berth poll cycle...');
for (const target of WATCHLIST) {
await checkVacancies(target);
}
});
console.log('🤖 Telegram Vacant Berth Alert Bot active and scheduled!');
Tip:The alert includes an inline button linking directly to the IRCTC e-ticketing portal for instant reservation.
5

Run with Docker or PM2

Keep the script running 24/7 on a cloud server so you never miss a chart preparation announcement.

bash
npx tsc
pm2 start dist/bot.js --name "vacant-berths-bot"
pm2 save
Tip:Because Current Booking tickets open 4 hours before departure, running 24/7 on a lightweight VPS guarantees timely alerts.
Production Endpoint

Vacant Berths After Charting API

Test live queries and inspect sub-100ms response payloads directly in the browser sandbox.

Frequently Asked Questions

Related Tutorials

View All Guides →