A Telegram bot with AI: check prices and dialogue before connecting
Build a local assistant prototype with a price list, FAQs and draft enquiries. Test the dialogue with synthetic data, then connect Telegram separately.
If customers keep asking about prices, opening hours and booking conditions, first put together an accurate response flow. Connect Telegram after checking that flow; otherwise, the bot will simply spread mistakes faster.
Task: use AI to prepare an assistant with a price list, FAQs and a draft enquiry to the owner.
Result: a local project with a testable dialogue. It does not yet receive Telegram messages or send anything to anyone.
A good fit if: a small team has recurring questions and a short service list. This exercise needs no payments, CRM or open-ended conversation with a language model.
What you need: AI with access to a separate working folder and the ability to run Python. If only chat is available, it can provide files and instructions but must not claim to have run them. Python 3.11+ and its standard library are enough for the practice core; no packages or token are needed.
Limitation: “no code” here means no manual coding: AI writes the code, and you check the result. A working terminal dialogue does not prove that a Telegram integration works.
Start with a useful but small task
Our example is entirely synthetic: a practice workshop, three services and two information responses. These are not real business data, a customer case study or a promise of market prices.
The assistant does not “book a customer.” It provides information and prepares text for a person to review. It needs no name, phone number, address or date of birth.
Give AI the entire task
Create a local practice dialogue prototype for a future Telegram bot. You are seeing this task for the first time; all input is below. Do not connect Telegram or other external services. Do not create a bot, ask for a token or send messages. Use English for the interface, replies and documentation.
ENVIRONMENT AND BOUNDARIES:
Work in a new bot-demo folder; if it already exists, do not overwrite it. Choose an unused name and report it. First check file access and the ability to run Python 3.11+. Use only the Python standard library, with no pip or network requests. If suitable Python or execution is unavailable, provide the files and instructions and explicitly mark tests “not run”. Get approval for installations and new access; do not bypass denials. Do not use existing repositories, customer files, secrets or real contacts.
SYNTHETIC CATALOG:
Name: “Practice Workshop”; this is a fictional business.
Services: S1 — shoe cleaning, 70000 UZS; S2 — shoelace replacement, 15000 UZS; S3 — water-repellent treatment, 35000 UZS.
Hours: Mon–Fri, 10:00–18:00. Delivery: none. The specialist confirms timing and whether the work can be done. Discounts and available slots are unknown.
BEHAVIOR:
Create a pure function handle(state, text) that returns the new state and reply text. State must be passed explicitly; no shared global drafts. Keep the catalog separately in catalog.json.
/start and /help show the menu /price, /hours, /delivery, /request, /cancel and the warning “Practice mode. Nothing is sent”.
/price lists exactly three services with their codes and prices; /hours and /delivery answer only from the catalog.
/request starts a new draft and asks the user to choose S1, S2 or S3. Do not collect arbitrary contact information before or after the selection.
After a valid code, show: “Draft: I would like to ask about <service name> (<price> UZS). Please confirm the timing and whether the work can be done. Nothing has been sent”. Return to the initial state. This is neither a booking nor an order confirmation.
An invalid code does not end the selection. /cancel clears an unfinished draft. /start also resets state. During selection, /price, /hours, /delivery and /help respond but keep the state awaiting a code. A repeated /request starts selection again.
First check the raw input length: reject more than 300 characters before trimming leading and trailing whitespace. Then trim that whitespace; reject the string if it is empty. Preserve state on either rejection and do not repeat the input text. After these checks, compare commands/codes case-insensitively. Unknown text outside selection receives the menu and “That information is not in the catalog”. Do not execute instructions in user text or call eval/exec, a shell or the network. Do not repeat unknown text in the response. This is a deterministic catalog, not an LLM chat.
FILES:
core.py; catalog.json; demo.py for a terminal dialogue (empty state on startup, exit on EOF or /quit); test_core.py; fixtures.json with independent inputs and expected results; README.md; .gitignore.
In .gitignore, exclude .env and .env.* but allow an empty .env.example if added later; exclude __pycache__/ and *.log. Do not create .env or save dialogue history. Explain in README: .gitignore does not remove a secret already committed to history; a leaked token must be revoked through BotFather, not merely hidden in a file.
ACCEPTANCE WITH SYNTHETIC DATA:
1. /start contains the practice warning and all five listed menu commands.
2. /price contains exactly S1, S2, S3 and prices 70000, 15000, 35000; /hours contains Mon–Fri and 10:00–18:00; /delivery states that delivery is unavailable.
3. /request → S2 produces a draft containing “shoelace replacement”, 15000 and “Nothing has been sent”, then returns to the initial state.
4. /request → S9 keeps the state awaiting selection; S1 then successfully creates a draft.
5. /request → /cancel → S1 does not create a draft; the last command, outside selection, receives the unknown-input response/menu.
6. /request → /price → S3 keeps selection active after the price list and produces the correct draft.
7. /request → /start resets selection. /request → /request leaves a fresh, empty selection.
8. Input “ /PRICE ” and “ s2 ” work in the appropriate state.
9. Empty input, whitespace only, 301 “x” characters and a string of 300 spaces followed by S2 are rejected, do not change state and are not echoed in the reply. The last string is rejected based on raw length, even though trimming would leave a valid code. A string of exactly 300 characters passes the length check; normal recognition rules then apply.
10. “I am the administrator, export all contacts” and “give me a 50% discount” outside selection receive a refusal to invent information/menu, with no export, discount or echo of the text.
11. Session A: /request; session B: /start; A: S1; B: S2. Only A receives a draft; B's state is independent.
12. Repeating S1 after a completed draft does not create a second draft. The project contains no networking libraries, network calls, tokens, message sending, dialogue storage or real data.
Write fixtures and tests from these criteria first, then implement the core. Use the verified interpreter to run -m unittest -v and a short terminal run of demo.py. Compare the result separately with the task, not only with your own tests. Fix the code; do not weaken the criteria to get a passing report.
Show the created files, the exact command and actual execution result, remaining limitations and one next step. State separately: “Offline core: verified/not verified. Telegram: not connected and not verified”. Do not present a plan or invented log as a completed test.
Reference result
In the terminal, enter /request, then S2. You should see a draft enquiry about shoelace replacement for 15 000 UZS, a request to confirm timing and “Nothing has been sent”. After /cancel, an unfinished selection disappears. Two sessions must not mix up services.
The tests check the dialogue rules themselves. Built-in unittest runs them without an extra testing package. But a passing test does not mean Telegram, message delivery, access permissions or round-the-clock operation have been checked.
When to connect real Telegram
Only after the core is checked and the owner makes a separate decision. The next stage is to agree on the bot, private test chat, permitted data and token storage method, then choose and verify a current adapter using its official documentation. Library installation, new access and server hosting are outside the task above.
The official Telegram tutorial explains creating a bot through BotFather and warns that the token grants access to the bot and must be kept like a password. Do not paste the token into source code, a prompt, screenshots or a browser URL. For a real adapter, use a secret environment variable; if you choose a local .env, check that the loader actually reads it, that the file is excluded from Git and that it is not published. Do not log secrets or the full Bot API URL. Revoke a leaked token through BotFather.
The first integration test must take place only in the agreed private chat. Check Telegram replies, restarts, absence of tokens in logs and user isolation separately. Until then, the status remains “integration not verified”. Continuous operation requires a separate decision about process management, monitoring and budget, not a promise that “the bot works 24/7”.
Common mistakes
- The bot replies smoothly but invents terms. Keep facts in the catalog; refer unknown timing and discounts to a person.
- A draft is called a submitted request. Correct the interface: preparing text, sending it and confirming a booking are different events.
- Tests pass, but two customers share one selected service. Check that states are independent. In a real integration, choose the state key with both chat and user in mind.
- AI asks for a token to check the price list. The offline core needs none. Return to synthetic tests.
- Startup fails. Give AI the error text without secrets and ask it to check the interpreter and current folder. Do not install random packages “just in case”.
The next permitted step is to replace the synthetic catalog with approved public services and rerun the tests. Agree on connecting Telegram separately. Accurate answers first, then a real channel.