mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-29 10:02:04 +00:00
fix: honor twitch default send account
This commit is contained in:
@@ -258,5 +258,52 @@ describe("send", () => {
|
||||
"default",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses the configured default account when accountId is omitted", async () => {
|
||||
const secondaryAccount = {
|
||||
...mockAccount,
|
||||
username: "secondary-user",
|
||||
channel: "secondary-channel",
|
||||
};
|
||||
vi.mocked(resolveTwitchAccountContext).mockImplementation((_cfg, accountId) => ({
|
||||
accountId: accountId?.trim() || "secondary",
|
||||
account: secondaryAccount,
|
||||
tokenResolution: { source: "config", token: secondaryAccount.accessToken ?? "" },
|
||||
configured: true,
|
||||
availableAccountIds: ["default", "secondary"],
|
||||
}));
|
||||
const mockSend = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
messageId: "twitch-msg-secondary",
|
||||
});
|
||||
vi.mocked(getClientManager).mockReturnValue({
|
||||
sendMessage: mockSend,
|
||||
} as unknown as ReturnType<typeof getClientManager>);
|
||||
|
||||
const result = await sendMessageTwitchInternal(
|
||||
"",
|
||||
"Hello!",
|
||||
{
|
||||
channels: {
|
||||
twitch: {
|
||||
defaultAccount: "secondary",
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
undefined,
|
||||
false,
|
||||
mockLogger as unknown as Console,
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(getClientManager).toHaveBeenCalledWith("secondary");
|
||||
expect(mockSend).toHaveBeenCalledWith(
|
||||
secondaryAccount,
|
||||
"secondary-channel",
|
||||
"Hello!",
|
||||
expect.any(Object),
|
||||
"secondary",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import { getClientManager as getRegistryClientManager } from "./client-manager-registry.js";
|
||||
import { DEFAULT_ACCOUNT_ID, resolveTwitchAccountContext } from "./config.js";
|
||||
import { resolveTwitchAccountContext } from "./config.js";
|
||||
import { stripMarkdownForTwitch } from "./utils/markdown.js";
|
||||
import { generateMessageId, normalizeTwitchChannel } from "./utils/twitch.js";
|
||||
|
||||
@@ -51,16 +51,21 @@ export async function sendMessageTwitchInternal(
|
||||
channel: string,
|
||||
text: string,
|
||||
cfg: OpenClawConfig,
|
||||
accountId: string = DEFAULT_ACCOUNT_ID,
|
||||
accountId?: string,
|
||||
stripMarkdown: boolean = true,
|
||||
logger: Console = console,
|
||||
): Promise<SendMessageResult> {
|
||||
const { account, configured, availableAccountIds } = resolveTwitchAccountContext(cfg, accountId);
|
||||
const {
|
||||
account,
|
||||
configured,
|
||||
availableAccountIds,
|
||||
accountId: resolvedAccountId,
|
||||
} = resolveTwitchAccountContext(cfg, accountId);
|
||||
if (!account) {
|
||||
return {
|
||||
ok: false,
|
||||
messageId: generateMessageId(),
|
||||
error: `Account not found: ${accountId}. Available accounts: ${availableAccountIds.join(", ") || "none"}`,
|
||||
error: `Account not found: ${accountId ?? "(default)"}. Available accounts: ${availableAccountIds.join(", ") || "none"}`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,7 +74,7 @@ export async function sendMessageTwitchInternal(
|
||||
ok: false,
|
||||
messageId: generateMessageId(),
|
||||
error:
|
||||
`Account ${accountId} is not properly configured. ` +
|
||||
`Account ${resolvedAccountId} is not properly configured. ` +
|
||||
"Required: username, clientId, and token (config or env for default account).",
|
||||
};
|
||||
}
|
||||
@@ -91,12 +96,12 @@ export async function sendMessageTwitchInternal(
|
||||
};
|
||||
}
|
||||
|
||||
const clientManager = getRegistryClientManager(accountId);
|
||||
const clientManager = getRegistryClientManager(resolvedAccountId);
|
||||
if (!clientManager) {
|
||||
return {
|
||||
ok: false,
|
||||
messageId: generateMessageId(),
|
||||
error: `Client manager not found for account: ${accountId}. Please start the Twitch gateway first.`,
|
||||
error: `Client manager not found for account: ${resolvedAccountId}. Please start the Twitch gateway first.`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,7 +111,7 @@ export async function sendMessageTwitchInternal(
|
||||
normalizeTwitchChannel(normalizedChannel),
|
||||
cleanedText,
|
||||
cfg,
|
||||
accountId,
|
||||
resolvedAccountId,
|
||||
);
|
||||
|
||||
if (!result.ok) {
|
||||
|
||||
Reference in New Issue
Block a user