Commands and inline buttons: building a short reader journey

Catalogue, card, Back and Cancel: a Python storyboard and separate loopback HTTP adapter, simulated ACK, and evidence limits without Telegram API calls.

A short journey preserves a clear path forward and back.

A reader opens a journal bot to find an article. They need a clear starting point, a short list, and a way back. If every button sends another menu and Back resets the selected topic each time, the number of available features only makes that task harder. Message transport can work correctly while the reader's journey remains inconsistent.

Consider an independent teaching journal with synthetic cards. We will build the path /start → catalogue → article card and define what old buttons, returning, and cancelling mean. A local Python model and a clickable storyboard help verify our transition rules. Message delivery, rendering in Telegram, and usability for real readers require different checks.

A command starts the journey; a button continues its context

A command is useful as a known entry point. /start opens the beginning, /catalog opens the catalogue, /help explains the available functions, and /cancel discards an unapplied selection. Each article does not need its own command: the command list would soon become a second catalogue to maintain alongside the first.

Telegram supports commands in a menu and different sets for different scopes. A command appearing in a menu, however, is not an access check: the server must validate the received action. The command documentation states this explicitly. The teaching model accepts already-normalized commands; parsing complete Updates, mentions, and deep-link parameters is outside its scope.

Inline buttons belong to a particular message. They are useful for moving between a card and a list because available actions appear beside the content. The inline keyboard documentation also describes editing the keyboard during navigation. In our model, a click produces a proposal to replace the navigation message. A real adapter still has to carry out that intention and handle the API response.

Define states and return behavior first

A small table is a useful way to describe the journey. It forces us to decide exactly what survives a transition before choosing colors or button labels.

State What the reader sees What returning means
Home The journal's purpose and an entry into the catalogue Start a new journey
Catalogue The current topic and page of cards Move to an adjacent page or return home
Card Title, short description, and link Restore the catalogue topic and page
Topic selection A temporarily selected value Cancel it or apply it explicitly
Help Commands and the meaning of buttons Return to the catalogue or home

The example shows 2 cards per page. This is a teaching value, not a proven optimal screen capacity. The catalogue has a stable order of synthetic records. A card remembers the page from which it was opened; applying another topic starts a new filtered list on its first page.

This context belongs to a particular local session. It is not the history of every message, and it does not automatically move between devices. A real bot needs an explicit context scope: the bot, user, chat, and particular navigation message. A page number alone cannot provide that scope.

A callback carries a choice, not permission to act

A navigation button needs only a short action address: open a known card or return to the list. The article body, an arbitrary URL, and user permissions do not belong in a callback. The InlineKeyboardButton contract limits callback_data to 1–64 bytes. Our narrow format uses ASCII to keep the boundary obvious; the general API bound concerns UTF-8 bytes.

An illustrative card keyboard has different button types:

{
  "inline_keyboard": [
    [
      {
        "text": "Read the article",
        "url": "https://journal.example/articles/a3"
      }
    ],
    [
      {
        "text": "Back to list",
        "callback_data": "n1:0123456789abcdef:7:catalog"
      }
    ]
  ]
}

A URL button opens an address. A callback button returns the selection data to the server. In the example, each has only one of those two action types. The address uses a synthetic domain, and the callback value illustrates the format; this is not a record of a received message.

The model checks the local session tag, screen revision, and set of actions the server actually offered on that screen. It then reads the article's availability again. This rejects a forged route but does not replace authentication or a real user's permissions. The CallbackQuery data should not itself be treated as proof that the corresponding button is still present in the message, either.

Back and Cancel make different promises

Back to list restores the reading position. If a card was opened from a later page of a particular topic, returning to the overall beginning forces the reader to find it again. If the last page has become empty in the meantime, the model selects the nearest remaining page and displays current cards.

Cancel works on an unfinished selection. On the topic screen, the currently applied value is stored separately from the draft. Choosing another topic changes only the draft; Apply moves it into the catalogue context; Cancel discards it while preserving the previous list. The /cancel command makes the same limited promise.

This is navigation state held in process memory. It is not a subscription, bookmark, or account setting. If a button changed that kind of business state, separate access, confirmation, and retry rules would be required. Returning to an earlier screen does not by itself undo a committed action. A button label should therefore name the specific consequence instead of vaguely promising to cancel everything.

An old button should lead to understandable recovery

A message can outlive its context. The reader opened another page, returned to an old message, or pressed the same button again. Accepting that callback as a new current selection threatens the journey's consistency even when every article is public.

In the model, each new presentation receives the next revision. A callback from an earlier revision opens the current catalogue with an explanation; it does not repeat the temporary topic selection. An unknown action or another session's tag also leads to controlled recovery. If an article is unpublished after the list was shown, its text and URL are no longer returned.

This policy deliberately supports one active journey per local session. Two browser tabs sharing that session can display different revisions, so the older tab will receive catalogue recovery. Several independent navigation messages need separate contexts. The old-button rule is also not a business-operation idempotency mechanism: it protects screen sequencing rather than guaranteeing that money is charged or a message sent only once.

Acknowledging the click and performing the transition are separate steps. Telegram expects answerCallbackQuery to end the waiting indication after a callback. The local model merely sets the corresponding flag in the adapter plan, including for a rejected button. It neither makes the call nor proves that Telegram accepted the answer.

One transition mechanism for the storyboard and checks

The clickable example starts a small HTTP server on loopback only. HTML forms send commands and callbacks to the same Python model used by the checks. There is no separate copy of the rules in JavaScript. The website button displays the synthetic address without navigating outside the example.

The server escapes card text, rejects ambiguous forms, and checks the local session, request origin, and form token. These constraints support a controlled teaching interaction. They do not turn the example into a production service: the http.server documentation explicitly limits that server's intended use. Restarting the process loses every local session.

All 18 scenarios produced their expected outcomes in the local run. They cover reaching a card, returning to the correct page, applying and cancelling a topic, repeating an old callback, forged actions, an empty catalogue, and an article that has become unavailable. Separate checks cover button structure, HTML escaping, and refusing to overwrite the report file. These verify a specific model; they do not measure interface speed or usability.

An HTTP adapter to an owned loopback simulator

A separate narrow Python adapter wraps the unchanged Navigation. It accepts a synthetic private command/callback subset and checks bot/user/chat/message binding; trusted local context supplies bot identity. This implements neither a complete Telegram Update parser, webhook authentication, nor production ACL.

LoopbackClient makes real POST JSON requests only to its owned 127.0.0.1 simulator. Only answerCallbackQuery, editMessageText, and sendMessage are permitted, without tokens, proxies, redirects, or a Telegram endpoint. The simulator checks bodies, inline keyboards, and bounded callback bytes under its own test contract. Its response is not a Telegram acknowledgement.

A callback first computes proposed Navigation state on a copy. Only a positive simulated ACK commits that state; a negative ACK preserves state/revision/routes, keeping the already visible Cancel usable. ACK precedes edit. Only the specific simulated message-to-edit-not-found refusal permits one send fallback with a new active message ID. Other ACK/edit/send failures propagate without automatic retry.

After a positive ACK or command, state may already have changed before rendering fails. Memory state and the HTTP effect share no transaction and provide no durable idempotency. Simulator method names prove neither a real spinner, a Telegram message edit, nor delivery.

The separate corrected adapter run completed 25/25 checks and 73 owned loopback POST requests, including negative body cases. Telegram/provider calls were 0 and no test bot was used. The historical 18 model scenarios and their six source files remained unchanged and were not rerun. These are two separate forms of evidence rather than 43 newly executed scenarios.

Run the additional stdlib experiment from its example directory, using a new report file outside the sources:

ADAPTER_WORKSPACE="$(mktemp -d)"
python3 -B run_adapter_lab.py --report "$ADAPTER_WORKSPACE/report.json"

Moving into Telegram needs separate evidence

After the local exercise, the journey still needs to run on a separate test bot. Telegram describes this separation of testing so that checks do not affect the main bot's users. No such bot or real API calls were used for this article.

The real Telegram adapter still must connect the model to a verified context, turn the plan into concrete calls, and handle failures. In particular, editMessageText has its own parameters and execution conditions; changing a local object does not prove that a Telegram message was edited. The real labels, link opening, repeated presses, and an unavailable old message also need to be observed in the client.

An acceptance criterion should describe the reader's action: after returning they see the same applied selection; after cancelling there is no new subscription; after rejection there is an available way forward. A local check result should not be extended to delivery, support for every client, or correctness of the future adapter.

A short journey emerges when every transition preserves a clear promise: open an article, restore a position, or discard only an unfinished selection. The state table and local example make that promise testable. Whether readers find it sufficiently clear requires a separate check with people, rather than a count of the buttons in the menu.

  1. Distribution A stale callback: menu versions and authorization when the action runs
  2. Distribution One webhook for several bots: choosing the right context
  3. Distribution A bot conversation as a state machine: pause, cancellation, and return