A step-by-step guide to building your own Telegram bot for degen season!
v0.0.1 (commit 1821559)
Add dependencies to the project
Activities:
- Create
requirements.txt
and addpython-telegram-bot>=20.7
- Use
pip install -r requirements.txt
to install all required modules - Use
pip freeze | grep telegram
to verify the installation
> pip freeze | grep telegram
python-telegram-bot==20.7
v0.0.2 (commit 8ee04d8)
Register for a bot using BotFather, Telegram's bot registration system
Activities:
-
Join the BotFather channel: https://t.me/botfather
-
Send command
/newbot
to start creating a new bot -
Follow the responses to give your bot a Name and username
See./artifacts/step 2 - bot-father.png
-
Create a local
.env
file and add your bot's token
Notes:
- the username must end with "bot"
- the username can only have letters, numbers, and underscores
v0.0.3 (commit 96e0025)
First steps with your degen bot
Grab the first codeblock from the PTB intro page
See: ./src/main.py
Before we begin:
The sample uses a literal TOKEN
string:warning:. We need to replace that without our own token, but for security, we don't want it embedded in our code! In this commit, we upgrade the code to use environment variables, inherited from the terminal/shell.
The sample uses async/await
to provide multitasking for python. As this project evolves, we'll compare this strategy to threads for performance and scaling.
- TODO: add a module to load the .env file.
⚠️ Sometimes called a "magic constant", literal strings and numbers that exist in code without an explanation can lead to confusion and untraceable bugs in the future.
Activities:
- Use command
export TG_TOKEN=YOUR_TOKEN_HERE
to addTG_TOKEN
to terminal/shell memory.
Verify with commandenv | grep TG_TOKEN
. - Add an import for the
os
module, then useos.getenv
to load it from the terminal/shell:
TG_TOKEN = os.getenv("TG_TOKEN")
- Run the bot:
python ./src/main.py
- Follow the link provided by BotFather and click the Start prompt or enter the
/start
command