MODULE 4.1
Telegram as work interface
Run a restricted query bot and understand where AI comes in.
What it is
A bot receives messages via the Telegram API and returns responses. Intelligence can come from rules, a program, or a model call. The mobile app does not execute its tasks on the server by itself: there is an intermediate program with defined permissions.
Why learn
Separating interface and execution avoids calling any automatic response an intelligent agent. First build a reliable path to receive and reply; then connect the needed capability.
Key concepts
Message; Bot API; program; agent; result.
What it is
In Telegram, find the official BotFather and use /newbot. Choose a name and identifier as shown in the instructions. The generated token authenticates your program with Telegram. Store it as TELEGRAM_BOT_TOKEN in a private file; the kit only contains example values.
Why learn
Anyone who controls the token can operate the bot. Screenshots of the process and URLs containing the token can leak access. If exposed, revoke the token in BotFather before continuing.
Key concepts
BotFather; token; environment variable; rotation.
What it is
The kit bot only accepts private chats and configured IDs. It also accepts only known commands. Verifying the ID is different from checking the visible name: names can change. A message from an unknown user should not trigger file reads or system commands.
Why learn
A bot found on the internet may receive unexpected messages. Program authentication with a token does not mean authorization for anyone who talks to it. These are separate controls.
Key concepts
Numeric ID; access list; private chat; fixed commands.
What it is
Long polling is the program asking Telegram for messages and waiting a bit when there are no new ones. It is simple to learn and does not require opening a public inbound port. Webhook is another strategy, where Telegram calls your HTTPS address; it is not needed in this lab.
Why learn
Choosing a single mode reduces configuration problems. Keep only one instance fetching messages for a bot: duplicate processes can compete for updates.
Key concepts
getUpdates; offset; timeout; single instance; outbound access.
What it is
The kit deliberately separates transport and work functions. It starts deterministic: status and report of fake data. To attach AI, define a function with limited input, timeout, output ceiling, and review. Do not expose codex exec directly to public messages nor disable protections to make it work.
Why learn
A predictable program allows testing the base without spending API. Then you assess whether AI improves interpretation, summarization, or classification and measure the result against a known reference.
Key concepts
Domain function; limits; timeout; review; minimal data.
What it is
Test allowed sender, blocked, group, unknown command, and missing data. Logs should report the type of failure and timestamp, without the token or full private messages. In the lab, stopping the process should halt responses: this proves the local program is on the path.
Why learn
A correct response does not prove the bot is restricted nor that it retrieves the network. A small set of scenarios demonstrates the important properties before migrating to a VPS.
Key concepts
Self‑test; network failure; logs without secrets; interruption; diagnosis.