Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.18.2: setup pairing start hotfix

- `[Setup]` `/telegram-setup` now updates the live in-memory config immediately after persisting the validated bot token and before starting polling. Impact: first-time setup no longer shows `Send /start...` followed by `Telegram bot is not configured`, and `/start` can be received without restarting Pi.

## 0.18.1: Windows setup transport hotfix

- `[Setup]` `/telegram-setup` token validation now uses the same fallback-aware Telegram transport as normal API calls. Impact: Windows/QEMU hosts that fail native `fetch` during bot-token validation can retry through IPv4 fallback instead of failing before config is saved.
Expand Down
8 changes: 5 additions & 3 deletions lib/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ export function createTelegramSetupPromptRuntime<
return async (ctx: TContext): Promise<void> => {
if (!ctx.hasUI || !deps.setupGuard.start()) return;
try {
const nextConfig = await runTelegramSetup({
await runTelegramSetup({
hasUI: ctx.hasUI,
env: deps.env ?? process.env,
config: deps.getConfig(),
promptInput: (label, value) => ctx.ui.input(label, value),
promptEditor: (label, value) => ctx.ui.editor(label, value),
getMe: deps.getMe,
persistConfig: deps.persistConfig,
persistConfig: async (config) => {
await deps.persistConfig(config);
deps.setConfig(config);
},
notify: (message, level) => ctx.ui.notify(message, level),
startPolling: () => deps.startPolling(ctx),
updateStatus: () => deps.updateStatus(ctx),
});
if (nextConfig) deps.setConfig(nextConfig);
} catch (error) {
deps.recordRuntimeEvent?.("setup", error);
throw error;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llblab/pi-telegram",
"version": "0.18.1",
"version": "0.18.2",
"private": false,
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,11 @@ test("Setup prompt runtime guards concurrent setup and stores successful config"
"editor:env-token",
"getMe:new-token",
"persist:new-token",
"set:demo_bot",
"notify:info:Telegram bot connected: @demo_bot",
"notify:info:Send /start to your bot in Telegram to pair this extension with your account.",
"poll",
"status",
"set:demo_bot",
"finish",
"start",
]);
Expand Down
42 changes: 42 additions & 0 deletions tests/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,48 @@ test("Setup runner reports invalid tokens without persisting or starting polling
assert.deepEqual(calls, ["error:Unauthorized"]);
});

test("Setup prompt runtime stores config before starting polling", async () => {
const calls: string[] = [];
let currentToken: string | undefined;
const runtime = createTelegramSetupPromptRuntime({
env: {},
getConfig: () => ({}),
setConfig: (config) => {
currentToken = config.botToken;
calls.push(`set:${config.botToken}`);
},
setupGuard: {
start: () => true,
finish: () => calls.push("finish"),
},
getMe: async () => ({ ok: true, result: { id: 7, username: "demo_bot" } }),
persistConfig: async (config) => {
calls.push(`persist:${config.botToken}`);
},
startPolling: () => calls.push(`start:${currentToken ?? "missing"}`),
updateStatus: () => calls.push("status"),
});

await runtime({
hasUI: true,
ui: {
input: async () => "token",
editor: async () => "token",
notify: (message) => calls.push(`notify:${message}`),
},
});

assert.deepEqual(calls, [
"persist:token",
"set:token",
"notify:Telegram bot connected: @demo_bot",
"notify:Send /start to your bot in Telegram to pair this extension with your account.",
"start:token",
"status",
"finish",
]);
});

test("Setup prompt runtime reports token check errors and always finishes", async () => {
const calls: string[] = [];
let locked = false;
Expand Down
Loading