Learn Coding
56 subscribers
21 links
Download Telegram
This media is not supported in your browser
VIEW IN TELEGRAM
🔥 1 Week Break — Build Something

You have been learning for 12 lectures straight
Variables, strings, loops, functions, files, OOP — all of it
Now it is time to actually use it

No new lecture for 1 week
Instead — build something
Anything
From scratch, using only what you have learned so far

Ideas if you are stuck:
➡️ A to-do list that saves to a file
➡️ A quiz game with scores
➡️ A contact book with search
➡️ A simple calculator with a menu
➡️ A password generator
➡️ A number guessing game with a leaderboard
➡️ A student grade tracker

But honestly — build whatever YOU want to build
The idea does not matter, the act of building does

Rules:
➡️ No copying code from the internet
➡️ Only use what was covered in Lectures 1 to 12
➡️ It does not have to be perfect — it just has to be yours

When you are done:
➡️ Screenshot your project running
➡️ Record a short screen recording of it in action
➡️ Drop it in the comments below

I will look at every single one

New lecture drops in 7 days
See what you can build 🚀
Please open Telegram to view this post
VIEW IN TELEGRAM
⚠️ Real Talk

If nobody submits anything from the break post — I am stopping this channel

I put in the effort, you put in the work
That is the deal

Build something, screenshot it, drop it in the comments
Simple as that
Please open Telegram to view this post
VIEW IN TELEGRAM
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟭𝟯 — 𝗛𝗼𝘄 𝗧𝗲𝗹𝗲𝗴𝗿𝗮𝗺 𝗕𝗼𝘁𝘀 𝗪𝗼𝗿𝗸

Python basics are done
Now we get to the actual reason you are here
Telegram Bots

But before writing a single line of bot code
You need to understand what is actually happening under the hood
Skipping this is why most beginners get confused later

This lecture covers:
➡️ What a Telegram bot actually is
➡️ The Bot API vs MTProto — two completely different things
➡️ What Updates are
➡️ Polling vs Webhooks
➡️ Creating your first bot with BotFather
➡️ Calling the raw API from your browser
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 What is a Telegram Bot?

A Telegram bot is a special account that is controlled by code instead of a human
When someone sends your bot a message — your code receives it and decides what to do

Bots can:
➡️ Send and receive messages
➡️ Show buttons and menus
➡️ Send photos, videos, files
➡️ Work in groups and channels
➡️ Accept payments
➡️ Run games and quizzes

Bots cannot:
➡️ See messages in groups unless added or mentioned (by default)
➡️ Add themselves to groups
➡️ Message users first (users must start the bot)
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Bot API vs MTProto — The Most Important Distinction

Telegram has two completely different APIs
Most beginners do not know this and get confused

Bot API:
➡️ Official simplified API for bots
➡️ Easy to use, well documented
➡️ Has limitations — cannot read all messages, limited features
➡️ Libraries: aiogram, python-telegram-bot

MTProto:
➡️ The raw protocol the official Telegram app uses
➡️ Full power — can do virtually anything
➡️ Can act as a real user account (userbot)
➡️ Libraries: Pyrogram, Telethon

We start with Bot API using aiogram
Then move to MTProto with Pyrogram and Telethon
Both are covered in this course
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 What are Updates?

Every single thing that happens on Telegram is called an Update
A message sent — Update
A button clicked — Update
Someone joining a group — Update
A photo sent — Update

Your bot's entire job is to receive Updates and respond to them

An Update looks like this in raw JSON:
{
"update_id": 123456789,
"message": {
"message_id": 1,
"from": {
"id": 987654321,
"first_name": "Ahmed",
"username": "ahmed123"
},
"chat": {
"id": 987654321,
"type": "private"
},
"text": "/start"
}
}


This is what Telegram sends your bot when someone types /start
Your code reads this and decides what to do
Libraries like aiogram handle all this for you automatically
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Polling vs Webhooks

There are two ways your bot can receive Updates

Polling:
➡️ Your bot asks Telegram every few seconds "any new messages?"
➡️ Easy to set up — works on your local computer
➡️ Slightly slower response time
➡️ Best for development and learning

Webhooks:
➡️ Telegram calls your server the instant something happens
➡️ Requires a public server with HTTPS
➡️ Faster and more efficient
➡️ Best for production deployed bots

We use polling for now — it is perfect for learning
We switch to webhooks when we deploy
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Creating a Bot with BotFather

BotFather is the official Telegram bot for creating bots
Every bot starts here

Steps:
1. Open Telegram and search @BotFather
2. Send /newbot
3. Enter a name for your bot (example: My First Bot)
4. Enter a username — must end in "bot" (example: myfirstbot_bot)
5. BotFather gives you a token that looks like this:

1234567890:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw


This token is your bot's password — never share it publicly
Anyone with this token controls your bot completely
If you accidentally leak it — go to BotFather and regenerate it immediately

Store it in a .env file — we will cover this properly next lecture
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Testing the Raw API in Your Browser

Before using any library — test the raw API directly
This shows you what is really happening underneath

Open your browser and visit:
https://api.telegram.org/bot<YOUR_TOKEN>/getMe


Replace <YOUR_TOKEN> with your actual token
You should see your bot's info in JSON format

Now send your bot a message on Telegram and visit:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates


You will see the raw Update JSON — exactly what your code will receive
This is the foundation everything is built on
Understanding this makes every library make complete sense
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 13 Homework

No code this time — just setup:

➡️ Create a bot using BotFather and save your token safely
➡️ Open your browser and test getMe — screenshot the JSON response
➡️ Send your bot a message then test getUpdates — screenshot the Update JSON
➡️ Install aiogram: open your terminal and run:

pip install aiogram


➡️ Install python-dotenv for safe token storage:

pip install python-dotenv


Screenshot everything and make sure aiogram installs without errors

⚠️ Next lecture drops tomorrow — Your First Bot
🔥 Your bot will actually respond to messages
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟭𝟰 — 𝗬𝗼𝘂𝗿 𝗙𝗶𝗿𝘀𝘁 𝗕𝗼𝘁

Last lecture you created a bot and tested the raw API
This lecture your bot actually comes alive
It will receive messages and respond to them

We are using aiogram v3 — the most professional bot library in Python
It is fully async, modern, and what production bots are built with

This lecture covers:
➡️ Project structure and .env setup
➡️ Setting up Bot and Dispatcher
➡️ Your first message handler
➡️ Running the bot with polling
➡️ Understanding async/await in bots
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Project Setup

Create a folder for your bot project with this structure:

my_bot/
├── bot.py
└── .env


Inside .env — store your token safely:
BOT_TOKEN=1234567890:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw


Never put your token directly in your Python file
Never upload .env to GitHub
Create a .gitignore file and add .env to it

# .gitignore
.env


This is not optional — leaked tokens get your bot hijacked
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Understanding async/await

Bots need to handle many users at the same time
While waiting for one user's response the bot should not freeze for everyone else
That is what async/await solves

Normal function:
def greet():
print("Hello") # runs and blocks until done


Async function:
async def greet():
print("Hello") # runs without blocking other tasks


await means "do this but let other things run while waiting":
async def handle(message):
await message.reply("Hello!") # sends reply without freezing the bot


In aiogram every handler must be async
Every Telegram API call must be awaited
You will get an error if you forget either
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Your First Bot — Full Code

import asyncio
from aiogram import Bot, Dispatcher
from aiogram.types import Message
from aiogram.filters import Command
import os
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv("BOT_TOKEN")

bot = Bot(token=TOKEN)
dp = Dispatcher()

@dp.message(Command("start"))
async def start_handler(message: Message):
await message.answer(f"Hello {message.from_user.first_name}! I am alive!")

@dp.message(Command("help"))
async def help_handler(message: Message):
await message.answer("I am a bot. Send me a message and I will echo it back.")

@dp.message()
async def echo_handler(message: Message):
await message.answer(message.text)

async def main():
await dp.start_polling(bot)

if name == "main":
asyncio.run(main())


Run this with: python bot.py
Open Telegram, send your bot /start
It responds — your bot is alive
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Breaking Down the Code

load_dotenv() — loads your .env file so os.getenv() can read it

Bot(token=TOKEN) — creates the bot object that talks to Telegram

Dispatcher() — the brain of your bot, routes messages to the right handler

@dp.message(Command("start")) — a decorator
It tells the Dispatcher: when someone sends /start, run this function

message.from_user.first_name — the sender's first name
This is the OOP we covered last section — message is an object with attributes

message.answer() — sends a reply to the same chat
message.reply() — sends a reply that quotes the original message

The echo handler at the bottom has no filter
It catches every message that did not match any other handler
Order matters — put specific handlers first, catch-all last
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this for a full visual walkthrough of setting up aiogram v3

➡️ aiogram 3 beginner series — full playlist
➡️ Official aiogram 3 docs

🔖 Watch: Aiogram Basics: Build Your First Telegram Bot (15:00) + Lesson 1 — First Handlers (23:39)
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 14 Homework

Get the echo bot running then extend it:

➡️ Add a /about command that tells the user what your bot does
➡️ Add a /time command that sends the current time

from datetime import datetime

@dp.message(Command("time"))
async def time_handler(message: Message):
now = datetime.now().strftime("%H:%M:%S")
await message.answer(f"Current time: {now}")


➡️ Make the echo handler only respond to text messages:

from aiogram.filters import F

@dp.message(F.text)
async def echo_handler(message: Message):
await message.answer(message.text)


Test all commands, screenshot the responses from your actual bot

⚠️ Next lecture drops in 2 days — Commands & Handlers
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM