sipeed/picoclaw · error

failed to start long polling

Error message

failed to start long polling: %w

What it means

Returned by TelegramChannel.Start when bot.UpdatesViaLongPolling fails to begin the 30-second long-poll update stream — network unreachable, API server error, or the context already cancelled. Start cancels its context and returns, so the channel never begins processing updates.

Solutions

  1. Check network egress to api.telegram.org (or the configured base_url) including proxy settings
  2. If a custom BaseURL is set, verify it is a working Telegram Bot API server
  3. Restart the channel after connectivity is restored
  4. Check whether the bot token was revoked (causes API rejection at polling start)
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at pkg/channels/telegram/telegram.go:162 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/096dbc87dbad21f0. Report an issue: GitHub.

Appendix: source

Thrown at pkg/channels/telegram/telegram.go:162

func telegramMediaGroupDelay(telegramCfg *config.TelegramSettings) time.Duration {
	if telegramCfg != nil && telegramCfg.MediaGroupDelayMS > 0 {
		return time.Duration(telegramCfg.MediaGroupDelayMS) * time.Millisecond
	}
	return defaultMediaGroupDelay
}

func (c *TelegramChannel) Start(ctx context.Context) error {
	logger.InfoC("telegram", "Starting Telegram bot (polling mode)...")

	c.ctx, c.cancel = context.WithCancel(ctx)

	updates, err := c.bot.UpdatesViaLongPolling(c.ctx, &telego.GetUpdatesParams{
		Timeout: 30,
	})
	if err != nil {
		c.cancel()
		return fmt.Errorf("failed to start long polling: %w", err)
	}

	bh, err := th.NewBotHandler(c.bot, updates)
	if err != nil {
		c.cancel()
		return fmt.Errorf("failed to create bot handler: %w", err)
	}
	c.bh = bh

	bh.HandleMessage(func(ctx *th.Context, message telego.Message) error {
		return c.handleMessage(ctx, &message)
	}, th.AnyMessage())

	c.SetRunning(true)
	logger.InfoCF("telegram", "Telegram bot connected", map[string]any{
		"username": c.bot.Username(),
	})

View on GitHub (pinned to 49183d7e8d)