refactor(pairing): centralize reply formatting

This commit is contained in:
Peter Steinberger
2026-01-08 23:29:20 +00:00
parent e952f7df96
commit 7ece3717e6
10 changed files with 123 additions and 83 deletions

View File

@@ -53,6 +53,13 @@ export function formatSignalSenderDisplay(sender: SignalSender): string {
return sender.kind === "phone" ? sender.e164 : `uuid:${sender.raw}`;
}
export function formatSignalPairingIdLine(sender: SignalSender): string {
if (sender.kind === "phone") {
return `Your Signal number: ${sender.e164}`;
}
return `Your Signal sender id: ${formatSignalSenderId(sender)}`;
}
export function resolveSignalRecipient(sender: SignalSender): string {
return sender.kind === "phone" ? sender.e164 : sender.raw;
}

View File

@@ -22,11 +22,13 @@ import { spawnSignalDaemon } from "./daemon.js";
import {
formatSignalSenderDisplay,
formatSignalSenderId,
formatSignalPairingIdLine,
isSignalSenderAllowed,
resolveSignalPeerId,
resolveSignalRecipient,
resolveSignalSender,
} from "./identity.js";
import { buildPairingReply } from "../pairing/pairing-messages.js";
import { sendMessageSignal } from "./send.js";
import { runSignalSseLoop } from "./sse-reconnect.js";
@@ -317,11 +319,8 @@ export async function monitorSignalProvider(
const senderRecipient = resolveSignalRecipient(sender);
const senderPeerId = resolveSignalPeerId(sender);
const senderAllowId = formatSignalSenderId(sender);
const senderIdLine =
sender.kind === "phone"
? `Your Signal number: ${sender.e164}`
: `Your Signal sender id: ${senderAllowId}`;
if (!senderRecipient) return;
const senderIdLine = formatSignalPairingIdLine(sender);
const groupId = dataMessage.groupInfo?.groupId ?? undefined;
const groupName = dataMessage.groupInfo?.groupName ?? undefined;
const isGroup = Boolean(groupId);
@@ -352,16 +351,11 @@ export async function monitorSignalProvider(
try {
await sendMessageSignal(
`signal:${senderRecipient}`,
[
"Clawdbot: access not configured.",
"",
senderIdLine,
"",
`Pairing code: ${code}`,
"",
"Ask the bot owner to approve with:",
"clawdbot pairing approve --provider signal <code>",
].join("\n"),
buildPairingReply({
provider: "signal",
idLine: senderIdLine,
code,
}),
{
baseUrl,
account,