mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:50:43 +00:00
fix(matrix): align mention-stripped command body
This commit is contained in:
@@ -514,14 +514,15 @@ describe("matrix monitor handler pairing account scope", () => {
|
||||
|
||||
it("strips the Matrix self user id before room slash command detection", async () => {
|
||||
const hasControlCommand = vi.fn((text?: string) => text === "/new");
|
||||
const { handler, recordInboundSession } = createMatrixHandlerTestHarness({
|
||||
cfg: { commands: { useAccessGroups: false } },
|
||||
isDirectMessage: false,
|
||||
mentionRegexes: [],
|
||||
shouldHandleTextCommands: () => true,
|
||||
hasControlCommand,
|
||||
getMemberDisplayName: async () => "sender",
|
||||
});
|
||||
const { handler, finalizeInboundContext, recordInboundSession } =
|
||||
createMatrixHandlerTestHarness({
|
||||
cfg: { commands: { useAccessGroups: false } },
|
||||
isDirectMessage: false,
|
||||
mentionRegexes: [],
|
||||
shouldHandleTextCommands: () => true,
|
||||
hasControlCommand,
|
||||
getMemberDisplayName: async () => "sender",
|
||||
});
|
||||
|
||||
await handler(
|
||||
"!room:example.org",
|
||||
@@ -532,6 +533,14 @@ describe("matrix monitor handler pairing account scope", () => {
|
||||
);
|
||||
|
||||
expect(hasControlCommand).toHaveBeenCalledWith("/new", expect.anything());
|
||||
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
RawBody: "@bot:example.org /new",
|
||||
CommandBody: "/new",
|
||||
BodyForAgent: "@bot:example.org /new",
|
||||
BodyForCommands: "/new",
|
||||
}),
|
||||
);
|
||||
expect(recordInboundSession).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -935,8 +935,8 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
surface: "matrix",
|
||||
});
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
// Keep this scoped to command precheck so mention/history/body semantics
|
||||
// continue to see the original Matrix message.
|
||||
// Keep mention stripping on the command-only path so history and agent
|
||||
// prompt text continue to see the original Matrix message.
|
||||
const commandCheckText = stripMatrixMentionPrefix({
|
||||
text: mentionPrecheckText,
|
||||
userId: selfUserId,
|
||||
@@ -1076,6 +1076,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
await commitInboundEventIfClaimed();
|
||||
return undefined;
|
||||
}
|
||||
const commandBodyText = hasControlCommandInMessage ? commandCheckText : bodyText;
|
||||
const senderName = await getSenderName();
|
||||
if (_configuredBinding) {
|
||||
const { ensureConfiguredAcpBindingReady } = await loadAcpBindingRuntime();
|
||||
@@ -1123,6 +1124,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
inboundHistory,
|
||||
senderName,
|
||||
bodyText,
|
||||
commandBodyText,
|
||||
media,
|
||||
locationPayload,
|
||||
messageId: _messageId,
|
||||
@@ -1176,6 +1178,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
inboundHistory,
|
||||
senderName,
|
||||
bodyText,
|
||||
commandBodyText,
|
||||
media,
|
||||
locationPayload,
|
||||
messageId: _messageId,
|
||||
@@ -1294,7 +1297,9 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
||||
Body: body,
|
||||
RawBody: bodyText,
|
||||
CommandBody: bodyText,
|
||||
CommandBody: commandBodyText,
|
||||
BodyForAgent: bodyText,
|
||||
BodyForCommands: commandBodyText,
|
||||
InboundHistory: inboundHistory && inboundHistory.length > 0 ? inboundHistory : undefined,
|
||||
From: isDirectMessage ? `matrix:${senderId}` : `matrix:channel:${roomId}`,
|
||||
To: `room:${roomId}`,
|
||||
|
||||
Reference in New Issue
Block a user