@@ -66,16 +66,18 @@ export type OutboundPayloadMirror = {
|
66 | 66 | mediaUrls: string[]; |
67 | 67 | }; |
68 | 68 | |
69 | | -function collectPresentationMirrorText(presentation: MessagePresentation | undefined): string[] { |
70 | | -if (!presentation) { |
71 | | -return []; |
72 | | -} |
| 69 | +type MirrorTextBlock = MessagePresentation["blocks"][number] | InteractiveReply["blocks"][number]; |
| 70 | + |
| 71 | +function collectBlockMirrorText( |
| 72 | +blocks: readonly MirrorTextBlock[], |
| 73 | +options: { includeContext?: boolean } = {}, |
| 74 | +): string[] { |
73 | 75 | const lines: string[] = []; |
74 | | -if (presentation.title?.trim()) { |
75 | | -lines.push(presentation.title.trim()); |
76 | | -} |
77 | | -for (const block of presentation.blocks) { |
78 | | -if ((block.type === "text" || block.type === "context") && block.text.trim()) { |
| 76 | +for (const block of blocks) { |
| 77 | +if ( |
| 78 | + (block.type === "text" || (options.includeContext === true && block.type === "context")) && |
| 79 | + block.text.trim() |
| 80 | +) { |
79 | 81 | lines.push(block.text.trim()); |
80 | 82 | continue; |
81 | 83 | } |
@@ -101,38 +103,25 @@ function collectPresentationMirrorText(presentation: MessagePresentation | undef
|
101 | 103 | return lines; |
102 | 104 | } |
103 | 105 | |
104 | | -function collectInteractiveMirrorText(interactive: InteractiveReply | undefined): string[] { |
105 | | -if (!interactive) { |
| 106 | +function collectPresentationMirrorText(presentation: MessagePresentation | undefined): string[] { |
| 107 | +if (!presentation) { |
106 | 108 | return []; |
107 | 109 | } |
108 | 110 | const lines: string[] = []; |
109 | | -for (const block of interactive.blocks) { |
110 | | -if (block.type === "text" && block.text.trim()) { |
111 | | -lines.push(block.text.trim()); |
112 | | -continue; |
113 | | -} |
114 | | -if (block.type === "buttons") { |
115 | | -for (const button of block.buttons) { |
116 | | -if (button.label.trim()) { |
117 | | -lines.push(button.label.trim()); |
118 | | -} |
119 | | -} |
120 | | -continue; |
121 | | -} |
122 | | -if (block.type === "select") { |
123 | | -if (block.placeholder?.trim()) { |
124 | | -lines.push(block.placeholder.trim()); |
125 | | -} |
126 | | -for (const option of block.options) { |
127 | | -if (option.label.trim()) { |
128 | | -lines.push(option.label.trim()); |
129 | | -} |
130 | | -} |
131 | | -} |
| 111 | +if (presentation.title?.trim()) { |
| 112 | +lines.push(presentation.title.trim()); |
132 | 113 | } |
| 114 | +lines.push(...collectBlockMirrorText(presentation.blocks, { includeContext: true })); |
133 | 115 | return lines; |
134 | 116 | } |
135 | 117 | |
| 118 | +function collectInteractiveMirrorText(interactive: InteractiveReply | undefined): string[] { |
| 119 | +if (!interactive) { |
| 120 | +return []; |
| 121 | +} |
| 122 | +return collectBlockMirrorText(interactive.blocks); |
| 123 | +} |
| 124 | + |
136 | 125 | function resolveOutboundMirrorText(entry: OutboundPayloadPlan): string { |
137 | 126 | const text = entry.parts.text.trim() ? entry.parts.text : entry.payload.text; |
138 | 127 | if (text?.trim()) { |
|