fix: use openclaw onboard for channel setup (#2598)

* fix: set telegram groupPolicy to open during channel setup

OpenClaw defaults groupPolicy to "allowlist" with an empty groupAllowFrom,
which silently drops all group messages. Set it to "open" after adding the
Telegram channel so group messages work out of the box.

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

* fix: use OpenClaw config file for Telegram setup instead of broken CLI commands

Telegram is a built-in channel in OpenClaw, not a plugin. The previous
approach used `openclaw plugins enable telegram` (caused OOM on 2GB) and
`openclaw channels add --channel telegram` (command doesn't exist).

Now writes Telegram config (botToken, enabled, groupPolicy) directly into
the atomic JSON config file during setup. Also sets groupPolicy to "open"
so group messages work out of the box instead of being silently dropped.

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

* fix: use openclaw onboard for channel setup instead of manual config

OpenClaw has a built-in `openclaw onboard` command that interactively
guides users through Telegram/WhatsApp channel setup. Use that instead
of manually prompting for tokens and writing config ourselves.

- Remove custom Telegram token prompt from agent-setup.ts
- Remove broken `openclaw channels add` and `openclaw plugins enable`
- Run `openclaw onboard` after gateway starts for channel setup
- Base config (API key, gateway, model) still written atomically

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ahmed Abushagur 2026-03-13 15:45:16 -07:00 committed by GitHub
parent 0b5c702b71
commit b3f221f5bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 79 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.17.12",
"version": "0.17.14",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -325,28 +325,29 @@ async function setupOpenclawConfig(
}
const gatewayToken = token ?? crypto.randomUUID().replace(/-/g, "");
const escapedKey = jsonEscape(apiKey);
const escapedToken = jsonEscape(gatewayToken);
const escapedModel = jsonEscape(modelId);
const config = `{
"env": {
"OPENROUTER_API_KEY": ${escapedKey}
},
"gateway": {
"mode": "local",
"auth": {
"token": ${escapedToken}
}
},
"agents": {
"defaults": {
"model": {
"primary": ${escapedModel}
}
}
}
}`;
// Build config object for atomic JSON write — base config only (API key, gateway, model).
// Channel setup (Telegram, WhatsApp) is handled by `openclaw onboard` in orchestrate.ts.
const configObj: Record<string, unknown> = {
env: {
OPENROUTER_API_KEY: apiKey,
},
gateway: {
mode: "local",
auth: {
token: gatewayToken,
},
},
agents: {
defaults: {
model: {
primary: modelId,
},
},
},
};
const config = JSON.stringify(configObj, null, 2);
await uploadConfigFile(runner, config, "$HOME/.openclaw/openclaw.json");
// Configure browser via CLI (openclaw config set) — the supported way to set
@ -364,22 +365,6 @@ async function setupOpenclawConfig(
logWarn("Browser config setup failed (non-fatal)");
}
// Enable channel plugins before configuring them — plugins are disabled by
// default in OpenClaw and the gateway hangs if a token is set for a disabled plugin.
const pluginsToEnable: string[] = [];
if (enabledSteps?.has("telegram")) {
pluginsToEnable.push("telegram");
}
if (enabledSteps?.has("whatsapp")) {
pluginsToEnable.push("whatsapp");
}
if (pluginsToEnable.length > 0) {
const enableCmds = pluginsToEnable.map((p) => `openclaw plugins enable ${shellQuote(p)}`).join("; ");
await asyncTryCatchIf(isOperationalError, () =>
runner.runServer(`export PATH=$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH; ${enableCmds}`),
);
}
// Re-assert gateway auth token after browser config set calls — each `openclaw config set`
// does a read-modify-write on the config file and may drop fields written by uploadConfigFile.
// Re-setting the token here ensures it survives those cycles and the gateway starts authenticated.
@ -393,8 +378,7 @@ async function setupOpenclawConfig(
logWarn("Gateway token re-assertion failed (non-fatal) — dashboard may show Unauthorized");
}
// Channel configuration (Telegram token, WhatsApp QR) happens in orchestrate.ts
// AFTER the gateway starts — openclaw channels commands need a running gateway.
// Channel setup (Telegram, WhatsApp) is handled by `openclaw onboard` in orchestrate.ts.
// Write USER.md bootstrap file — guides users to the web dashboard for
// visual tasks like WhatsApp QR code scanning that don't work in the TUI.

View file

@ -25,8 +25,6 @@ import {
logWarn,
openBrowser,
prepareStdinForHandoff,
prompt,
shellQuote,
validateModelId,
withRetry,
} from "./ui";
@ -293,44 +291,14 @@ export async function runOrchestration(
}
}
// 11c. Channel setup (runs after gateway is up so openclaw commands work)
const ocPath = "export PATH=$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH";
if (enabledSteps?.has("telegram")) {
logStep("Setting up Telegram...");
const envToken = process.env.TELEGRAM_BOT_TOKEN;
if (!envToken) {
logInfo("To get a bot token:");
logInfo(" 1. Open Telegram and search for @BotFather");
logInfo(" 2. Send /newbot and follow the prompts");
logInfo(" 3. Copy the token (looks like 123456:ABC-DEF...)");
logInfo(" Press Enter to skip if you don't have one yet.");
}
const trimmedToken = envToken?.trim() || (await prompt("Telegram bot token: ")).trim();
if (trimmedToken) {
const escaped = shellQuote(trimmedToken);
const result = await asyncTryCatchIf(isOperationalError, () =>
cloud.runner.runServer(
`source ~/.spawnrc 2>/dev/null; ${ocPath}; openclaw channels add --channel telegram --token ${escaped}`,
),
);
if (result.ok) {
logInfo("Telegram channel added");
} else {
logWarn("Telegram setup failed — configure it via the web dashboard after launch");
}
} else {
logInfo("No token entered — set up Telegram via the web dashboard after launch");
}
}
if (enabledSteps?.has("whatsapp")) {
logStep("Linking WhatsApp — scan the QR code with your phone...");
logInfo("Open WhatsApp > Settings > Linked Devices > Link a Device");
process.stderr.write("\n");
const whatsappCmd = `source ~/.spawnrc 2>/dev/null; ${ocPath}; openclaw channels login --channel whatsapp`;
// 11c. Channel setup — delegate to OpenClaw's built-in onboard wizard.
// `openclaw onboard` interactively guides the user through Telegram, WhatsApp,
// and other channel configuration. Runs after the gateway starts.
if (enabledSteps?.has("telegram") || enabledSteps?.has("whatsapp")) {
const ocPath = "export PATH=$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH";
logStep("Running OpenClaw channel setup...");
prepareStdinForHandoff();
await cloud.interactiveSession(whatsappCmd);
await cloud.interactiveSession(`source ~/.spawnrc 2>/dev/null; ${ocPath}; openclaw onboard`);
}
// 11d. Agent-specific pre-launch tip (e.g. channel setup ordering hint)