mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 17:11:46 +00:00
fix: honor default account in plugin commands
This commit is contained in:
@@ -536,4 +536,76 @@ describe("registerPluginCommand", () => {
|
||||
sessionId: "session-123",
|
||||
});
|
||||
});
|
||||
|
||||
it("passes the effective default account to plugin command handlers when accountId is omitted", async () => {
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "line",
|
||||
source: "test",
|
||||
plugin: {
|
||||
...createChannelTestPluginBase({
|
||||
id: "line",
|
||||
label: "LINE",
|
||||
config: {
|
||||
listAccountIds: () => ["default", "work"],
|
||||
defaultAccountId: () => "work",
|
||||
resolveAccount: (_cfg, accountId) => ({ accountId: accountId ?? "work" }),
|
||||
},
|
||||
}),
|
||||
bindings: {
|
||||
resolveCommandConversation: ({
|
||||
originatingTo,
|
||||
commandTo,
|
||||
fallbackTo,
|
||||
}: {
|
||||
originatingTo?: string;
|
||||
commandTo?: string;
|
||||
fallbackTo?: string;
|
||||
}) => {
|
||||
const rawTarget = [originatingTo, commandTo, fallbackTo].find(Boolean)?.trim();
|
||||
if (!rawTarget) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
conversationId: rawTarget.replace(/^line:/i, "").replace(/^user:/i, ""),
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
let receivedCtx:
|
||||
| {
|
||||
accountId?: string;
|
||||
}
|
||||
| undefined;
|
||||
const handler = async (ctx: { accountId?: string }) => {
|
||||
receivedCtx = ctx;
|
||||
return { text: "ok" };
|
||||
};
|
||||
|
||||
const result = await executePluginCommand({
|
||||
command: {
|
||||
name: "accountcheck",
|
||||
description: "Demo command",
|
||||
acceptsArgs: false,
|
||||
handler,
|
||||
pluginId: "demo-plugin",
|
||||
},
|
||||
channel: "line",
|
||||
senderId: "U123",
|
||||
isAuthorizedSender: true,
|
||||
commandBody: "/accountcheck",
|
||||
config: {} as never,
|
||||
from: "line:user:U1234567890abcdef1234567890abcdef",
|
||||
});
|
||||
|
||||
expect(result).toEqual({ text: "ok" });
|
||||
expect(receivedCtx).toMatchObject({
|
||||
accountId: "work",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -191,6 +191,7 @@ export async function executePluginCommand(params: {
|
||||
messageThreadId: params.messageThreadId,
|
||||
threadParentId: params.threadParentId,
|
||||
});
|
||||
const effectiveAccountId = bindingConversation?.accountId ?? params.accountId;
|
||||
|
||||
const ctx: PluginCommandContext = {
|
||||
senderId,
|
||||
@@ -205,7 +206,7 @@ export async function executePluginCommand(params: {
|
||||
config,
|
||||
from: params.from,
|
||||
to: params.to,
|
||||
accountId: params.accountId,
|
||||
accountId: effectiveAccountId,
|
||||
messageThreadId: params.messageThreadId,
|
||||
threadParentId: params.threadParentId,
|
||||
requestConversationBinding: async (bindingParams) => {
|
||||
|
||||
Reference in New Issue
Block a user