fix(signal): replace  with @uuid/@phone from mentions

Related #1926

Signal mentions were appearing as  (object replacement character)
instead of readable identifiers. This caused Clawdbot to misinterpret
messages and respond inappropriately.

Now parses dataMessage.mentions array and replaces the placeholder
character with @{uuid} or @{phone} from the mention metadata.
This commit is contained in:
Alex Gleason
2026-01-25 18:47:54 -06:00
committed by Vignesh
parent 4d0443391c
commit 051c574047
2 changed files with 26 additions and 1 deletions

View File

@@ -352,7 +352,23 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {
: deps.isSignalReactionMessage(dataMessage?.reaction)
? dataMessage?.reaction
: null;
const messageText = (dataMessage?.message ?? "").trim();
// Replace (object replacement character) with @uuid or @phone from mentions
let messageText = (dataMessage?.message ?? "").trim();
if (messageText && dataMessage?.mentions?.length) {
const mentions = dataMessage.mentions
.filter((m) => (m.uuid || m.number) && m.start != null && m.length != null)
.sort((a, b) => (b.start ?? 0) - (a.start ?? 0)); // Reverse order to avoid index shifting
for (const mention of mentions) {
const start = mention.start!;
const length = mention.length!;
const identifier = mention.uuid || mention.number || "";
const replacement = `@${identifier}`;
messageText = messageText.slice(0, start) + replacement + messageText.slice(start + length);
}
}
const quoteText = dataMessage?.quote?.text?.trim() ?? "";
const hasBodyContent =
Boolean(messageText || quoteText) || Boolean(!reaction && dataMessage?.attachments?.length);

View File

@@ -16,10 +16,19 @@ export type SignalEnvelope = {
reactionMessage?: SignalReactionMessage | null;
};
export type SignalMention = {
name?: string | null;
number?: string | null;
uuid?: string | null;
start?: number | null;
length?: number | null;
};
export type SignalDataMessage = {
timestamp?: number;
message?: string | null;
attachments?: Array<SignalAttachment>;
mentions?: Array<SignalMention> | null;
groupInfo?: {
groupId?: string | null;
groupName?: string | null;