Skip to main content
Home ← Telegram bot source ← Order-taking Telegram bot source
Level: intermediate

Order-taking Telegram bot source

Download the free source of a Telegram bot that takes the customer’s name, product and phone number step by step and saves the order in a CSV file, with a full guide.

WHAT_Order-taking Telegram bot source

A step-by-step order conversation that turns Telegram into a simple order channel.

📝 Step-by-step: name, product, phone
💾 Saves orders in orders.csv
🧾 Sends an order summary to the customer
🔄 Multi-user conversation memory
This version keeps orders in a CSV file and conversation memory in RAM. For a real project with a database and admin panel, the Filtor team can build a custom version.

Step-by-step setup guide

Follow these steps in order to get the bot running on your system or server.

Create a bot with @BotFather and copy its token.
Install Python and run pip install requests.
Paste the token into TOKEN and run python bot.py.
Send /start in Telegram and complete an order; check the orders.csv file.

The full bot source (copy or download)

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.

bot.py
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
#  Order-taking Telegram bot  |  Built by Filtor (filtori.com)
# ------------------------------------------------------------
#  This bot runs a step-by-step conversation with the customer,
#  takes the order and saves it in the orders.csv file:
#     1) customer name
#     2) the product or service they want
#     3) phone number
#  At the end it sends the customer an order summary.
#
#  Note: a Telegram bot must run on a server that has access
#     to api.telegram.org.
#
#  Full guide:
#     https://filtori.com/en/telegram-bot-source/order-bot/
#  Custom version + panel and payment?  +98 912 287 4862
#  Our Telegram: https://t.me/filtori
# ------------------------------------------------------------

import csv
import time
from datetime import datetime

import requests

TOKEN = "PASTE_YOUR_BOT_TOKEN_HERE"
BASE = f"https://api.telegram.org/bot{TOKEN}"

# The file where orders are saved (created next to this file)
ORDERS_FILE = "orders.csv"

# ------------------------------------------------------------
#  Temporary conversation memory:
#  for each user we keep track of which step of the order they are on.
#  Note: this memory is in RAM; if the bot restarts it is cleared.
#  For a real project it is better to use a database (Filtor can help).
# ------------------------------------------------------------
sessions = {}


def send_message(chat_id, text):
    url = f"{BASE}/sendMessage"
    try:
        requests.post(url, json={"chat_id": chat_id, "text": text}, timeout=15)
    except requests.RequestException as error:
        print("Error sending message:", error)


def get_updates(offset):
    url = f"{BASE}/getUpdates"
    params = {"offset": offset, "timeout": 30}
    try:
        return requests.get(url, params=params, timeout=40).json()
    except requests.RequestException as error:
        print("Error fetching messages:", error)
        return {"ok": False, "result": []}


def save_order(data):
    """Save one complete order to the CSV file."""
    is_new_file = False
    try:
        with open(ORDERS_FILE, "r", encoding="utf-8"):
            pass
    except FileNotFoundError:
        is_new_file = True

    with open(ORDERS_FILE, "a", newline="", encoding="utf-8") as file:
        writer = csv.writer(file)
        if is_new_file:
            writer.writerow(["Date", "Name", "Product", "Phone"])
        writer.writerow(
            [
                datetime.now().strftime("%Y-%m-%d %H:%M"),
                data["name"],
                data["product"],
                data["phone"],
            ]
        )


def handle(chat_id, text):
    """Step-by-step order conversation logic."""
    if text == "/start":
        sessions[chat_id] = {"step": "name", "data": {}}
        send_message(chat_id, "Hi 👋 To place an order, please write your full name:")
        return

    if chat_id not in sessions:
        send_message(chat_id, "To start an order, send the /start command.")
        return

    session = sessions[chat_id]
    step = session["step"]

    if step == "name":
        session["data"]["name"] = text
        session["step"] = "product"
        send_message(chat_id, "Thanks ✅ Now write which product or service you want:")

    elif step == "product":
        session["data"]["product"] = text
        session["step"] = "phone"
        send_message(chat_id, "Great 👌 Finally, write your phone number so we can coordinate with you:")

    elif step == "phone":
        session["data"]["phone"] = text
        data = session["data"]
        save_order(data)

        send_message(
            chat_id,
            "Your order was placed successfully ✅\n\n"
            f"👤 Name: {data['name']}\n"
            f"🛍️ Product: {data['product']}\n"
            f"📞 Phone: {data['phone']}\n\n"
            "We will contact you soon. Thanks for choosing Filtor 🙏",
        )
        del sessions[chat_id]


def main():
    print("Filtor order bot is running... (Ctrl+C to stop)")
    offset = 0
    while True:
        updates = get_updates(offset)
        if not updates.get("ok"):
            time.sleep(2)
            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:
                handle(chat_id, text)

        time.sleep(0.5)


if __name__ == "__main__":
    main()
The full source of this bot ↑ — copy or download it now

Where are the orders saved?

Each completed order is saved as a row in the orders.csv file next to the bot, with the date, name, product and phone number. You can open it in Excel.

Does the conversation memory survive a restart?

No. In this sample version the conversation memory is in RAM and is cleared on restart. For a stable version, a database should be used — the Filtor team can help.

Can it be connected to a payment gateway?

Yes, in a professional version. The Filtor team builds a custom order bot with a database, admin panel and payment gateway for your business.

about this bot

Where are the orders saved?

Each completed order is saved as a row in the orders.csv file next to the bot, with the date, name, product and phone number. You can open it in Excel.

Does the conversation memory survive a restart?

No. In this sample version the conversation memory is in RAM and is cleared on restart. For a stable version, a database should be used — the Filtor team can help.

Can it be connected to a payment gateway?

Yes, in a professional version. The Filtor team builds a custom order bot with a database, admin panel and payment gateway for your business.

CTA_Order-taking Telegram bot source

The Filtor team builds a custom order-taking Telegram bot with a database, admin panel and payment gateway, tailored to your business.

Other Telegram bot sources

→ Back to all sources   Estimate the cost of a custom bot