11// Discord plugin module implements runtime.messaging.send behavior.
22import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime" ;
3- import { createReusableDiscordReplyReference } from "../reply-reference.js" ;
3+ import {
4+ createReusableDiscordReplyReference ,
5+ resolveDiscordReplyReference ,
6+ } from "../reply-reference.js" ;
47import {
58 assertMediaNotDataUrl ,
69 jsonResult ,
@@ -26,6 +29,19 @@ function hasDiscordComponentObjectKeys(value: unknown): value is Record<string,
2629 ) ;
2730}
2831
32+ function resolveActionReplyReference ( ctx : DiscordMessagingActionContext , replyToId ?: string ) {
33+ const reply = ctx . options ?. reply ;
34+ // Host-resolved facts own physical-send scope. Raw-only plugin callers keep
35+ // their longstanding reusable reply semantics when no host fact exists.
36+ return reply
37+ ? resolveDiscordReplyReference ( {
38+ replyToId : reply . replyToId ,
39+ replyToIdSource : reply . source ,
40+ replyToMode : reply . source === "implicit" ? reply . mode : undefined ,
41+ } )
42+ : createReusableDiscordReplyReference ( replyToId ) ;
43+ }
44+
2945function readDiscordThreadArchiveTimestamp ( thread : unknown ) : string | undefined {
3046 if ( ! thread || typeof thread !== "object" || Array . isArray ( thread ) ) {
3147 return undefined ;
@@ -252,7 +268,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
252268 {
253269 ...ctx . withOpts ( ) ,
254270 silent,
255- reply : createReusableDiscordReplyReference ( replyTo ) ,
271+ reply : resolveActionReplyReference ( ctx , replyTo ) ,
256272 sessionKey : sessionKey ?? undefined ,
257273 agentId : agentId ?? undefined ,
258274 mediaUrl : mediaUrl ?? undefined ,
@@ -286,7 +302,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
286302 assertMediaNotDataUrl ( mediaUrl ) ;
287303 const result = await discordMessagingActionRuntime . sendVoiceMessageDiscord ( to , mediaUrl , {
288304 ...ctx . withOpts ( ) ,
289- reply : createReusableDiscordReplyReference ( replyTo ) ,
305+ reply : resolveActionReplyReference ( ctx , replyTo ) ,
290306 silent,
291307 mediaAccess : ctx . options ?. mediaAccess ,
292308 mediaLocalRoots : ctx . options ?. mediaLocalRoots ,
@@ -308,7 +324,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
308324 filename : filename ?? undefined ,
309325 mediaLocalRoots : ctx . options ?. mediaLocalRoots ,
310326 mediaReadFile : ctx . options ?. mediaReadFile ,
311- reply : createReusableDiscordReplyReference ( replyTo ) ,
327+ reply : resolveActionReplyReference ( ctx , replyTo ) ,
312328 components,
313329 embeds,
314330 silent,
@@ -424,7 +440,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
424440 mediaAccess : ctx . options ?. mediaAccess ,
425441 mediaLocalRoots : ctx . options ?. mediaLocalRoots ,
426442 mediaReadFile : ctx . options ?. mediaReadFile ,
427- reply : createReusableDiscordReplyReference ( replyTo ) ,
443+ reply : resolveActionReplyReference ( ctx , replyTo ) ,
428444 } ,
429445 ) ;
430446 return jsonResult ( { ok : true , result } ) ;
0 commit comments