this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(bot): register webhook with Telegram on startup

Previously, webhook mode only logged the URL but never actually called
setWebhook. This meant the secret_token was never configured, causing
Telegram to send updates without the X-Telegram-Bot-Api-Secret-Token
header, which the app then rejected with 401 Unauthorized.

Now registerWebhook() is called on startup in webhook mode, ensuring
the webhook is properly configured with the secret token.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

alice 09dc4626 e0030ec5

+29 -2
+22
src/bot.ts
··· 411 411 } 412 412 413 413 /** 414 + * Register webhook with Telegram 415 + * 416 + * Called on startup when webhook mode is enabled. 417 + * Ensures the webhook is properly configured with the secret token. 418 + */ 419 + export async function registerWebhook(): Promise<void> { 420 + console.log(`Registering webhook: ${config.TELEGRAM_WEBHOOK_URL}`); 421 + 422 + await bot.telegram.setWebhook(config.TELEGRAM_WEBHOOK_URL, { 423 + secret_token: config.TELEGRAM_WEBHOOK_SECRET_TOKEN, 424 + }); 425 + 426 + // Verify registration 427 + const info = await bot.telegram.getWebhookInfo(); 428 + console.log(`Webhook registered: ${info.url ?? '(no url)'}`); 429 + 430 + if (info.last_error_message !== undefined && info.last_error_message !== '') { 431 + console.warn(`Webhook last error: ${info.last_error_message}`); 432 + } 433 + } 434 + 435 + /** 414 436 * Start polling mode (for development) 415 437 * 416 438 * Only used when TELEGRAM_WEBHOOK_URL is empty.
+7 -2
src/index.ts
··· 12 12 import { config, isWebhookMode } from './config'; 13 13 import { healthCheck, simpleHealthCheck } from './health'; 14 14 import { initializeLetta } from './letta'; 15 - import { handleUpdate, startPolling } from './bot'; 15 + import { handleUpdate, startPolling, registerWebhook } from './bot'; 16 16 import { dispatchTool } from './tools'; 17 17 import type { Update } from 'telegraf/types'; 18 18 ··· 141 141 142 142 // Start bot in appropriate mode 143 143 if (isWebhookMode()) { 144 - console.log(`Webhook mode enabled: ${config.TELEGRAM_WEBHOOK_URL}`); 144 + try { 145 + await registerWebhook(); 146 + } catch (error) { 147 + console.error('Failed to register webhook:', error); 148 + console.error('Bot will not receive messages until webhook is registered.'); 149 + } 145 150 } else { 146 151 console.log('Webhook mode disabled, starting polling for development...'); 147 152 try {