ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

channel connect telegram always fails with 'Invalid bot token' in bundled CLI

Open codeaholicguy opened this issue 1 month ago • 0 comments

Summary

ai-devkit channel connect telegram always reports Invalid bot token. Please check and try again. in the published CLI bundle, even when a valid bot token is entered.

Root cause

In packages/cli/src/commands/channel.ts, token validation used a dynamic import:

const { Telegraf } = await import("telegraf");
const bot = new Telegraf(botToken.trim());
const me = await bot.telegram.getMe();

In the published bundle (dist/bundle/cli.js, built by esbuild via scripts/bundle-cli.mjs), that dynamic import is compiled into a lazy chunk (lib-*.js) whose module namespace only has a default export — no named Telegraf export:

import { require_lib } from "./chunk-XXXX.js";
export default require_lib();

So Telegraf is undefined, new Telegraf(token) throws TypeError: Telegraf is not a constructor, and the catch reports "Invalid bot token" for any failure — the token is never sent to Telegram. This only reproduces in the bundled release; in dev mode (ts-node), the real telegraf package resolves with proper CJS named-export interop, which is why it wasn't caught by tests.

Verified against the installed 0.70.0 package: import() of the generated chunk returns { default: ... } with no Telegraf.

Expected

A valid bot token connects successfully and reports Connected to bot @<username>.

Actual

Invalid bot token. Please check and try again. regardless of token validity.

Proposed fix

Add validateTelegramBotToken to @ai-devkit/channel-connector (mirroring validateSlackCredentials), using the static import { Telegraf } from "telegraf" which bundles correctly, and call it from the connect command. Also log the underlying (token-redacted) error under --debug, matching the Slack path.

codeaholicguy avatar Oct 12 '26 13:10 codeaholicguy