Telegram bot that is used to print data from the mango db database
This is a Telegram bot that allows users to search a MongoDB database using a mobile number.
If the number exists, the bot returns all associated details.
If not, it replies with "โ Data not found."
- ๐ Search MongoDB using a mobile number (_id)
- โ Handles errors gracefully
- ๐ Easy to set up and deploy
- ๐ Automatically reconnects to MongoDB
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
2๏ธโฃ Install Dependencies##
pip install -r requirements.txt
3๏ธโฃ Create a .env File
Create a .env file in the project directory and add your credentials:
BOT_TOKEN=your-telegram-bot-token
MONGO_URI=mongodb://localhost:27017/
DB_NAME=your_database_name
COLLECTION_NAME=your_collection_name
4๏ธโฃ Run the Bot
Copy code
python bot.py
๐ฎ How to Use 1๏ธโฃ Start the Bot
Send /start to see a welcome message.
2๏ธโฃ Search a Number
Send a mobile number (e.g., 9692307299) to search in the database.
3๏ธโฃ Response Examples If found:
โ Data Found: ๐น Name: John Doe ๐น Email: johndoe@example.com ๐น City: New York
If not found: โ Data not found.
โ๏ธ Deployment (Optional) Deploy on a Linux Server (Auto-Restart) Run the bot using screen
screen -S telegram-bot
python bot.py
Press CTRL + A, then D to detach.
To restart the bot automatically if it crashes, use:
while true; do python3 bot.py; sleep 5; done
๐ Troubleshooting Bot not responding? Check if BOT_TOKEN is correct. Ensure MongoDB is running (systemctl start mongod). MongoDB connection error? Verify MONGO_URI in .env file.
๐ค Contributing Fork the repo Create a new branch (git checkout -b feature-branch) Commit changes (git commit -m "Added feature") Push (git push origin feature-branch) Open a Pull Request ๐
๐ License This project is open-source under the MIT License.
โญ๏ธ Show Some Love! If you found this project useful, give it a star โญ๏ธ on GitHub!