refactor(pairing): centralize reply formatting
This commit is contained in:
10
src/pairing/pairing-labels.ts
Normal file
10
src/pairing/pairing-labels.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { PairingProvider } from "./pairing-store.js";
|
||||
|
||||
export const PROVIDER_ID_LABELS: Record<PairingProvider, string> = {
|
||||
telegram: "telegramUserId",
|
||||
discord: "discordUserId",
|
||||
slack: "slackUserId",
|
||||
signal: "signalNumber",
|
||||
imessage: "imessageSenderId",
|
||||
whatsapp: "whatsappSenderId",
|
||||
};
|
||||
44
src/pairing/pairing-messages.test.ts
Normal file
44
src/pairing/pairing-messages.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { buildPairingReply } from "./pairing-messages.js";
|
||||
|
||||
describe("buildPairingReply", () => {
|
||||
const cases = [
|
||||
{
|
||||
provider: "discord",
|
||||
idLine: "Your Discord user id: 1",
|
||||
code: "ABC123",
|
||||
},
|
||||
{
|
||||
provider: "slack",
|
||||
idLine: "Your Slack user id: U1",
|
||||
code: "DEF456",
|
||||
},
|
||||
{
|
||||
provider: "signal",
|
||||
idLine: "Your Signal number: +15550001111",
|
||||
code: "GHI789",
|
||||
},
|
||||
{
|
||||
provider: "imessage",
|
||||
idLine: "Your iMessage sender id: +15550002222",
|
||||
code: "JKL012",
|
||||
},
|
||||
{
|
||||
provider: "whatsapp",
|
||||
idLine: "Your WhatsApp sender id: +15550003333",
|
||||
code: "MNO345",
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const testCase of cases) {
|
||||
it(`formats pairing reply for ${testCase.provider}`, () => {
|
||||
const text = buildPairingReply(testCase);
|
||||
expect(text).toContain(testCase.idLine);
|
||||
expect(text).toContain(`Pairing code: ${testCase.code}`);
|
||||
expect(text).toContain(
|
||||
`clawdbot pairing approve --provider ${testCase.provider} <code>`,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
19
src/pairing/pairing-messages.ts
Normal file
19
src/pairing/pairing-messages.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { PairingProvider } from "./pairing-store.js";
|
||||
|
||||
export function buildPairingReply(params: {
|
||||
provider: PairingProvider;
|
||||
idLine: string;
|
||||
code: string;
|
||||
}): string {
|
||||
const { provider, idLine, code } = params;
|
||||
return [
|
||||
"Clawdbot: access not configured.",
|
||||
"",
|
||||
idLine,
|
||||
"",
|
||||
`Pairing code: ${code}`,
|
||||
"",
|
||||
"Ask the bot owner to approve with:",
|
||||
`clawdbot pairing approve --provider ${provider} <code>`,
|
||||
].join("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user