Skip to content

Commit f76f06b

Browse files
authored
fix(nostr): return relay event ids in send receipts (#110006)
1 parent 5c4fbc3 commit f76f06b

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎extensions/nostr/src/channel.outbound.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function installOutboundRuntime(convertMarkdownTables = vi.fn((text: string) =>
4949
}
5050

5151
async function startOutboundAccount(accountId?: string) {
52-
const sendDm = vi.fn(async () => {});
52+
const sendDm = vi.fn(async () => "a".repeat(64));
5353
const bus = {
5454
sendDm,
5555
close: vi.fn(),
@@ -140,6 +140,24 @@ describe("nostr outbound cfg threading", () => {
140140
await cleanup.stop();
141141
});
142142

143+
it("returns the relay-confirmed event id in the delivery receipt", async () => {
144+
installOutboundRuntime();
145+
const { cleanup, sendDm } = await startOutboundAccount();
146+
const eventId = "b".repeat(64);
147+
sendDm.mockResolvedValueOnce(eventId);
148+
149+
const result = await nostrOutboundAdapter.sendText({
150+
cfg: createCfg() as OpenClawConfig,
151+
to: "NPUB123",
152+
text: "hello",
153+
accountId: "default",
154+
});
155+
156+
expect(result.messageId).toBe(eventId);
157+
158+
await cleanup.stop();
159+
});
160+
143161
it("backs declared message adapter capabilities with outbound sends", async () => {
144162
installOutboundRuntime();
145163
const { cleanup, sendDm } = await startOutboundAccount();

‎extensions/nostr/src/gateway.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ export const nostrOutboundAdapter: NostrOutboundAdapter = {
323323
});
324324
const message = core.channel.text.convertMarkdownTables(text ?? "", tableMode);
325325
const normalizedTo = normalizePubkey(to);
326-
await bus.sendDm(normalizedTo, message);
326+
const eventId = await bus.sendDm(normalizedTo, message);
327327
return attachChannelToResult("nostr", {
328328
to: normalizedTo,
329-
messageId: `nostr-${Date.now()}`,
329+
messageId: eventId,
330330
});
331331
},
332332
};

‎extensions/nostr/src/nostr-bus.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export interface NostrBusHandle {
144144
/** Get the bot's public key */
145145
publicKey: string;
146146
/** Send a DM to a pubkey */
147-
sendDm: (toPubkey: string, text: string) => Promise<void>;
147+
sendDm: (toPubkey: string, text: string) => Promise<string>;
148148
/** Get current metrics snapshot */
149149
getMetrics: () => MetricsSnapshot;
150150
/** Publish a profile (kind:0) to all relays */
@@ -643,8 +643,8 @@ export async function startNostrBus(options: NostrBusOptions): Promise<NostrBusH
643643
});
644644

645645
// Public sendDm function
646-
const sendDm = async (toPubkey: string, text: string): Promise<void> => {
647-
await sendEncryptedDm(
646+
const sendDm = async (toPubkey: string, text: string): Promise<string> => {
647+
return await sendEncryptedDm(
648648
pool,
649649
sk,
650650
toPubkey,
@@ -744,7 +744,7 @@ async function sendEncryptedDm(
744744
healthTracker: RelayHealthTracker,
745745
onError?: (error: Error, context: string) => void,
746746
replyToEventId?: string,
747-
): Promise<void> {
747+
): Promise<string> {
748748
const ciphertext = encrypt(sk, toPubkey, text);
749749
// NIP-04 uses an e tag to keep a reply attached to its verified inbound event.
750750
const tags = [["p", toPubkey]];
@@ -788,7 +788,7 @@ async function sendEncryptedDm(
788788
cb?.recordSuccess();
789789
healthTracker.recordSuccess(relay, latency);
790790

791-
return; // Success - exit early
791+
return reply.id;
792792
} catch (err) {
793793
lastError = err as Error;
794794
const latency = Date.now() - startTime;

0 commit comments

Comments
 (0)