This document explains how to set up the environment variables for the Telegram Bot Starter.
Create a .env file in the project root with the following variables:
# Bot settings
BOT_TOKEN=your_bot_token_from_botfather
BOT_NAME=YourBotName
# MongoDB settings
MONGODB_URI=mongodb://localhost:27017/tg_bot
# Admin settings - can be a single ID or a comma-separated list
ADMIN_IDS=123456789
# OR for multiple admins:
# ADMIN_IDS=123456789,987654321
# Localization
DEFAULT_LANGUAGE=en
BOT_TOKEN: The token provided by BotFather when creating a new bot- Example:
123456789:ABCdefGHIJKlmnoPQRSTUvwxyz
- Example:
BOT_NAME: A friendly name for your bot (used in logs and some messages)
-
MONGODB_URI: The connection string for MongoDB- Local example:
mongodb://localhost:27017/tg_bot - Atlas example:
mongodb+srv://user:password@cluster.mongodb.net/tg_bot
Important Notes on MongoDB URI:
- Make sure the database name (e.g.,
tg_bot) is properly separated in the URI path - If using connection parameters, add them after the database name with a question mark:
mongodb://localhost:27017/tg_bot?retryWrites=true - Do NOT include write concern in the database name part of the URI
- Local example:
ADMIN_IDS: User ID(s) of the bot administrator(s)- Single admin:
123456789 - Multiple admins:
123456789,987654321 - How to find your user ID: Send a message to @userinfobot
- Single admin:
DEFAULT_LANGUAGE: Default language code for the bot- Options:
en(English),ru(Russian) - Add more languages by following the instructions in the README.md
- Options:
- Copy the template from this document
- Create a new file named
.envin the project root - Replace the placeholder values with your actual configuration
- The bot will automatically load these settings on startup