Download the free source of the simplest Telegram bot that greets the user and echoes their messages, with a full step-by-step guide. Written in Python with only the requests library.
A minimal but complete starting point to understand how a Telegram bot works.
Follow these steps in order to get the bot running on your system or server.
pip install requests in the terminal.TOKEN variable and run python bot.py./start to your bot in Telegram and see the welcome message.This is the same code as in the ZIP file. You can copy it right from here. Just remember to replace the TOKEN value with your own bot token.
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
# Welcome Telegram bot | Built by Filtor (filtori.com)
# ------------------------------------------------------------
# This is the simplest possible example:
# - sends a welcome message on the /start command
# - echoes back any text message the user sends
# Written using only the requests library, with no other dependency.
#
# Note: a Telegram bot must run on a server that has access
# to api.telegram.org.
#
# Full illustrated guide:
# https://filtori.com/en/telegram-bot-source/welcome-bot/
# Need a professional, custom version? Call: +98 912 287 4862
# Or message us on Telegram: https://t.me/filtori
# ------------------------------------------------------------
import time
import requests
# 1) Get your bot token from @BotFather in Telegram and paste it here.
TOKEN = "PASTE_YOUR_BOT_TOKEN_HERE"
# Telegram API base address
BASE = f"https://api.telegram.org/bot{TOKEN}"
def send_message(chat_id, text):
"""Send a text message to the user."""
url = f"{BASE}/sendMessage"
data = {"chat_id": chat_id, "text": text}
try:
requests.post(url, json=data, timeout=15)
except requests.RequestException as error:
print("Error sending message:", error)
def get_updates(offset):
"""Fetch new messages using long polling."""
url = f"{BASE}/getUpdates"
params = {"offset": offset, "timeout": 30}
try:
response = requests.get(url, params=params, timeout=40)
return response.json()
except requests.RequestException as error:
print("Error fetching messages:", error)
return {"ok": False, "result": []}
def main():
print("Filtor welcome bot is running... (press Ctrl+C to stop)")
offset = 0 # id of the last update we processed
while True:
updates = get_updates(offset)
if not updates.get("ok"):
time.sleep(2) # on error, wait a bit and try again
continue
for update in updates.get("result", []):
offset = update["update_id"] + 1
message = update.get("message")
if not message:
continue
chat_id = message["chat"]["id"]
text = message.get("text", "")
if text == "/start":
send_message(
chat_id,
"Hi 👋 Welcome to our bot!\n"
"Whatever you type, I will send it right back to you.\n"
"This bot was built with ❤️ by Filtor: filtori.com",
)
elif text:
send_message(chat_id, f"You said: {text}")
time.sleep(0.5)
if __name__ == "__main__":
main()
Yes, the full source of the welcome bot is completely free and downloadable without registration. You can use it in your own projects.
Just Python and the requests library, plus a bot token from BotFather. No database or extra tools are needed for this bot.
The bot needs a server that can reach api.telegram.org. If you want us to set it up on a stable server for you, the Filtor team can help.
Yes, the full source of the welcome bot is completely free and downloadable without registration. You can use it in your own projects.
Just Python and the requests library, plus a bot token from BotFather. No database or extra tools are needed for this bot.
The bot needs a server that can reach api.telegram.org. If you want us to set it up on a stable server for you, the Filtor team can help.
The Filtor team builds a custom Telegram bot with an admin panel, database and payment, tailored to your business — from a simple welcome bot to a full sales system.