A TypeScript-based Telegram userbot that automatically posts messages to all groups you're a member of at configured intervals. The bot deletes the previous message before posting a new one in each group.
- ✅ Automatically fetches all groups you're a member of
- ✅ Posts messages at configurable intervals
- ✅ Deletes previous message before posting new one
- ✅ Real-time console logging
- ✅ Proper account authentication
- ✅ TypeScript with full type safety
- ✅ ESLint and Prettier configured
- ✅ Hot reload with Nodemon
- Node.js (v18 or higher)
- npm or yarn
- Telegram API credentials (API ID and API Hash)
- Go to https://my.telegram.org/apps
- Log in with your phone number
- Create a new application
- Copy your
api_idandapi_hash
- Clone or download this repository
- Install dependencies:
npm install- Create a
.envfile in the root directory:
cp .env.example .env- Edit
.envand add your credentials:
API_ID=your_api_id
API_HASH=your_api_hash
POST_INTERVAL_MS=60000- Create
config/message.txtfile with your message (or setMESSAGEin.env):
mkdir -p config
echo "Your message here" > config/message.txtNote: The config/message.txt file takes priority over the MESSAGE environment variable. If the file doesn't exist, it will fall back to the MESSAGE env var.
API_ID: Your Telegram API ID (from https://my.telegram.org/apps)API_HASH: Your Telegram API HashSESSION_NAME: Name for the session file (default: "session", saved inconfig/directory)POST_INTERVAL_MS: Interval between posts in milliseconds (default: 60000 = 1 minute)MESSAGE: The message to post in groups (optional -config/message.txttakes priority)
The bot uses a config/ directory in the project root for storing:
- Session files:
config/{SESSION_NAME}.session- Automatically created after first authentication - Message file:
config/message.txt- Your message to post (create this file or useMESSAGEenv var)
The config/ directory is automatically created on first run.
npm run devnpm run build
npm start# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Check formatting
npm run format:checkOn the first run, the bot will:
- Connect to Telegram
- Ask for your phone number
- Send you a verification code
- Ask you to enter the code
- Once authenticated, it will fetch all your groups
- Start posting messages at the configured interval
After the first authentication, the session will be saved and you won't need to authenticate again.
- Startup: The bot connects to Telegram and authenticates if needed
- Group Fetching: Retrieves all groups and channels you're a member of
- Posting: For each group:
- Deletes the previous message (if exists)
- Posts the configured message
- Schedules the next post based on
POST_INTERVAL_MS
- Logging: All actions are logged to the console in real-time
Press Ctrl+C to gracefully stop the bot. It will:
- Stop all posting intervals
- Disconnect from Telegram
- Exit cleanly
.
├── src/
│ ├── index.ts # Main entry point
│ ├── bot.ts # Bot logic and posting
│ ├── config.ts # Configuration loader
│ └── logger.ts # Logging utility
├── config/ # Configuration directory (auto-created)
│ ├── session.session # Session file (auto-created after auth)
│ └── message.txt # Message file (create this)
├── dist/ # Compiled JavaScript (generated)
├── .env # Environment variables (create this)
├── .env.example # Example environment file
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .eslintrc.json # ESLint configuration
├── .prettierrc.json # Prettier configuration
└── nodemon.json # Nodemon configuration
- The bot requires you to be a member of the groups you want to post to
- Make sure you have permission to send messages in the groups
- The bot deletes its own previous messages before posting new ones
- Session files are stored in
config/directory and should be kept secure - Message is read from
config/message.txt(falls back toMESSAGEenv var if file doesn't exist) - The
config/directory is automatically created on first run
MIT