--- phase: 03-container-actions plan: 02 subsystem: telegram-callbacks tags: [callback-query, inline-keyboard, telegram-api, n8n, http-request] # Dependency graph requires: - phase: 03-01 provides: Basic container actions with match routing provides: - Callback query handling for inline buttons - Did-you-mean suggestion flow for typos - 2-minute confirmation timeout - Message cleanup after button clicks affects: [03-update-flow, 04-logs] # Tech tracking tech-stack: added: [] patterns: - "HTTP Request node for Telegram inline keyboards (workaround for native node bug)" - "Callback data JSON encoding with short keys for 64-byte limit" - "Stateless confirmation via timestamp in callback_data" - "answerCallbackQuery + deleteMessage for UI cleanup" key-files: created: [] modified: - n8n-workflow.json key-decisions: - "Use HTTP Request for sendMessage with inline_keyboard (native Telegram node doesn't support dynamic keyboards)" - "Encode action as single char (s/t/r/x) to fit in 64-byte callback_data limit" - "2-minute timeout enforced client-side via timestamp comparison" - "Delete suggestion message after any button click for clean UI" patterns-established: - "Callback query routing: Route Update Type -> IF Callback Authenticated -> Parse Callback Data -> Route Callback" - "Score-based fuzzy matching for suggestions (score >= 2 required)" - "Three-branch callback handling: cancel, expired, execute" # Metrics duration: 15min completed: 2026-01-30 --- # Phase 03 Plan 02: Callback Query Handling Summary **Inline button infrastructure with did-you-mean suggestions using HTTP Request for Telegram API and stateless callback_data encoding** ## Performance - **Duration:** 15 min - **Started:** 2026-01-30T13:27:00Z - **Completed:** 2026-01-30T13:42:00Z - **Tasks:** 3 - **Files modified:** 1 ## Accomplishments - Telegram Trigger now receives both message and callback_query updates - Route Update Type switch separates message vs callback flows - IF Callback Authenticated validates user before processing callbacks - Find Closest Match scores containers and suggests best match for typos - Build Suggestion Keyboard creates inline_keyboard JSON with short callback_data - Send Suggestion uses HTTP Request to Telegram API (workaround for native node limitation) - Full callback flow: Parse -> Route -> Handle (Cancel/Expired/Execute) - Cancel: answer query "Cancelled", delete suggestion message - Expired: answer query with alert, delete message - Execute: run Docker action, answer query, delete message, send result ## Task Commits Each task was committed atomically: 1. **Task 1: Configure Telegram Trigger for callback queries** - `2cbf6e7` (feat) 2. **Task 2: Implement suggestion flow for no-match cases** - `56eea26` (feat) 3. **Task 3: Handle suggestion callback and execute action** - `768d758` (feat) ## Files Created/Modified - `n8n-workflow.json` - Extended from 27 to 41 nodes with callback infrastructure: - Route Update Type, IF Callback Authenticated (Task 1) - Find Closest Match, Check Suggestion, Build Suggestion Keyboard, Send Suggestion (Task 2) - Parse Callback Data, Route Callback, Handle Cancel/Expired, Build/Execute/Parse Callback Action, Answer/Delete/Send result (Task 3) ## Decisions Made - Use HTTP Request node for sendMessage with inline_keyboard - native Telegram node has expression bug with dynamic keyboards - Encode action as single character (s=start, t=stop, r=restart, x=cancel) to fit callback_data 64-byte limit - Require minimum score of 2 for suggestions - prevents suggesting unrelated containers - 2-minute timeout enforced via timestamp in callback_data (stateless approach) - Delete suggestion message after any button click for clean chat UI ## Deviations from Plan None - plan executed exactly as written. ## Issues Encountered None ## User Setup Required None - no external service configuration required. ## Next Phase Readiness - Single-container suggestion flow complete - Multiple-match batch confirmation still uses placeholder text (could be enhanced in future) - Ready for Phase 04: Logs & Intelligence - Container update flow (pull + recreate) deferred to later plan --- *Phase: 03-container-actions* *Completed: 2026-01-30*