mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
fix: honor nostr default account routing
This commit is contained in:
@@ -85,4 +85,58 @@ describe("nostr outbound cfg threading", () => {
|
||||
|
||||
cleanup.stop();
|
||||
});
|
||||
|
||||
it("uses the configured defaultAccount when accountId is omitted", async () => {
|
||||
const resolveMarkdownTableMode = vi.fn(() => "off");
|
||||
const convertMarkdownTables = vi.fn((text: string) => text);
|
||||
setNostrRuntime({
|
||||
channel: {
|
||||
text: {
|
||||
resolveMarkdownTableMode,
|
||||
convertMarkdownTables,
|
||||
},
|
||||
},
|
||||
reply: {},
|
||||
} as unknown as PluginRuntime);
|
||||
|
||||
const sendDm = vi.fn(async () => {});
|
||||
const bus = {
|
||||
sendDm,
|
||||
close: vi.fn(),
|
||||
getMetrics: vi.fn(() => ({ counters: {} })),
|
||||
publishProfile: vi.fn(),
|
||||
getProfileState: vi.fn(async () => null),
|
||||
};
|
||||
mocks.startNostrBus.mockResolvedValueOnce(bus as any);
|
||||
|
||||
const cleanup = (await nostrPlugin.gateway!.startAccount!(
|
||||
createStartAccountContext({
|
||||
account: buildResolvedNostrAccount({ accountId: "work" }),
|
||||
}),
|
||||
)) as { stop: () => void };
|
||||
|
||||
const cfg = {
|
||||
channels: {
|
||||
nostr: {
|
||||
privateKey: TEST_RESOLVED_PRIVATE_KEY, // pragma: allowlist secret
|
||||
defaultAccount: "work",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await nostrPlugin.outbound!.sendText!({
|
||||
cfg: cfg as any,
|
||||
to: "NPUB123",
|
||||
text: "hello",
|
||||
});
|
||||
|
||||
expect(resolveMarkdownTableMode).toHaveBeenCalledWith({
|
||||
cfg,
|
||||
channel: "nostr",
|
||||
accountId: "work",
|
||||
});
|
||||
expect(sendDm).toHaveBeenCalledWith("normalized-npub123", "hello");
|
||||
|
||||
cleanup.stop();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -406,9 +406,8 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = createChatChanne
|
||||
return entry.trim();
|
||||
}
|
||||
},
|
||||
notify: async ({ id, message }) => {
|
||||
// Get the default account's bus and send approval message
|
||||
const bus = activeBuses.get(DEFAULT_ACCOUNT_ID);
|
||||
notify: async ({ cfg, id, message, accountId }) => {
|
||||
const bus = activeBuses.get(accountId ?? resolveDefaultNostrAccountId(cfg));
|
||||
if (bus) {
|
||||
await bus.sendDm(id, message);
|
||||
}
|
||||
@@ -423,7 +422,7 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = createChatChanne
|
||||
textChunkLimit: 4000,
|
||||
sendText: async ({ cfg, to, text, accountId }) => {
|
||||
const core = getNostrRuntime();
|
||||
const aid = accountId ?? DEFAULT_ACCOUNT_ID;
|
||||
const aid = accountId ?? resolveDefaultNostrAccountId(cfg);
|
||||
const bus = activeBuses.get(aid);
|
||||
if (!bus) {
|
||||
throw new Error(`Nostr bus not running for account ${aid}`);
|
||||
|
||||
Reference in New Issue
Block a user