mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 23:17:27 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user