@@ -28,10 +28,7 @@ import { createChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-run
2828import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared" ;
2929import {
3030 type MessagePresentation ,
31- normalizeMessagePresentation ,
32- renderMessagePresentationFallbackText ,
3331 resolveMessagePresentationButtonAction ,
34- resolveMessagePresentationControlValue ,
3532} from "openclaw/plugin-sdk/interactive-runtime" ;
3633import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime" ;
3734import { resolvePayloadMediaUrls , sendTextMediaPayload } from "openclaw/plugin-sdk/reply-payload" ;
@@ -73,6 +70,7 @@ import type { MattermostSendResult } from "./mattermost/send.js";
7370import {
7471 looksLikeMattermostTargetId ,
7572 normalizeMattermostMessagingTarget ,
73+ resolveMattermostPresentation ,
7674 requiresMattermostMediaUpload ,
7775} from "./normalize.js" ;
7876import { collectRuntimeConfigAssignments , secretTargetRegistryEntries } from "./secret-contract.js" ;
@@ -83,33 +81,6 @@ import type { MattermostConfig } from "./types.js";
8381
8482const loadMattermostChannelRuntime = createLazyRuntimeModule ( ( ) => import ( "./channel.runtime.js" ) ) ;
8583
86- function buildMattermostPresentationButtons ( presentation : MessagePresentation ) {
87- return presentation . blocks
88- . filter ( ( block ) => block . type === "buttons" )
89- . map ( ( block ) =>
90- block . buttons . flatMap ( ( button ) => {
91- if ( button . action ) {
92- return [ ] ;
93- }
94- const value = resolveMessagePresentationControlValue ( button ) ;
95- return value
96- ? [
97- {
98- id : value ,
99- text : button . label ,
100- callback_data : value ,
101- context : {
102- callback_data : value ,
103- } ,
104- style : button . style ,
105- } ,
106- ]
107- : [ ] ;
108- } ) ,
109- )
110- . filter ( ( row ) => row . length > 0 ) ;
111- }
112-
11384const MATTERMOST_PRESENTATION_CAPABILITIES = {
11485 supported : true ,
11586 buttons : true ,
@@ -572,15 +543,10 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
572543 throw new Error ( "Mattermost send requires a target (to)." ) ;
573544 }
574545
575- const presentation = normalizeMessagePresentation ( params . presentation ) ;
576- const message = presentation
577- ? renderMessagePresentationFallbackText ( {
578- text : typeof params . message === "string" ? params . message : "" ,
579- presentation,
580- } )
581- : typeof params . message === "string"
582- ? params . message
583- : "" ;
546+ const { text : message , buttons } = resolveMattermostPresentation ( {
547+ text : typeof params . message === "string" ? params . message : undefined ,
548+ presentation : params . presentation ,
549+ } ) ;
584550 // Mattermost post root_id is the thread root. A generic replyTo can name
585551 // the current child post, so prefer threadId unless the caller supplied the
586552 // Mattermost-specific replyToId root directly.
@@ -591,8 +557,6 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
591557 const resolvedAccountId = accountId || undefined ;
592558
593559 const mediaUrl = resolveMattermostSendAttachmentMedia ( params ) ;
594- const buttons = presentation ? buildMattermostPresentationButtons ( presentation ) : [ ] ;
595-
596560 const result = await (
597561 await loadMattermostChannelRuntime ( )
598562 ) . sendMessageMattermost ( to , message , {
@@ -803,15 +767,14 @@ const mattermostOutbound: ChannelOutboundAdapter = {
803767 if ( payload . mediaUrls && payload . mediaUrls . length > 1 ) {
804768 return null ;
805769 }
806- const buttons = buildMattermostPresentationButtons ( presentation ) ;
807- const hasButtons = buttons . some ( ( row ) => row . length > 0 ) ;
808- if ( ! hasButtons && ! hasMattermostPresentationNavigation ( presentation ) ) {
770+ const { text, buttons } = resolveMattermostPresentation ( { text : payload . text , presentation } ) ;
771+ if ( ! buttons . length && ! hasMattermostPresentationNavigation ( presentation ) ) {
809772 return null ;
810773 }
811774 return {
812775 ...payload ,
813- text : renderMessagePresentationFallbackText ( { text : payload . text , presentation } ) ,
814- ...( hasButtons
776+ text,
777+ ...( buttons . length
815778 ? {
816779 channelData : {
817780 ...payload . channelData ,
0 commit comments