mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:10:45 +00:00
fix(reply): keep native command replies visible
This commit is contained in:
@@ -4335,6 +4335,35 @@ describe("sendPolicy deny — suppress delivery, not processing (#53328)", () =>
|
|||||||
expect(dispatcher.sendFinalReply).not.toHaveBeenCalled();
|
expect(dispatcher.sendFinalReply).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps native command replies visible in group/channel turns", async () => {
|
||||||
|
setNoAbort();
|
||||||
|
const dispatcher = createDispatcher();
|
||||||
|
const replyResolver = vi.fn(async (_ctx: MsgContext, opts?: GetReplyOptions) => {
|
||||||
|
expect(opts?.sourceReplyDeliveryMode).toBe("automatic");
|
||||||
|
expect(opts?.suppressTyping).toBe(false);
|
||||||
|
return { text: "status reply" } satisfies ReplyPayload;
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await dispatchReplyFromConfig({
|
||||||
|
ctx: buildTestCtx({
|
||||||
|
ChatType: "group",
|
||||||
|
CommandSource: "native",
|
||||||
|
CommandAuthorized: true,
|
||||||
|
WasMentioned: true,
|
||||||
|
SessionKey: "test:telegram:group:G1",
|
||||||
|
}),
|
||||||
|
cfg: emptyConfig,
|
||||||
|
dispatcher,
|
||||||
|
replyResolver,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(replyResolver).toHaveBeenCalledTimes(1);
|
||||||
|
expect(result.queuedFinal).toBe(true);
|
||||||
|
expect(dispatcher.sendFinalReply).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ text: "status reply" }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("allows config to keep group/channel source delivery automatic", async () => {
|
it("allows config to keep group/channel source delivery automatic", async () => {
|
||||||
setNoAbort();
|
setNoAbort();
|
||||||
const dispatcher = createDispatcher();
|
const dispatcher = createDispatcher();
|
||||||
|
|||||||
@@ -42,6 +42,15 @@ describe("resolveSourceReplyDeliveryMode", () => {
|
|||||||
}),
|
}),
|
||||||
).toBe("automatic");
|
).toBe("automatic");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("treats native commands as explicit replies in groups", () => {
|
||||||
|
expect(
|
||||||
|
resolveSourceReplyDeliveryMode({
|
||||||
|
cfg: emptyConfig,
|
||||||
|
ctx: { ChatType: "group", CommandSource: "native" },
|
||||||
|
}),
|
||||||
|
).toBe("automatic");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveSourceReplyVisibilityPolicy", () => {
|
describe("resolveSourceReplyVisibilityPolicy", () => {
|
||||||
@@ -83,6 +92,22 @@ describe("resolveSourceReplyVisibilityPolicy", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps native command replies visible in groups", () => {
|
||||||
|
expect(
|
||||||
|
resolveSourceReplyVisibilityPolicy({
|
||||||
|
cfg: emptyConfig,
|
||||||
|
ctx: { ChatType: "group", CommandSource: "native" },
|
||||||
|
sendPolicy: "allow",
|
||||||
|
}),
|
||||||
|
).toMatchObject({
|
||||||
|
sourceReplyDeliveryMode: "automatic",
|
||||||
|
suppressAutomaticSourceDelivery: false,
|
||||||
|
suppressDelivery: false,
|
||||||
|
suppressHookReplyLifecycle: false,
|
||||||
|
suppressTyping: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps configured automatic group delivery visible", () => {
|
it("keeps configured automatic group delivery visible", () => {
|
||||||
expect(
|
expect(
|
||||||
resolveSourceReplyVisibilityPolicy({
|
resolveSourceReplyVisibilityPolicy({
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { SourceReplyDeliveryMode } from "../get-reply-options.types.js";
|
|||||||
|
|
||||||
export type SourceReplyDeliveryModeContext = {
|
export type SourceReplyDeliveryModeContext = {
|
||||||
ChatType?: string;
|
ChatType?: string;
|
||||||
|
CommandSource?: "text" | "native";
|
||||||
};
|
};
|
||||||
|
|
||||||
export function resolveSourceReplyDeliveryMode(params: {
|
export function resolveSourceReplyDeliveryMode(params: {
|
||||||
@@ -15,6 +16,9 @@ export function resolveSourceReplyDeliveryMode(params: {
|
|||||||
if (params.requested) {
|
if (params.requested) {
|
||||||
return params.requested;
|
return params.requested;
|
||||||
}
|
}
|
||||||
|
if (params.ctx.CommandSource === "native") {
|
||||||
|
return "automatic";
|
||||||
|
}
|
||||||
const chatType = normalizeChatType(params.ctx.ChatType);
|
const chatType = normalizeChatType(params.ctx.ChatType);
|
||||||
if (chatType === "group" || chatType === "channel") {
|
if (chatType === "group" || chatType === "channel") {
|
||||||
return params.cfg.messages?.groupChat?.visibleReplies === "automatic"
|
return params.cfg.messages?.groupChat?.visibleReplies === "automatic"
|
||||||
|
|||||||
Reference in New Issue
Block a user