@@ -9,6 +9,7 @@ import { getChannelPlugin } from "../../channels/plugins/index.js";
99import { getLoadedChannelPluginForRead } from "../../channels/plugins/registry-loaded.js" ;
1010import { normalizeAnyChannelId } from "../../channels/registry.js" ;
1111import type { OpenClawConfig } from "../../config/types.openclaw.js" ;
12+ import { hasReplyPayloadContent } from "../../interactive/payload.js" ;
1213import { normalizeMediaReferenceForComparison } from "../../media/media-reference-comparison.js" ;
1314import {
1415 channelRouteTargetsMatchExact ,
@@ -35,22 +36,6 @@ type MessagingToolDedupeRouteParams = {
3536 accountId ?: string ;
3637} ;
3738
38- /** Removes text payloads already sent by message tools. */
39- function filterMessagingToolDuplicates ( params : {
40- payloads : ReplyPayload [ ] ;
41- sentTexts : string [ ] ;
42- } ) : ReplyPayload [ ] {
43- const { payloads, sentTexts } = params ;
44- if ( sentTexts . length === 0 ) {
45- return payloads ;
46- }
47- return payloads . filter (
48- ( payload ) =>
49- Boolean ( payload . mediaUrl || payload . mediaUrls ?. length ) ||
50- ! isMessagingToolDuplicate ( payload . text ?? "" , sentTexts ) ,
51- ) ;
52- }
53-
5439/** Removes media payload URLs already sent by message tools. */
5540export function filterMessagingToolMediaDuplicates ( params : {
5641 payloads : ReplyPayload [ ] ;
@@ -110,12 +95,12 @@ export function filterMessagingToolMediaDuplicates(params: {
11095 }
11196
11297 const nextMediaUrl = stripSingle ? undefined : mediaUrl ;
113- const nextMediaUrls = filteredUrls ?. length ? filteredUrls : undefined ;
98+ const nextMediaUrls = strippedMediaUrls ? filteredUrls : mediaUrls ;
11499 const nextPayload = copyReplyPayloadMetadata ( payload , {
115100 ...payload ,
116101 mediaUrl : nextMediaUrl ,
117- mediaUrls : nextMediaUrls ,
118- ...( payload . audioAsVoice === true && ! nextMediaUrl && ! nextMediaUrls
102+ mediaUrls : nextMediaUrls ?. length ? nextMediaUrls : undefined ,
103+ ...( payload . audioAsVoice === true && ! nextMediaUrl && ! nextMediaUrls ?. length
119104 ? { audioAsVoice : undefined }
120105 : { } ) ,
121106 } ) ;
@@ -422,14 +407,22 @@ export function filterMessagingToolReplyPayload(
422407 decision . matchingRoute && ! decision . useGlobalSentTextEvidenceFallback
423408 ? decision . routeSentTexts
424409 : ( params . sentTexts ?? [ ] ) ;
425- const filterPayload = ( normalizedSentMediaUrls : string [ ] ) =>
426- filterMessagingToolDuplicates ( {
427- payloads : filterMessagingToolMediaDuplicates ( {
428- payloads : [ params . payload ] ,
429- sentMediaUrls : normalizedSentMediaUrls ,
430- } ) ,
431- sentTexts,
410+ const filterPayload = ( normalizedSentMediaUrls : string [ ] ) => {
411+ const payloads = filterMessagingToolMediaDuplicates ( {
412+ payloads : [ params . payload ] ,
413+ sentMediaUrls : normalizedSentMediaUrls ,
432414 } ) ;
415+ return sentTexts . length === 0
416+ ? payloads
417+ : payloads . filter (
418+ ( payload ) =>
419+ ! isMessagingToolDuplicate ( payload . text ?? "" , sentTexts ) ||
420+ hasReplyPayloadContent (
421+ { ...payload , text : undefined } ,
422+ { extraContent : hasEnabledDeliveryOperation ( payload ) || payload . location != null } ,
423+ ) ,
424+ ) ;
425+ } ;
433426 return params . normalizeSentMediaUrls
434427 ? params . normalizeSentMediaUrls ( sentMediaUrls ) . then ( filterPayload )
435428 : filterPayload ( sentMediaUrls ) ;
0 commit comments