feat(telegram): show user id in pairing
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
- Providers/Doctor: warn when Telegram config expects unmentioned group messages but Bot API privacy mode is likely enabled; surface WhatsApp login/disconnect hints.
|
- Providers/Doctor: warn when Telegram config expects unmentioned group messages but Bot API privacy mode is likely enabled; surface WhatsApp login/disconnect hints.
|
||||||
- Providers/Doctor: add last inbound/outbound activity timestamps in `providers status` and extend `--probe` with Discord channel permission + Telegram group membership audits.
|
- Providers/Doctor: add last inbound/outbound activity timestamps in `providers status` and extend `--probe` with Discord channel permission + Telegram group membership audits.
|
||||||
- Docs: add provider troubleshooting index (`/providers/troubleshooting`) and link it from the main troubleshooting guide.
|
- Docs: add provider troubleshooting index (`/providers/troubleshooting`) and link it from the main troubleshooting guide.
|
||||||
|
- Telegram: include the user id in DM pairing messages and label it clearly in `clawdbot pairing list --provider telegram`.
|
||||||
- Apps: refresh iOS/Android/macOS app icons for Clawdbot branding. (#521) — thanks @fishfisher
|
- Apps: refresh iOS/Android/macOS app icons for Clawdbot branding. (#521) — thanks @fishfisher
|
||||||
- Docs: expand parameter descriptions for agent/wake hooks. (#532) — thanks @mcinteerj
|
- Docs: expand parameter descriptions for agent/wake hooks. (#532) — thanks @mcinteerj
|
||||||
- Docs: add community showcase entries from Discord. (#476) — thanks @gupsammy
|
- Docs: add community showcase entries from Discord. (#476) — thanks @gupsammy
|
||||||
|
|||||||
64
src/cli/pairing-cli.test.ts
Normal file
64
src/cli/pairing-cli.test.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { Command } from "commander";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
const listProviderPairingRequests = vi.fn();
|
||||||
|
|
||||||
|
vi.mock("../pairing/pairing-store.js", () => ({
|
||||||
|
listProviderPairingRequests,
|
||||||
|
approveProviderPairingCode: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../telegram/send.js", () => ({
|
||||||
|
sendMessageTelegram: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../discord/send.js", () => ({
|
||||||
|
sendMessageDiscord: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../slack/send.js", () => ({
|
||||||
|
sendMessageSlack: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../signal/send.js", () => ({
|
||||||
|
sendMessageSignal: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../imessage/send.js", () => ({
|
||||||
|
sendMessageIMessage: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../config/config.js", () => ({
|
||||||
|
loadConfig: vi.fn().mockReturnValue({}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../telegram/token.js", () => ({
|
||||||
|
resolveTelegramToken: vi.fn().mockReturnValue({ token: "t" }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("pairing cli", () => {
|
||||||
|
it("labels Telegram ids as telegramUserId", async () => {
|
||||||
|
const { registerPairingCli } = await import("./pairing-cli.js");
|
||||||
|
listProviderPairingRequests.mockResolvedValueOnce([
|
||||||
|
{
|
||||||
|
id: "123",
|
||||||
|
code: "ABC123",
|
||||||
|
createdAt: "2026-01-08T00:00:00Z",
|
||||||
|
lastSeenAt: "2026-01-08T00:00:00Z",
|
||||||
|
meta: { username: "peter" },
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||||
|
const program = new Command();
|
||||||
|
program.name("test");
|
||||||
|
registerPairingCli(program);
|
||||||
|
await program.parseAsync(["pairing", "list", "--provider", "telegram"], {
|
||||||
|
from: "user",
|
||||||
|
});
|
||||||
|
expect(log).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining("telegramUserId=123"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
@@ -93,8 +93,9 @@ export function registerPairingCli(program: Command) {
|
|||||||
}
|
}
|
||||||
for (const r of requests) {
|
for (const r of requests) {
|
||||||
const meta = r.meta ? JSON.stringify(r.meta) : "";
|
const meta = r.meta ? JSON.stringify(r.meta) : "";
|
||||||
|
const idLabel = provider === "telegram" ? "telegramUserId" : "id";
|
||||||
console.log(
|
console.log(
|
||||||
`${r.code} id=${r.id}${meta ? ` meta=${meta}` : ""} ${r.createdAt}`,
|
`${r.code} ${idLabel}=${r.id}${meta ? ` meta=${meta}` : ""} ${r.createdAt}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -284,6 +284,9 @@ describe("createTelegramBot", () => {
|
|||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
expect(sendMessageSpy).toHaveBeenCalledTimes(1);
|
expect(sendMessageSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(sendMessageSpy.mock.calls[0]?.[0]).toBe(1234);
|
expect(sendMessageSpy.mock.calls[0]?.[0]).toBe(1234);
|
||||||
|
expect(String(sendMessageSpy.mock.calls[0]?.[1])).toContain(
|
||||||
|
"Your Telegram user id: 999",
|
||||||
|
);
|
||||||
expect(String(sendMessageSpy.mock.calls[0]?.[1])).toContain(
|
expect(String(sendMessageSpy.mock.calls[0]?.[1])).toContain(
|
||||||
"Pairing code:",
|
"Pairing code:",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -390,8 +390,10 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
first_name?: string;
|
first_name?: string;
|
||||||
last_name?: string;
|
last_name?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
|
id?: number;
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
|
const telegramUserId = from?.id ? String(from.id) : candidate;
|
||||||
const { code, created } = await upsertTelegramPairingRequest({
|
const { code, created } = await upsertTelegramPairingRequest({
|
||||||
chatId: candidate,
|
chatId: candidate,
|
||||||
username: from?.username,
|
username: from?.username,
|
||||||
@@ -413,6 +415,8 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
[
|
[
|
||||||
"Clawdbot: access not configured.",
|
"Clawdbot: access not configured.",
|
||||||
"",
|
"",
|
||||||
|
`Your Telegram user id: ${telegramUserId}`,
|
||||||
|
"",
|
||||||
`Pairing code: ${code}`,
|
`Pairing code: ${code}`,
|
||||||
"",
|
"",
|
||||||
"Ask the bot owner to approve with:",
|
"Ask the bot owner to approve with:",
|
||||||
|
|||||||
Reference in New Issue
Block a user