Merge pull request #2271 from alipgoldberg/setup-channel-back-nav-pr2-telegram
setup: add ← Back option to Telegram channel flow
This commit is contained in:
@@ -454,7 +454,7 @@ async function main(): Promise<void> {
|
|||||||
}
|
}
|
||||||
let result: void | typeof BACK_TO_CHANNEL_SELECTION;
|
let result: void | typeof BACK_TO_CHANNEL_SELECTION;
|
||||||
if (channelChoice === 'telegram') {
|
if (channelChoice === 'telegram') {
|
||||||
await runTelegramChannel(displayName!);
|
result = await runTelegramChannel(displayName!);
|
||||||
} else if (channelChoice === 'discord') {
|
} else if (channelChoice === 'discord') {
|
||||||
result = await runDiscordChannel(displayName!);
|
result = await runDiscordChannel(displayName!);
|
||||||
} else if (channelChoice === 'whatsapp') {
|
} else if (channelChoice === 'whatsapp') {
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ import * as p from '@clack/prompts';
|
|||||||
import k from 'kleur';
|
import k from 'kleur';
|
||||||
|
|
||||||
import * as setupLog from '../logs.js';
|
import * as setupLog from '../logs.js';
|
||||||
|
import { BACK_TO_CHANNEL_SELECTION, type ChannelFlowResult } from '../lib/back-nav.js';
|
||||||
import { confirmThenOpen, formatNoteLink } from '../lib/browser.js';
|
import { confirmThenOpen, formatNoteLink } from '../lib/browser.js';
|
||||||
|
import { brightSelect } from '../lib/bright-select.js';
|
||||||
import { askOperatorRole } from '../lib/role-prompt.js';
|
import { askOperatorRole } from '../lib/role-prompt.js';
|
||||||
import {
|
import {
|
||||||
type Block,
|
type Block,
|
||||||
@@ -38,8 +40,10 @@ import { accentGreen, brandBold, fitToWidth, fmtDuration, note } from '../lib/th
|
|||||||
|
|
||||||
const DEFAULT_AGENT_NAME = 'Nano';
|
const DEFAULT_AGENT_NAME = 'Nano';
|
||||||
|
|
||||||
export async function runTelegramChannel(displayName: string): Promise<void> {
|
export async function runTelegramChannel(displayName: string): Promise<ChannelFlowResult> {
|
||||||
const token = await collectTelegramToken();
|
const tokenOrBack = await collectTelegramToken();
|
||||||
|
if (tokenOrBack === 'back') return BACK_TO_CHANNEL_SELECTION;
|
||||||
|
const token = tokenOrBack;
|
||||||
const botUsername = await validateTelegramToken(token);
|
const botUsername = await validateTelegramToken(token);
|
||||||
|
|
||||||
// Deep-link the user into the bot's chat so they're on the right screen
|
// Deep-link the user into the bot's chat so they're on the right screen
|
||||||
@@ -131,17 +135,24 @@ export async function runTelegramChannel(displayName: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function collectTelegramToken(): Promise<string> {
|
async function collectTelegramToken(): Promise<string | 'back'> {
|
||||||
const existing = readEnvKey('TELEGRAM_BOT_TOKEN');
|
const existing = readEnvKey('TELEGRAM_BOT_TOKEN');
|
||||||
if (existing && /^[0-9]+:[A-Za-z0-9_-]{35,}$/.test(existing)) {
|
if (existing && /^[0-9]+:[A-Za-z0-9_-]{35,}$/.test(existing)) {
|
||||||
const reuse = ensureAnswer(await p.confirm({
|
const choice = ensureAnswer(await brightSelect<'yes' | 'no' | 'back'>({
|
||||||
message: `Found an existing Telegram bot token (${existing.slice(0, 8)}…). Use it?`,
|
message: `Found an existing Telegram bot token (${existing.slice(0, 8)}…). Use it?`,
|
||||||
initialValue: true,
|
options: [
|
||||||
|
{ value: 'yes', label: 'Yes, use the existing token' },
|
||||||
|
{ value: 'no', label: 'No, paste a new one' },
|
||||||
|
{ value: 'back', label: '← Back to channel selection' },
|
||||||
|
],
|
||||||
|
initialValue: 'yes',
|
||||||
}));
|
}));
|
||||||
if (reuse) {
|
if (choice === 'back') return 'back';
|
||||||
|
if (choice === 'yes') {
|
||||||
setupLog.userInput('telegram_token', 'reused-existing');
|
setupLog.userInput('telegram_token', 'reused-existing');
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
// 'no' falls through to the paste flow below
|
||||||
}
|
}
|
||||||
|
|
||||||
note(
|
note(
|
||||||
@@ -159,6 +170,19 @@ async function collectTelegramToken(): Promise<string> {
|
|||||||
'Set up your Telegram bot',
|
'Set up your Telegram bot',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Back-aware gate before the password prompt — `p.password` doesn't
|
||||||
|
// accept extra options, so we offer Back as a separate brightSelect
|
||||||
|
// immediately after the BotFather instructions and before the paste.
|
||||||
|
const proceed = ensureAnswer(await brightSelect<'continue' | 'back'>({
|
||||||
|
message: 'Ready to paste your bot token?',
|
||||||
|
options: [
|
||||||
|
{ value: 'continue', label: 'Yes, paste it on the next prompt' },
|
||||||
|
{ value: 'back', label: '← Back to channel selection' },
|
||||||
|
],
|
||||||
|
initialValue: 'continue',
|
||||||
|
}));
|
||||||
|
if (proceed === 'back') return 'back';
|
||||||
|
|
||||||
const answer = ensureAnswer(
|
const answer = ensureAnswer(
|
||||||
await p.password({
|
await p.password({
|
||||||
message: 'Paste your bot token',
|
message: 'Paste your bot token',
|
||||||
|
|||||||
Reference in New Issue
Block a user