- Search for this Username on Telegram:
@BotFather
. - To create a new bot: type
/newbot
and click on send. - Set a Name for your Bot(This is the Display Name).
- Now, Set a unique Username(The username should end with 'bot'. For example: 'Tetris_bot' or 'tetrisbot').
- Now the bot has been created and the bot link is generated. This link can be used to access and chat with the bot.
- With this link, the Bot Token gets generated. (Note: Keep your token secure and store it safely, it can be used by anyone to control the bot).
- More on Telegram-Bot-API:
https://core.telegram.org/api
- Installing MongoDB:
sudo apt install mongodb
. - Clone this repository:
git clone https://github.com/skynet-05/Internship-QM-Telegram-API.git
. - Go into the folder:
cd Internship-QM-Telegram-API
. - Installing python dependencies all at once:
pip3 install -r requirements.txt
(If this step gives an error continue with steps 5, 6 and 7 else not required) - Installing Python package of MongoDB:
pip3 install pymongo
. - Installing Python package of Telegram:
pip3 install telegram
. - Installing Python requests package:
pip3 install requests
- Now save the bot token in config.py file. Replace
PUT YOUR BOT TOKEN HERE
with the generated token. - Full code is on
final_telegram_code.py
file. - Few changes have to be made in
final_telegram_code.py
file. - Replace
GIVE A NAME FOR YOUR DATABASE
infinal_telegram_code.py
file with a name for your DataBase. - Replace
GIVE A NAME FOR THE COLLECTIONS
infinal_telegram_code.py
file with a name for your collections in the DataBase. - Now save the file.
- Run the file by using this command
python3 final_telegram_code.py
. This code is now running and your bot is online. - You can now send messages to your bot using the bot link from any phone and and the messages can be replied back to the user from terminal where the code is running.
- All messages sent to bot from a user is store in the MongoDB database created.
- Code can be stopped by pressing
ctrl + c
from keyboard.
- Open a new terminal
- Type
mongo
and press enter. - To list all DataBases created:
show dbs
. - Now you should be able to see the database name you had given in
final_telegram_code.py
file. - To access the database:
use <NAME OF YOUR DATABASE>
(Note: do not include '<' '>'). - To list all collections in the database:
show collections
. - To print all data in the collection:
db.<NAME OF THE COLLECTION>.find().pretty()
(Note: do not include '<' '>'). - Now all data stored in the collection is printed and can be viewed.
- More MongoDB functionality can be found here -> https://docs.mongodb.com/manual/
If any issues, it can be addressed here -> https://github.com/skynet-05/Internship-QM-Telegram-API/issues