TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shadownrx/apisquare/llms.txt
Use this file to discover all available pages before exploring further.
/api/webhook endpoint is the heart of ApiSquare — Telegram delivers all bot updates here as POST requests. The handler processes both plain text messages and inline-keyboard callback queries, maintaining per-user conversation state in Vercel KV so multi-step booking flows survive across separate Telegram messages. No authentication is required; Telegram calls this endpoint directly on your behalf.
POST /api/webhook
Telegram sends a JSON-encoded Update object in the request body every time a user interacts with the bot.Processing Pipeline
The handler executes the following steps in order on every incoming update:- Deduplication — checks
update_idagainst a KV key (processed:update:{update_id}) with a 10-minute TTL to skip replayed updates. Falls back to an in-memorySetwhen KV is unavailable. - Rate limiting — enforces a per-user limit of 20 messages per 60-second window based on the
chat.idextracted from either themessageorcallback_queryfield. - Routing — dispatches to the callback-query handler if
update.callback_queryis present, otherwise to the text-message handler. - Reply — sends responses to the user via the Telegram Bot API using
sendMessageoranswerCallbackQuery. - Always
200 OK— returns{"status":"ok"}regardless of outcome.
Request Body
Telegram delivers amessage update when the user sends text:
callback_query update when the user taps an inline keyboard button:
Telegram’s monotonically increasing update identifier. Used by the deduplication layer to skip already-processed updates within a 10-minute window.
Present on text/command updates. Must contain at least
message.chat.id and message.text.Present on inline-button tap updates. Must contain
callback_query.id, callback_query.message.chat.id, and callback_query.data.Response
The endpoint always returnsHTTP 200:
The webhook always returns
HTTP 200 {"status":"ok"} — even when an
internal error occurs. This prevents Telegram from retrying the same update,
which would cause duplicate messages or duplicate bookings.GET /api/webhook — Verification Endpoint
ReturnsHTTP 200 {"status":"ok"} immediately. This route exists so that Telegram (and any infrastructure probe) can verify the webhook URL is reachable before sending live updates.
Request
Supported Text Commands
The message handler normalises incoming text to lowercase and trims whitespace before matching. The following inputs are recognised as top-level intents:| Command / Text | Action |
|---|---|
/start, start, hola, hello, buenos días, buenas tardes, buenas noches, hey | Clear conversation state, show main menu |
/servicios, servicios, servicio, /categorias, categorias, categoria, que servicios hay | List all available services with prices |
/misreservas, mis reservas, misreservas, reservas, ver reservas, ver mis reservas | Show the user’s active reservations |
/reservar, reservar, reservar turno, quiero reservar, agendar, quiero agendar, hacer una reserva | Begin the multi-step booking flow |
Rate Limiting
ApiSquare enforces a per-user rate limit to protect against abuse and excessive KV reads.| Parameter | Value |
|---|---|
| Maximum requests | 20 messages |
| Window duration | 60 seconds |
| Scope | Per chat.id |
| KV key | ratelimit:user:{chatId} |
| KV TTL | 60 seconds |
- If the triggering update is a callback query, Telegram receives an
answerCallbackQuerycall with the warning text⚠️ Demasiadas solicitudes. Esperá un momento. - If it is a text message, the bot sends
⚠️ Estás enviando demasiados mensajes. Por favor esperá un momento antes de continuar.
HTTP 200 {"status":"ok"} immediately after responding.
The
chatId used for rate limiting is extracted from whichever field is
present in the update: update.message.chat.id for text messages or
update.callback_query.message.chat.id for inline-button taps.Conversation State
ApiSquare maintains multi-step booking state in Vercel KV under the keyconv:{chatId}. State is a JSON object of type ConversationState:
paso field drives the state machine. Recognised values are: profesional, servicio, nombre, fecha, hora, and confirmar. Sending /start (or any greeting) clears this state entirely, restarting the flow.
Environment Variables
| Variable | Required | Description |
|---|---|---|
TELEGRAM_TOKEN | ✅ Yes | Bot token from @BotFather. Used for all Telegram Bot API calls. |
KV_REST_API_URL | Recommended | Vercel KV REST endpoint. Required for persistent state, deduplication, and rate limiting across serverless invocations. |
KV_REST_API_TOKEN | Recommended | Auth token for the Vercel KV REST API. Must be paired with KV_REST_API_URL. |