PRACTICAL CASE · 02
How an AI agent in Telegram stops being a dumb autoresponder
A user sends a single message, but the bot responds off-topic: it cannot see the context, confuses the subject, and triggers unnecessary actions.
Situation
Start by defining the input and the expected result. The bot must understand whether it has received a question, file, task, or command. Do not start with a long prompt: first add a router and a clear response for uncertain cases.
What to do
Create a token through BotFather and store it in `.env`. Restrict access to your Telegram ID. Separate the modes: `answer`, `analyze`, `approve`. Use a separate permission for reading chats, and do not combine it with the bot.
Verifying the result
Test: send a question about the weather, then a financial screenshot, then “send an email.” The first two requests are processed, while the third command creates a confirmation request. Sending the same message again must not create a second job.
What usually breaks
A duplicate response means deduplication is missing. A “specify the domain” response to an already clear question means that routing runs after the wrong filter. Fix state and context first, then the prompt.