Skip to content

[Bug]: Heartbeat Telegram delivery ignores config token (env-only) #318

@lekawik

Description

@lekawik

Summary

Heartbeat runs targeting Telegram fail unless TELEGRAM_BOT_TOKEN is set in the gateway environment. The gateway already supports telegram.botToken in clawdbot.json, but the heartbeat send path never passes it through. Gmail hook delivery works because it explicitly resolves the token from config.

Error

Error: TELEGRAM_BOT_TOKEN is required for Telegram sends (Bot API)

Steps to reproduce

  1. Configure Telegram in clawdbot.json:
    • telegram.botToken set
    • agent.heartbeat.target = "telegram"
    • agent.heartbeat.to = "<chat_id>"
  2. Ensure TELEGRAM_BOT_TOKEN is not set in the environment for the gateway service.
  3. Trigger a heartbeat (wait for interval or manual trigger).

Expected

Heartbeat sends the Telegram message using telegram.botToken from config (or tokenFile/env fallback).

Actual

Heartbeat fails with the error above.

Root Cause

runHeartbeatOnce builds deps.sendTelegram = sendMessageTelegram and calls it without a token:

  • src/infra/heartbeat-runner.ts uses deps.sendTelegram(to, chunk, { verbose: false }).
  • src/telegram/send.ts falls back to opts.token ?? process.env.TELEGRAM_BOT_TOKEN and throws when env is missing.

The heartbeat path never calls resolveTelegramToken(cfg).

Contrast (works in hooks/cron)

Cron/hook delivery resolves and passes the token explicitly:

  • src/cron/isolated-agent.ts calls resolveTelegramToken(params.cfg) and passes token into sendMessageTelegram.

Suggested Fix

Resolve and pass the Telegram token in the heartbeat path, e.g.:

  • Use resolveTelegramToken(cfg) in runHeartbeatOnce (or deliverHeartbeatReply) and pass token into sendMessageTelegram.

Notes

This looks similar to issue #76 (cron delivery), but the heartbeat code path is separate and still env-only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions