@@ -23,6 +23,14 @@ type DiscordOutboundPayloadContext = Parameters<
2323> [ 0 ] ;
2424type DiscordPayloadSendContext = Awaited < ReturnType < typeof createDiscordPayloadSendContext > > ;
2525
26+ function resolveDiscordDeliveryProgress ( ctx : DiscordOutboundPayloadContext ) {
27+ return ctx . onDeliveryResult
28+ ? async ( result : Awaited < ReturnType < DiscordPayloadSendContext [ "send" ] > > ) => {
29+ await ctx . onDeliveryResult ?.( attachChannelToResult ( "discord" , result ) ) ;
30+ }
31+ : undefined ;
32+ }
33+
2634function createDiscordUnknownPayloadResult ( target : string ) {
2735 return {
2836 messageId : "" ,
@@ -94,13 +102,15 @@ export async function sendDiscordOutboundPayload(params: {
94102 replyTo : voiceReplyTo ,
95103 } ) ,
96104 ) ;
105+ await ctx . onDeliveryResult ?.( attachChannelToResult ( "discord" , lastResult ) ) ;
97106 if ( payload . text ?. trim ( ) ) {
98107 lastResult = await sendContext . withRetry (
99108 async ( ) =>
100109 await sendContext . send ( sendContext . target , payload . text , {
101110 verbose : false ,
102111 ...resolveDiscordFormattedDeliveryOptions ( ctx , sendContext ) ,
103112 replyTo : voiceReplyTo ,
113+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
104114 } ) ,
105115 ) ;
106116 }
@@ -111,6 +121,7 @@ export async function sendDiscordOutboundPayload(params: {
111121 verbose : false ,
112122 ...resolveDiscordMediaDeliveryOptions ( ctx , sendContext , mediaUrl ) ,
113123 replyTo : voiceReplyTo ,
124+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
114125 } ) ,
115126 ) ;
116127 }
@@ -146,6 +157,7 @@ export async function sendDiscordOutboundPayload(params: {
146157 embeds,
147158 filename,
148159 ...resolveDiscordFormattedDeliveryOptions ( ctx , sendContext ) ,
160+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
149161 } ) ,
150162 ) ,
151163 send : async ( { text, mediaUrl, isFirst } ) =>
@@ -157,6 +169,7 @@ export async function sendDiscordOutboundPayload(params: {
157169 components : isFirst ? nativeComponents : undefined ,
158170 embeds : isFirst ? embeds : undefined ,
159171 filename : isFirst ? filename : undefined ,
172+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
160173 } ) ,
161174 ) ,
162175 } ) ;
@@ -176,19 +189,22 @@ export async function sendDiscordOutboundPayload(params: {
176189 text : payload . text ?? "" ,
177190 mediaUrls,
178191 fallbackResult : createDiscordUnknownPayloadResult ( sendContext . target ) ,
179- sendNoMedia : async ( ) =>
180- await sendContext . withRetry (
192+ sendNoMedia : async ( ) => {
193+ return await sendContext . withRetry (
181194 async ( ) =>
182195 await sendDiscordComponentMessageLazy ( sendContext . target , componentSpec , {
183196 ...resolveDiscordFormattedDeliveryOptions ( ctx , sendContext ) ,
197+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
184198 } ) ,
185- ) ,
199+ ) ;
200+ } ,
186201 send : async ( { text, mediaUrl, isFirst } ) => {
187202 if ( isFirst ) {
188203 return await sendContext . withRetry (
189204 async ( ) =>
190205 await sendDiscordComponentMessageLazy ( sendContext . target , componentSpec , {
191206 ...resolveDiscordMediaDeliveryOptions ( ctx , sendContext , mediaUrl ) ,
207+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
192208 } ) ,
193209 ) ;
194210 }
@@ -197,6 +213,7 @@ export async function sendDiscordOutboundPayload(params: {
197213 await sendContext . send ( sendContext . target , text , {
198214 verbose : false ,
199215 ...resolveDiscordMediaDeliveryOptions ( ctx , sendContext , mediaUrl ) ,
216+ onDeliveryResult : resolveDiscordDeliveryProgress ( ctx ) ,
200217 } ) ,
201218 ) ;
202219 } ,
0 commit comments