PalsPantry is a Python-based Telegram bot designed to enable a single shop owner to manage an inventory of products and for customers to browse these products and place simple orders. The bot is built using the python-telegram-bot
library and emphasizes a clean, abstracted persistence layer for future flexibility.
The initial MVP focuses on core product management for the shop owner and a browse-to-order-receipt flow for customers, without real-time payment processing.
- Bot Ownership: Securely designate a single bot owner via the
/set_owner
command (first user to issue becomes owner). - Product Management:
/addproduct
: A multi-step conversation to add new products with details:- Name
- Description
- Price
- Stock Quantity
- Category
- Image (optional)
/myproducts
: View a list of all added products.- (Future MVP) Edit existing products.
- (Future MVP) Delete products.
- (Future MVP) Quick stock updates (e.g.,
/setstock <product_id> <quantity>
).
- Order Management:
- Receive notifications for new customer orders.
- Ability to view orders.
- Ability to update order status (e.g., Pending, Preparing, Ready, Completed, Cancelled).
- Browse Products:
- Start shopping via a command like
/shop
or/menu
. - Browse products by categories.
- View detailed information for each product (including image).
- Start shopping via a command like
- Shopping Cart:
- Add desired products to a temporary shopping cart (stored in user session data).
- View the cart contents (
/cart
). - (Future MVP) Modify item quantities or remove items from the cart.
- Place Order:
- "Checkout" the cart to place an order.
- The bot generates an order receipt for the customer.
- No real-time payment processing in MVP.
- Order Status:
- (Future MVP) Customers can check the status of their orders.
- Initial Setup:
- Run
/set_owner
to claim bot ownership.
- Run
- Adding a Product (
/addproduct
- In Progress):- A
ConversationHandler
guides the owner:- Bot: "What's the product's name?" -> User provides name.
- Bot: "Now, a description?" -> User provides description.
- Bot: "Price? (e.g., 10.99)" -> User provides price.
- Bot: "Quantity available?" -> User provides quantity.
- Bot: "Category? (Choose existing, type new, or skip)" -> User interacts.
- Bot: "Optionally, send an image (or /skip)." -> User sends image or skips.
- Bot: Shows a summary and asks for confirmation (
[Confirm & Add] [Edit] [Cancel]
).
- A
- Managing Products:
- Use
/myproducts
to see current inventory, with options to manage each item.
- Use
- Handling Orders:
- Receives a message when a customer places an order.
- Uses commands/inline keyboards to update the status of an order (e.g.,
/updatestatus <order_id> <status>
).
- Start Shopping:
- Customer sends
/shop
or/menu
.
- Customer sends
- Navigation:
- Bot presents categories (e.g., via inline keyboards).
- Customer selects a category to view products.
- Products are listed (potentially with pagination for many items), each with a "View Details" option.
- Product Interaction:
- Customer views full product details (name, description, price, image).
- "Add to Cart" button available on product detail view.
- Cart Management:
- Customer uses
/cart
to see items, total. - Options to modify cart (future MVP) or "Place Order".
- Customer uses
- Placing an Order:
- Customer confirms order from the cart.
- Bot provides an "order receipt" message.
- Bot informs the shop owner of the new order.
- Language: Python 3
- Core Library:
python-telegram-bot
(v20+) - Configuration:
config.py
loading from environment variables and.env
files (usingpython-dotenv
). - Logging: Standard Python
logging
module, configured inconfig.py
. - Persistence Abstraction Layer (PAL):
persistence/abstract_persistence.py
: Defines the interface for data operations.persistence/in_memory_persistence.py
: Current implementation. Stores bot owner and product data in memory. Data resets on bot restart.
- Testing:
pytest
framework.pytest-asyncio
for async tests.pytest-mock
(andunittest.mock
) for mocking.- Fixtures in
tests/conftest.py
for shared test setup.
- Conversations:
ConversationHandler
for multi-step interactions like adding products. - User Session Data:
context.user_data
for temporary data like shopping carts.
This project is being developed iteratively.
-
Milestone 1: Robust Foundation & In-Memory Persistence (✅ COMPLETE)
- Project setup, basic bot connection.
- Configuration management (
config.py
,.env
). - Structured Logging.
- Persistence Abstraction Layer (
AbstractPantryPersistence
). InMemoryPersistence
for bot owner./set_owner
command implemented using PAL.- Unit tests for core setup, owner logic, and
InMemoryPersistence
(owner part). - Extended PAL &
InMemoryPersistence
for Product Management. - Unit tests for Product Management in
InMemoryPersistence
.
-
Milestone 2: Core Product & Shop Features (✅ COMPLETE)
- The
/addproduct
feature has been successfully modularized.
- The
palspantry-telegram-bot/
├── bot_main.py # Main application logic, command handlers
├── config.py # Configuration loading
├── persistence/
│ ├── __init__.py
│ ├── abstract_persistence.py # PAL interface
│ └── in_memory_persistence.py # In-memory data storage
├── handlers/
│ └── product/
│ └── add_product.py
└── tests/
└── handlers/
└── product/
└── test_add_product.py
├── requirements.txt # Python dependencies
├── .env.example # Example environment file (actual .env is gitignored)
├── .gitignore
└── pytest.ini # Pytest configuration
- Clone the repository.
- Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up your Bot Token:
- Copy
.env.example
to.env
. - Edit
.env
and add your Telegram Bot token:BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN"
- Copy
- Run the bot:
python bot_main.py
- Run tests:
pytest
- More robust persistence
- Cloud deployment (e.g., AWS Lambda with CDK).
- Advanced UX: Richer inline keyboard navigation, pagination for long lists.
- Telegram Payments integration.
- Notifications for stock running low.
- User accounts for customers (order history, preferences).