---
name: debug-telegram-bot-callback-buttons
description: Debug and fix Telegram bot when inline keyboard buttons (callback_query) stop responding while text commands still work
---

# Debug Telegram Bot — Inline Buttons Not Working

## When to Use

Telegram bot responds to `/commands` and text messages but inline keyboard buttons (callback queries) produce no response at all — no loading state, no error message, complete silence.

## Root Cause Typically

The webhook's `allowed_updates` list was overwritten (often by another service like n8n, a re-deployment, or a bot library update) and no longer includes `callback_query`. Telegram simply doesn't deliver callback_query updates to the webhook endpoint.

## Debug Steps

### 1. Check Webhook Info via Telegram API

```bash
curl -s "https://api.telegram.org/bot<TOKEN>/getWebhookInfo" | jq .
```

Key fields to inspect:
- `result.url` — should point to your webhook endpoint
- `result.allowed_updates` — **must include `"callback_query"`**
- `result.pending_update_count` — if > 0, endpoint is not reachable
- `result.last_error_date` / `last_error_message` — Telegram-side errors

### 2. Fix by Re-registering Webhook with Full allowed_updates

```bash
curl -s -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your.domain/api/bot/webhook",
    "allowed_updates": ["message", "edited_message", "channel_post", "callback_query", "inline_query", "chosen_inline_result"],
    "max_connections": 40,
    "drop_pending_updates": true
  }'
```

### 3. Verify Fix

```bash
curl -s "https://api.telegram.org/bot<TOKEN>/getWebhookInfo" | jq .result.allowed_updates
```

Should now include `"callback_query"`.

### 4. (If using node-telegram-bot-api) Update Bot Code

In `initBot()`, explicitly pass `allowed_updates` to `setWebHook` so it survives restarts:

```typescript
await bot.setWebHook(fullWebhookUrl, {
  allowed_updates: ["message", "edited_message", "channel_post", "callback_query"],
  // drop_pending_updates: true
});
```

## Prevention

- Always explicitly set `allowed_updates` when calling `setWebHook` in bot startup code
- Add a health check endpoint that reports webhook status
- After deploying changes that touch webhook/proxy/n8n, verify with `getWebhookInfo`

## Pitfalls

- The `node-telegram-bot-api` library's `processUpdate()` is synchronous but handlers are async — unhandled rejections from callback handlers can crash silently
- The webhook endpoint is usually POST-only — a GET request returns 404, don't confuse this with the bot being down
- `pending_update_count: 0` with bad `allowed_updates` means Telegram isn't even sending those updates (good signal it's an `allowed_updates` issue)
