@adatechnology/conversations-ui 0.1.0-rc.2 → 0.1.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZDURDZTM.js → chunk-2AYDBWNE.js} +14 -0
- package/dist/chunk-TV4OQRGH.js +2187 -0
- package/dist/flows/index.d.ts +14 -2
- package/dist/flows/index.js +117 -39
- package/dist/index.d.ts +862 -136
- package/dist/index.js +1746 -1124
- package/dist/preview/index.d.ts +470 -0
- package/dist/preview/index.js +1329 -0
- package/dist/styles.css +228 -0
- package/dist/types-C6A_9edv.d.ts +456 -0
- package/package.json +10 -3
- package/src/AudioRecorderButton.test.tsx +30 -0
- package/src/AudioRecorderButton.tsx +248 -0
- package/src/AudioTranscription.test.tsx +115 -0
- package/src/AudioTranscription.tsx +249 -0
- package/src/Avatar.tsx +30 -4
- package/src/ChannelIcon.tsx +87 -0
- package/src/ConversationContextPanel.tsx +280 -0
- package/src/ConversationDocumentsPanel.tsx +425 -0
- package/src/ConversationHeader.tsx +257 -0
- package/src/ConversationListItem.tsx +54 -7
- package/src/ConversationLocalesProvider.tsx +44 -0
- package/src/ConversationRow.tsx +137 -0
- package/src/DateDivider.tsx +16 -3
- package/src/DocumentsLibrary.tsx +322 -0
- package/src/EmojiPicker.tsx +69 -55
- package/src/FileIcon.test.ts +83 -0
- package/src/FileIcon.tsx +88 -11
- package/src/InteractiveMessage.test.tsx +41 -0
- package/src/InteractiveMessage.tsx +143 -0
- package/src/Lightbox.tsx +18 -3
- package/src/MediaRenderer.tsx +96 -22
- package/src/MessageBubble.tsx +77 -5
- package/src/MessageComposer.test.tsx +35 -0
- package/src/MessageComposer.tsx +165 -19
- package/src/RichMessageComposer.test.tsx +83 -0
- package/src/RichMessageComposer.tsx +380 -0
- package/src/Wallpaper.test.tsx +21 -0
- package/src/Wallpaper.tsx +69 -7
- package/src/WhatsAppMessageEditor.tsx +28 -4
- package/src/WindowExpiredNotice.tsx +57 -0
- package/src/audioRecorderFormat.test.ts +67 -0
- package/src/conversationChannel.test.ts +53 -0
- package/src/conversationChannel.ts +146 -0
- package/src/conversationTranscript.test.ts +122 -0
- package/src/conversationTranscript.ts +89 -0
- package/src/conversationWindow.test.ts +90 -0
- package/src/conversationWindow.ts +78 -0
- package/src/documentTypeLabel.test.ts +57 -0
- package/src/emojiCatalog.test.ts +35 -0
- package/src/emojiCatalog.ts +189 -0
- package/src/flows/FlowGroupHeader.tsx +12 -2
- package/src/flows/FlowMapCanvas.tsx +17 -14
- package/src/flows/FlowMapNode.tsx +3 -1
- package/src/flows/FlowNodeCard.tsx +22 -4
- package/src/flows/FlowNodePanel.tsx +132 -35
- package/src/flows/FlowPalette.tsx +6 -2
- package/src/flows/FlowWhatsAppPreview.tsx +14 -3
- package/src/flows/flowGraph.ts +5 -5
- package/src/flows/labels.ts +5 -0
- package/src/hooks/useConversationActions.ts +56 -0
- package/src/hooks/useConversationDocuments.ts +15 -9
- package/src/hooks/useConversationList.ts +15 -9
- package/src/hooks/useConversationMessages.ts +2 -2
- package/src/hooks/useScrollToLatestMessage.ts +127 -0
- package/src/index.ts +140 -16
- package/src/lib/cn.test.ts +29 -0
- package/src/lib/cn.ts +15 -0
- package/src/lib/createMediaUrlResolver.ts +33 -0
- package/src/lib/paginated.test.ts +33 -0
- package/src/lib/paginated.ts +26 -0
- package/src/lib/phone.ts +34 -0
- package/src/preview/ConversationPreview.tsx +334 -0
- package/src/preview/MediaTypesPreview.tsx +87 -0
- package/src/preview/conversationPreviewFailures.test.ts +64 -0
- package/src/preview/createMockConversationsApi.ts +271 -0
- package/src/preview/createMockSSEProvider.ts +40 -0
- package/src/preview/createPreviewBridgeClient.test.ts +92 -0
- package/src/preview/createPreviewBridgeClient.ts +124 -0
- package/src/preview/createPreviewMediaUploader.ts +82 -0
- package/src/preview/createPreviewWebhookClient.test.ts +194 -0
- package/src/preview/createPreviewWebhookClient.ts +222 -0
- package/src/preview/index.ts +67 -0
- package/src/preview/mediaTypeOf.test.ts +15 -0
- package/src/preview/mockDocumentsSearch.test.ts +57 -0
- package/src/preview/mockEventSource.ts +53 -0
- package/src/preview/preview.test.ts +177 -0
- package/src/preview/previewFileSamples.test.ts +151 -0
- package/src/preview/previewFileSamples.ts +74 -0
- package/src/preview/previewFixtures.ts +440 -0
- package/src/preview/previewMediaSource.test.ts +62 -0
- package/src/preview/previewMediaSource.ts +91 -0
- package/src/preview/previewMediaUploader.test.ts +61 -0
- package/src/preview/previewStore.ts +193 -0
- package/src/preview/startPreviewScript.ts +60 -0
- package/src/providers/types.ts +175 -12
- package/src/quickReply.test.ts +58 -0
- package/src/settings/TranscriptionSettingsForm.test.tsx +81 -0
- package/src/settings/TranscriptionSettingsForm.tsx +189 -0
- package/src/settings/WhatsAppCreateTemplateForm.tsx +3 -1
- package/src/settings/WhatsAppTemplatesSettings.tsx +106 -0
- package/src/styles.css +173 -0
- package/src/types.ts +72 -1
- package/src/useDarkMode.ts +26 -0
- package/src/useIsNarrow.ts +29 -0
- package/src/useWaitingNotifications.ts +74 -29
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
1
|
+
import { useState, type ReactNode } from 'react'
|
|
2
2
|
import { Plus, Trash2, Save, X, AlertTriangle, AlertCircle } from 'lucide-react'
|
|
3
3
|
import { FlowWhatsAppPreview } from './FlowWhatsAppPreview'
|
|
4
4
|
import { nodeLabel } from './FlowNodeCard'
|
|
5
|
-
import { CROSS_FLOW_PREFIX, CONDITION_OPERATORS } from './flowGraph'
|
|
5
|
+
import { CROSS_FLOW_PREFIX, CONDITION_OPERATORS, BUILT_IN_ACTION_KINDS } from './flowGraph'
|
|
6
6
|
import { DEFAULT_FLOW_EDITOR_LABELS, type FlowEditorLabels } from './labels'
|
|
7
7
|
import type { FlowGraphData, FlowNodeData, GraphIssue } from './flowGraph'
|
|
8
8
|
|
|
@@ -73,6 +73,14 @@ export interface FlowNodePanelProps {
|
|
|
73
73
|
onChange: (updated: FlowNodeData) => void
|
|
74
74
|
onDelete: (nodeId: string) => void
|
|
75
75
|
labels?: Partial<FlowEditorLabels>
|
|
76
|
+
/**
|
|
77
|
+
* Seletor de arquivos do nó `send_media`, renderizado no lugar da mensagem direta.
|
|
78
|
+
*
|
|
79
|
+
* Slot, e não uma lista de arquivos por prop, porque a biblioteca é do host: upload, permissão e
|
|
80
|
+
* URL assinada são dele, e o painel não tem como buscar nada. Ausente, o nó continua editável —
|
|
81
|
+
* só não dá para anexar por aqui.
|
|
82
|
+
*/
|
|
83
|
+
renderMediaPicker?: (node: FlowNodeData) => ReactNode
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
// Paridade com financiamento-imobiliario-bot/apps/web/src/components/flows/FlowNodePanel.tsx —
|
|
@@ -86,18 +94,26 @@ export function FlowNodePanel({
|
|
|
86
94
|
onChange,
|
|
87
95
|
onDelete,
|
|
88
96
|
labels: labelsOverride,
|
|
97
|
+
renderMediaPicker,
|
|
89
98
|
}: FlowNodePanelProps) {
|
|
90
99
|
const labels = { ...DEFAULT_FLOW_EDITOR_LABELS, ...labelsOverride }
|
|
91
100
|
const [draft, setDraft] = useState<FlowNodeData>(node)
|
|
92
101
|
const otherNodeIds = Object.keys(graph.nodes).filter((id) => id !== node.id)
|
|
93
102
|
const isFixedLogic = draft.type === 'entrada_choice'
|
|
94
103
|
const isAction = draft.type === 'action'
|
|
104
|
+
const isSendMedia = isAction && draft.actionKind === BUILT_IN_ACTION_KINDS.SEND_MEDIA
|
|
95
105
|
const isCondition = draft.type === 'condition'
|
|
96
106
|
const isStart = graph.startNodeId === node.id
|
|
97
107
|
const nodeIssues = issues.filter((i) => i.nodeId === node.id)
|
|
98
108
|
// Chaves já usadas por perguntas deste fluxo — sugestão pro campo de variável da condição,
|
|
99
109
|
// sem travar em texto livre (a variável pode ter vindo de outro fluxo ou de um cálculo derivado).
|
|
100
|
-
const knownContextKeys = [
|
|
110
|
+
const knownContextKeys = [
|
|
111
|
+
...new Set(
|
|
112
|
+
Object.values(graph.nodes)
|
|
113
|
+
.map((n) => n.contextKey)
|
|
114
|
+
.filter((key): key is string => !!key),
|
|
115
|
+
),
|
|
116
|
+
]
|
|
101
117
|
const conditionAnswerIds = isCondition ? ['true', 'false'] : (draft.options ?? []).map(([id]) => id)
|
|
102
118
|
|
|
103
119
|
function updateNextString(value: string) {
|
|
@@ -106,7 +122,8 @@ export function FlowNodePanel({
|
|
|
106
122
|
|
|
107
123
|
function updateNextByAnswer(answerId: string, value: string) {
|
|
108
124
|
setDraft((prev) => {
|
|
109
|
-
const current =
|
|
125
|
+
const current =
|
|
126
|
+
typeof prev.next === 'object' && prev.next ? prev.next : { byAnswer: {}, default: otherNodeIds[0] ?? '' }
|
|
110
127
|
return { ...prev, next: { ...current, byAnswer: { ...current.byAnswer, [answerId]: value } } }
|
|
111
128
|
})
|
|
112
129
|
}
|
|
@@ -129,7 +146,10 @@ export function FlowNodePanel({
|
|
|
129
146
|
}
|
|
130
147
|
|
|
131
148
|
function addOption() {
|
|
132
|
-
setDraft((prev) => ({
|
|
149
|
+
setDraft((prev) => ({
|
|
150
|
+
...prev,
|
|
151
|
+
options: [...(prev.options ?? []), [String((prev.options?.length ?? 0) + 1), 'Nova opção']],
|
|
152
|
+
}))
|
|
133
153
|
}
|
|
134
154
|
|
|
135
155
|
function removeOption(index: number) {
|
|
@@ -140,12 +160,16 @@ export function FlowNodePanel({
|
|
|
140
160
|
return (
|
|
141
161
|
<>
|
|
142
162
|
{otherNodeIds.map((id) => (
|
|
143
|
-
<option key={id} value={id}>
|
|
163
|
+
<option key={id} value={id}>
|
|
164
|
+
{truncateLabel(nodeLabel(graph.nodes[id], labels))}
|
|
165
|
+
</option>
|
|
144
166
|
))}
|
|
145
167
|
{otherFlows.length > 0 && (
|
|
146
168
|
<optgroup label={labels.nodePanel.otherFlowsGroup}>
|
|
147
169
|
{otherFlows.map((flow) => (
|
|
148
|
-
<option key={flow.key} value={`${CROSS_FLOW_PREFIX}${flow.key}`}>
|
|
170
|
+
<option key={flow.key} value={`${CROSS_FLOW_PREFIX}${flow.key}`}>
|
|
171
|
+
{flow.label}
|
|
172
|
+
</option>
|
|
149
173
|
))}
|
|
150
174
|
</optgroup>
|
|
151
175
|
)}
|
|
@@ -157,13 +181,17 @@ export function FlowNodePanel({
|
|
|
157
181
|
<div className="fixed inset-y-0 right-0 w-96 bg-white dark:bg-gray-800 border-l border-gray-200 dark:border-gray-700 shadow-xl z-50 flex flex-col">
|
|
158
182
|
<div className="flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-gray-700">
|
|
159
183
|
<h3 className="text-sm font-semibold text-gray-900 dark:text-gray-100">{labels.nodePanel.title}</h3>
|
|
160
|
-
<button onClick={onClose} className="text-gray-400 hover:text-gray-600"
|
|
184
|
+
<button onClick={onClose} className="text-gray-400 hover:text-gray-600">
|
|
185
|
+
<X size={18} />
|
|
186
|
+
</button>
|
|
161
187
|
</div>
|
|
162
188
|
|
|
163
189
|
<div className="flex-1 overflow-y-auto p-4 space-y-4">
|
|
164
190
|
{nodeIssues.length > 0 && (
|
|
165
191
|
<div className="rounded-lg border border-gray-100 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40 p-2.5 space-y-1.5">
|
|
166
|
-
{nodeIssues.map((issue, i) =>
|
|
192
|
+
{nodeIssues.map((issue, i) => (
|
|
193
|
+
<IssueRow key={i} issue={issue} />
|
|
194
|
+
))}
|
|
167
195
|
</div>
|
|
168
196
|
)}
|
|
169
197
|
|
|
@@ -185,21 +213,33 @@ export function FlowNodePanel({
|
|
|
185
213
|
|
|
186
214
|
{draft.contextKey && (
|
|
187
215
|
<div>
|
|
188
|
-
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
189
|
-
|
|
216
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
217
|
+
{labels.nodePanel.contextKey}
|
|
218
|
+
</label>
|
|
219
|
+
<input
|
|
220
|
+
value={draft.contextKey}
|
|
221
|
+
disabled
|
|
222
|
+
className="w-full mt-1 rounded-xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900 px-3 py-2.5 text-sm text-gray-500"
|
|
223
|
+
/>
|
|
190
224
|
</div>
|
|
191
225
|
)}
|
|
192
226
|
|
|
193
227
|
{!isFixedLogic && !isAction && !isCondition && (
|
|
194
228
|
<div>
|
|
195
|
-
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
229
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
230
|
+
{labels.nodePanel.questionType}
|
|
231
|
+
</label>
|
|
196
232
|
<select
|
|
197
233
|
value={draft.questionType ?? 'text'}
|
|
198
|
-
onChange={(e) =>
|
|
234
|
+
onChange={(e) =>
|
|
235
|
+
setDraft((prev) => ({ ...prev, questionType: e.target.value as FlowNodeData['questionType'] }))
|
|
236
|
+
}
|
|
199
237
|
className={`w-full mt-1 ${SELECT_CLASSNAME}`}
|
|
200
238
|
>
|
|
201
239
|
{Object.entries(labels.questionTypeLabels).map(([key, label]) => (
|
|
202
|
-
<option key={key} value={key}>
|
|
240
|
+
<option key={key} value={key}>
|
|
241
|
+
{label}
|
|
242
|
+
</option>
|
|
203
243
|
))}
|
|
204
244
|
</select>
|
|
205
245
|
</div>
|
|
@@ -218,7 +258,9 @@ export function FlowNodePanel({
|
|
|
218
258
|
{isCondition && (
|
|
219
259
|
<div className="space-y-3">
|
|
220
260
|
<div>
|
|
221
|
-
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
261
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
262
|
+
{labels.nodePanel.conditionVariable}
|
|
263
|
+
</label>
|
|
222
264
|
<input
|
|
223
265
|
value={draft.conditionContextKey ?? ''}
|
|
224
266
|
onChange={(e) => setDraft((prev) => ({ ...prev, conditionContextKey: e.target.value }))}
|
|
@@ -226,23 +268,36 @@ export function FlowNodePanel({
|
|
|
226
268
|
className={`w-full mt-1 ${INPUT_CLASSNAME}`}
|
|
227
269
|
/>
|
|
228
270
|
<datalist id="condition-context-keys">
|
|
229
|
-
{knownContextKeys.map((key) =>
|
|
271
|
+
{knownContextKeys.map((key) => (
|
|
272
|
+
<option key={key} value={key} />
|
|
273
|
+
))}
|
|
230
274
|
</datalist>
|
|
231
275
|
</div>
|
|
232
276
|
<div>
|
|
233
|
-
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
277
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
278
|
+
{labels.nodePanel.conditionOperator}
|
|
279
|
+
</label>
|
|
234
280
|
<select
|
|
235
281
|
value={draft.conditionOperator ?? '>'}
|
|
236
|
-
onChange={(e) =>
|
|
282
|
+
onChange={(e) =>
|
|
283
|
+
setDraft((prev) => ({
|
|
284
|
+
...prev,
|
|
285
|
+
conditionOperator: e.target.value as FlowNodeData['conditionOperator'],
|
|
286
|
+
}))
|
|
287
|
+
}
|
|
237
288
|
className={`w-full mt-1 ${SELECT_CLASSNAME}`}
|
|
238
289
|
>
|
|
239
290
|
{CONDITION_OPERATORS.map((operator) => (
|
|
240
|
-
<option key={operator} value={operator}>
|
|
291
|
+
<option key={operator} value={operator}>
|
|
292
|
+
{labels.conditionOperatorLabels[operator] ?? operator}
|
|
293
|
+
</option>
|
|
241
294
|
))}
|
|
242
295
|
</select>
|
|
243
296
|
</div>
|
|
244
297
|
<div>
|
|
245
|
-
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
298
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
299
|
+
{labels.nodePanel.conditionValue}
|
|
300
|
+
</label>
|
|
246
301
|
<input
|
|
247
302
|
value={draft.conditionValue ?? ''}
|
|
248
303
|
onChange={(e) => setDraft((prev) => ({ ...prev, conditionValue: e.target.value }))}
|
|
@@ -262,7 +317,21 @@ export function FlowNodePanel({
|
|
|
262
317
|
/>
|
|
263
318
|
)}
|
|
264
319
|
|
|
265
|
-
{
|
|
320
|
+
{/* Os arquivos moram na biblioteca, não no grafo — trocar o material não repassa pelo editor. */}
|
|
321
|
+
{isSendMedia && (
|
|
322
|
+
<div>
|
|
323
|
+
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">{labels.nodePanel.media}</label>
|
|
324
|
+
<div className="mt-1">
|
|
325
|
+
{renderMediaPicker?.(node) ?? (
|
|
326
|
+
<p className="text-xs text-gray-400">{labels.nodePanel.mediaUnavailable}</p>
|
|
327
|
+
)}
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
)}
|
|
331
|
+
|
|
332
|
+
{/* `send_media` fica de fora: o handler do módulo só envia os anexos, então um campo de
|
|
333
|
+
mensagem aqui seria texto que o cliente nunca recebe. A legenda é por arquivo. */}
|
|
334
|
+
{isAction && draft.actionKind !== 'send_product_list' && !isSendMedia && (
|
|
266
335
|
<WhatsAppTextField
|
|
267
336
|
label={labels.nodePanel.directMessage}
|
|
268
337
|
value={draft.directMessage ?? ''}
|
|
@@ -283,11 +352,21 @@ export function FlowNodePanel({
|
|
|
283
352
|
<div className="space-y-2">
|
|
284
353
|
{(draft.options ?? []).map(([id, label], i) => (
|
|
285
354
|
<div key={i} className="flex items-center gap-2">
|
|
286
|
-
<input
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
355
|
+
<input
|
|
356
|
+
value={id}
|
|
357
|
+
onChange={(e) => updateOption(i, 0, e.target.value)}
|
|
358
|
+
placeholder={labels.nodePanel.optionId}
|
|
359
|
+
className={`w-16 ${INPUT_CLASSNAME}`}
|
|
360
|
+
/>
|
|
361
|
+
<input
|
|
362
|
+
value={label}
|
|
363
|
+
onChange={(e) => updateOption(i, 1, e.target.value)}
|
|
364
|
+
placeholder={labels.nodePanel.optionLabel}
|
|
365
|
+
className={`flex-1 ${INPUT_CLASSNAME}`}
|
|
366
|
+
/>
|
|
367
|
+
<button onClick={() => removeOption(i)} className="text-gray-400 hover:text-red-600">
|
|
368
|
+
<Trash2 size={14} />
|
|
369
|
+
</button>
|
|
291
370
|
</div>
|
|
292
371
|
))}
|
|
293
372
|
</div>
|
|
@@ -299,8 +378,11 @@ export function FlowNodePanel({
|
|
|
299
378
|
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">{labels.nodePanel.next}</label>
|
|
300
379
|
<p className="text-[11px] text-gray-400 dark:text-gray-500 mb-1">{labels.nodePanel.nextHint}</p>
|
|
301
380
|
{typeof draft.next !== 'object' && !isCondition ? (
|
|
302
|
-
<select
|
|
303
|
-
|
|
381
|
+
<select
|
|
382
|
+
value={typeof draft.next === 'string' ? draft.next : ''}
|
|
383
|
+
onChange={(e) => updateNextString(e.target.value)}
|
|
384
|
+
className={`w-full mt-1 ${SELECT_CLASSNAME}`}
|
|
385
|
+
>
|
|
304
386
|
<option value="">—</option>
|
|
305
387
|
{nextNodeOptions()}
|
|
306
388
|
</select>
|
|
@@ -309,10 +391,17 @@ export function FlowNodePanel({
|
|
|
309
391
|
{conditionAnswerIds.map((id) => (
|
|
310
392
|
<div key={id} className="flex items-center gap-2">
|
|
311
393
|
<span className="text-xs text-gray-500 w-32 shrink-0">
|
|
312
|
-
{isCondition
|
|
394
|
+
{isCondition
|
|
395
|
+
? id === 'true'
|
|
396
|
+
? labels.nodePanel.conditionTrue
|
|
397
|
+
: labels.nodePanel.conditionFalse
|
|
398
|
+
: labels.nodePanel.nextByAnswer(id)}
|
|
313
399
|
</span>
|
|
314
|
-
<select
|
|
315
|
-
|
|
400
|
+
<select
|
|
401
|
+
value={draft.next && typeof draft.next === 'object' ? (draft.next.byAnswer[id] ?? '') : ''}
|
|
402
|
+
onChange={(e) => updateNextByAnswer(id, e.target.value)}
|
|
403
|
+
className={`flex-1 ${SELECT_CLASSNAME}`}
|
|
404
|
+
>
|
|
316
405
|
<option value="">—</option>
|
|
317
406
|
{nextNodeOptions()}
|
|
318
407
|
</select>
|
|
@@ -322,8 +411,11 @@ export function FlowNodePanel({
|
|
|
322
411
|
<span className="text-xs text-gray-500 w-32 shrink-0">
|
|
323
412
|
{isCondition ? labels.nodePanel.conditionVariableMissing : labels.nodePanel.nextDefault}
|
|
324
413
|
</span>
|
|
325
|
-
<select
|
|
326
|
-
|
|
414
|
+
<select
|
|
415
|
+
value={draft.next && typeof draft.next === 'object' ? draft.next.default : ''}
|
|
416
|
+
onChange={(e) => updateNextDefault(e.target.value)}
|
|
417
|
+
className={`flex-1 ${SELECT_CLASSNAME}`}
|
|
418
|
+
>
|
|
327
419
|
<option value="">—</option>
|
|
328
420
|
{nextNodeOptions()}
|
|
329
421
|
</select>
|
|
@@ -335,12 +427,17 @@ export function FlowNodePanel({
|
|
|
335
427
|
</div>
|
|
336
428
|
|
|
337
429
|
<div className="p-4 border-t border-gray-100 dark:border-gray-700 flex gap-2">
|
|
338
|
-
<button
|
|
430
|
+
<button
|
|
431
|
+
onClick={() => onChange(draft)}
|
|
432
|
+
className="flex-1 inline-flex items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700"
|
|
433
|
+
>
|
|
339
434
|
<Save size={14} /> {labels.nodePanel.save}
|
|
340
435
|
</button>
|
|
341
436
|
{!isStart && (
|
|
342
437
|
<button
|
|
343
|
-
onClick={() => {
|
|
438
|
+
onClick={() => {
|
|
439
|
+
if (window.confirm(labels.nodePanel.deleteConfirm)) onDelete(node.id)
|
|
440
|
+
}}
|
|
344
441
|
title={labels.nodePanel.delete}
|
|
345
442
|
className="px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
|
346
443
|
>
|
|
@@ -72,7 +72,9 @@ export function FlowPalette({ onAdd, labels: labelsOverride, actionOptions }: Fl
|
|
|
72
72
|
onClick={() => setSubmenu(submenu === 'question' ? null : 'question')}
|
|
73
73
|
className="w-full flex items-center justify-between gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"
|
|
74
74
|
>
|
|
75
|
-
<span className="flex items-center gap-2"
|
|
75
|
+
<span className="flex items-center gap-2">
|
|
76
|
+
<MessageCircleQuestion size={15} className="text-blue-500" /> {labels.palette.question}
|
|
77
|
+
</span>
|
|
76
78
|
<ChevronRight size={13} className="text-gray-400" />
|
|
77
79
|
</button>
|
|
78
80
|
{submenu === 'question' && (
|
|
@@ -113,7 +115,9 @@ export function FlowPalette({ onAdd, labels: labelsOverride, actionOptions }: Fl
|
|
|
113
115
|
onClick={() => setSubmenu(submenu === 'action' ? null : 'action')}
|
|
114
116
|
className="w-full flex items-center justify-between gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"
|
|
115
117
|
>
|
|
116
|
-
<span className="flex items-center gap-2"
|
|
118
|
+
<span className="flex items-center gap-2">
|
|
119
|
+
<Zap size={15} className="text-orange-500" /> {labels.palette.action}
|
|
120
|
+
</span>
|
|
117
121
|
<ChevronRight size={13} className="text-gray-400" />
|
|
118
122
|
</button>
|
|
119
123
|
{submenu === 'action' && (
|
|
@@ -13,7 +13,11 @@ export interface FlowWhatsAppPreviewProps {
|
|
|
13
13
|
// opções, botões (≤3) ou lista (4+) — para o editor mostrar exatamente o que o cliente verá.
|
|
14
14
|
// Consome a mesma bolha/formatação do pacote (parseWhatsAppFormatting, T6.5) — T7.3 elimina a
|
|
15
15
|
// duplicação de estilo que existia entre este preview e o MessageBubble do bot.
|
|
16
|
-
export function FlowWhatsAppPreview({
|
|
16
|
+
export function FlowWhatsAppPreview({
|
|
17
|
+
body,
|
|
18
|
+
options,
|
|
19
|
+
labels = DEFAULT_FLOW_EDITOR_LABELS.nodePanel,
|
|
20
|
+
}: FlowWhatsAppPreviewProps) {
|
|
17
21
|
if (!body && (!options || options.length === 0)) {
|
|
18
22
|
return <p className="text-xs text-gray-400 dark:text-gray-500 italic px-1">{labels.previewPlaceholder}</p>
|
|
19
23
|
}
|
|
@@ -25,7 +29,11 @@ export function FlowWhatsAppPreview({ body, options, labels = DEFAULT_FLOW_EDITO
|
|
|
25
29
|
<div className="rounded-xl bg-[#e5ddd5] dark:bg-gray-900 p-3 space-y-1.5">
|
|
26
30
|
<div className="max-w-[85%]">
|
|
27
31
|
<div className="rounded-lg rounded-tl-none bg-white dark:bg-gray-700 px-3 py-2 text-sm text-gray-900 dark:text-gray-100 shadow-sm whitespace-pre-wrap break-words">
|
|
28
|
-
{body ?
|
|
32
|
+
{body ? (
|
|
33
|
+
parseWhatsAppFormatting(body)
|
|
34
|
+
) : (
|
|
35
|
+
<span className="italic text-gray-400">{labels.previewEmptyBody}</span>
|
|
36
|
+
)}
|
|
29
37
|
{hasOptions && !usesButtons && (
|
|
30
38
|
<div className="mt-2 -mx-3 -mb-2 border-t border-gray-100 dark:border-gray-600">
|
|
31
39
|
<div className="flex items-center justify-center gap-1.5 py-2 text-sm font-medium text-cyan-600 dark:text-cyan-400">
|
|
@@ -38,7 +46,10 @@ export function FlowWhatsAppPreview({ body, options, labels = DEFAULT_FLOW_EDITO
|
|
|
38
46
|
{hasOptions && usesButtons && (
|
|
39
47
|
<div className="mt-1 space-y-1">
|
|
40
48
|
{options!.map(([id, label]) => (
|
|
41
|
-
<div
|
|
49
|
+
<div
|
|
50
|
+
key={id}
|
|
51
|
+
className="rounded-lg bg-white dark:bg-gray-700 py-1.5 text-center text-sm font-medium text-cyan-600 dark:text-cyan-400 shadow-sm"
|
|
52
|
+
>
|
|
42
53
|
{label || <span className="italic text-gray-400">{labels.previewEmptyOption}</span>}
|
|
43
54
|
</div>
|
|
44
55
|
))}
|
package/src/flows/flowGraph.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
FlowNodeData,
|
|
14
14
|
FlowGraphData,
|
|
15
15
|
} from '@adatechnology/meta-whatsapp-contracts'
|
|
16
|
+
import { FLOW_ACTION_KIND } from '@adatechnology/meta-whatsapp-contracts'
|
|
16
17
|
|
|
17
18
|
export type {
|
|
18
19
|
FlowNodeType,
|
|
@@ -28,11 +29,10 @@ export const CONDITION_OPERATORS: FlowConditionOperator[] = ['>', '>=', '<', '<=
|
|
|
28
29
|
|
|
29
30
|
// Kinds de ação genéricos que o pacote conhece de fábrica — o host pode registrar quaisquer
|
|
30
31
|
// outros via `actionKindLabels`/`actionKinds` nos componentes (ver FlowPalette, labels.ts).
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} as const
|
|
32
|
+
// Reexporta o vocabulário do contrato em vez de redeclarar os literais: o editor oferece na
|
|
33
|
+
// paleta exatamente os `actionKind` que o backend sabe interpretar, e duas listas separadas
|
|
34
|
+
// divergiriam em silêncio (um nó publicável que nenhum handler atende).
|
|
35
|
+
export const BUILT_IN_ACTION_KINDS = FLOW_ACTION_KIND
|
|
36
36
|
|
|
37
37
|
// Destinos "flow:<key>" são saltos para outro fluxo, resolvidos pelo motor do host. Duplicado
|
|
38
38
|
// (em vez de importado do contracts) de propósito: são três linhas triviais e importá-las como
|
package/src/flows/labels.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface FlowEditorLabels {
|
|
|
47
47
|
conditionTrue: string
|
|
48
48
|
conditionFalse: string
|
|
49
49
|
conditionVariableMissing: string
|
|
50
|
+
media: string
|
|
51
|
+
mediaUnavailable: string
|
|
50
52
|
}
|
|
51
53
|
palette: {
|
|
52
54
|
title: string
|
|
@@ -87,6 +89,7 @@ export const DEFAULT_FLOW_EDITOR_LABELS: FlowEditorLabels = {
|
|
|
87
89
|
handoff: 'Encaminhar para atendimento',
|
|
88
90
|
rate_limited_handoff: 'Encaminhar (limite de simulações atingido)',
|
|
89
91
|
send_product_list: 'Enviar catálogo de produtos',
|
|
92
|
+
send_media: 'Enviar arquivos da biblioteca',
|
|
90
93
|
},
|
|
91
94
|
conditionOperatorLabels: {
|
|
92
95
|
'>': 'maior que',
|
|
@@ -143,6 +146,8 @@ export const DEFAULT_FLOW_EDITOR_LABELS: FlowEditorLabels = {
|
|
|
143
146
|
conditionTrue: 'Se verdadeiro →',
|
|
144
147
|
conditionFalse: 'Se falso →',
|
|
145
148
|
conditionVariableMissing: 'Se a variável ainda não foi coletada →',
|
|
149
|
+
media: 'Arquivos enviados neste ponto',
|
|
150
|
+
mediaUnavailable: 'A biblioteca de arquivos não está disponível neste painel.',
|
|
146
151
|
},
|
|
147
152
|
palette: {
|
|
148
153
|
title: 'Adicionar ao fluxo',
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useConversations } from '../providers/ConversationsProvider'
|
|
3
|
+
import type { ConversationTemplate } from '../providers/types'
|
|
4
|
+
|
|
5
|
+
export interface UseConversationActionsResult {
|
|
6
|
+
/** `undefined` quando a API do host não implementa a operação — a UI esconde a afordância. */
|
|
7
|
+
takeover: (() => Promise<void>) | undefined
|
|
8
|
+
release: (() => Promise<void>) | undefined
|
|
9
|
+
finalize: (() => Promise<void>) | undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Ações de atendimento de UMA conversa, já ligadas ao id.
|
|
14
|
+
*
|
|
15
|
+
* Separado de `useConversationMessages` porque assumir e devolver conversa também acontece a
|
|
16
|
+
* partir da lista, onde nenhuma thread está aberta — embutir nas mensagens obrigaria a carregar
|
|
17
|
+
* a thread inteira só para desenhar um botão na linha.
|
|
18
|
+
*/
|
|
19
|
+
export function useConversationActions(conversationId: string): UseConversationActionsResult {
|
|
20
|
+
const context = useConversations()
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error('useConversationActions requires an ancestor <ConversationsProvider>')
|
|
23
|
+
}
|
|
24
|
+
const { api } = context
|
|
25
|
+
|
|
26
|
+
return useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
takeover: api.takeover ? () => api.takeover!(conversationId) : undefined,
|
|
29
|
+
release: api.release ? () => api.release!(conversationId) : undefined,
|
|
30
|
+
finalize: api.finalize ? () => api.finalize!(conversationId) : undefined,
|
|
31
|
+
}),
|
|
32
|
+
[api, conversationId],
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface UseInboxActionsResult {
|
|
37
|
+
markAllRead: (() => Promise<void>) | undefined
|
|
38
|
+
listTemplates: (() => Promise<ConversationTemplate[]>) | undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Ações que valem para a caixa inteira, sem conversa selecionada. */
|
|
42
|
+
export function useInboxActions(): UseInboxActionsResult {
|
|
43
|
+
const context = useConversations()
|
|
44
|
+
if (!context) {
|
|
45
|
+
throw new Error('useInboxActions requires an ancestor <ConversationsProvider>')
|
|
46
|
+
}
|
|
47
|
+
const { api } = context
|
|
48
|
+
|
|
49
|
+
return useMemo(
|
|
50
|
+
() => ({
|
|
51
|
+
markAllRead: api.markAllRead ? () => api.markAllRead!() : undefined,
|
|
52
|
+
listTemplates: api.listTemplates ? () => api.listTemplates!() : undefined,
|
|
53
|
+
}),
|
|
54
|
+
[api],
|
|
55
|
+
)
|
|
56
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { useConversations } from '../providers/ConversationsProvider'
|
|
2
2
|
import { useAsyncResource } from './useAsyncResource'
|
|
3
|
-
import
|
|
3
|
+
import { documentsOf, totalOf } from '../lib/paginated'
|
|
4
|
+
import type { ConversationDocument, ListDocumentsParams } from '../providers/types'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
search?: string
|
|
7
|
-
page?: number
|
|
8
|
-
}
|
|
6
|
+
export type UseConversationDocumentsParams = ListDocumentsParams
|
|
9
7
|
|
|
10
8
|
export interface UseConversationDocumentsResult {
|
|
11
9
|
documents: ConversationDocument[]
|
|
10
|
+
/** Total no servidor. Cai para o tamanho da página quando a API devolve só o array. */
|
|
11
|
+
total: number
|
|
12
12
|
loading: boolean
|
|
13
13
|
error: Error | undefined
|
|
14
14
|
refetch: () => Promise<void>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// Aceita `undefined` como "ainda não buscar", igual a `useConversationRealtime`: a lista de anexos
|
|
18
|
+
// é consulta extra, e quem só abre o painel sob demanda não deve pagar por ela em toda conversa.
|
|
17
19
|
export function useConversationDocuments(
|
|
18
|
-
conversationId: string,
|
|
20
|
+
conversationId: string | undefined,
|
|
19
21
|
params?: UseConversationDocumentsParams,
|
|
20
22
|
): UseConversationDocumentsResult {
|
|
21
23
|
const context = useConversations()
|
|
@@ -25,9 +27,13 @@ export function useConversationDocuments(
|
|
|
25
27
|
const { api } = context
|
|
26
28
|
|
|
27
29
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
28
|
-
() => api.getDocuments(conversationId, params),
|
|
29
|
-
[conversationId, params?.search, params?.page],
|
|
30
|
+
() => (conversationId ? api.getDocuments(conversationId, params) : Promise.resolve([])),
|
|
31
|
+
[conversationId, params?.search, params?.page, params?.limit, params?.source, params?.sortDirection],
|
|
30
32
|
)
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
if (data === undefined) {
|
|
35
|
+
return { documents: [], total: 0, loading, error, refetch }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { documents: documentsOf(data), total: totalOf(data), loading, error, refetch }
|
|
33
39
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { useConversations } from '../providers/ConversationsProvider'
|
|
2
2
|
import { useAsyncResource } from './useAsyncResource'
|
|
3
|
-
import
|
|
3
|
+
import { conversationsOf, totalOf } from '../lib/paginated'
|
|
4
|
+
import type { ConversationSummary, ListConversationsParams } from '../providers/types'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
page?: number
|
|
7
|
-
limit?: number
|
|
8
|
-
waitingHuman?: boolean
|
|
9
|
-
search?: string
|
|
10
|
-
}
|
|
6
|
+
export type UseConversationListParams = ListConversationsParams
|
|
11
7
|
|
|
12
8
|
export interface UseConversationListResult {
|
|
13
9
|
conversations: ConversationSummary[]
|
|
10
|
+
/** Total no servidor. Cai para o tamanho da página quando a API devolve só o array. */
|
|
11
|
+
total: number
|
|
14
12
|
loading: boolean
|
|
15
13
|
error: Error | undefined
|
|
16
14
|
refetch: () => Promise<void>
|
|
@@ -23,10 +21,18 @@ export function useConversationList(params?: UseConversationListParams): UseConv
|
|
|
23
21
|
}
|
|
24
22
|
const { api } = context
|
|
25
23
|
|
|
24
|
+
// `filters` é objeto novo a cada render do host; serializar evita refetch em laço sem obrigar
|
|
25
|
+
// o consumidor a memoizar — omissão que só apareceria como loop de rede em produção.
|
|
26
|
+
const filtersKey = JSON.stringify(params?.filters ?? {})
|
|
27
|
+
|
|
26
28
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
27
29
|
() => api.fetchConversations(params),
|
|
28
|
-
[params?.page, params?.limit, params?.waitingHuman, params?.search],
|
|
30
|
+
[params?.page, params?.limit, params?.waitingHuman, params?.search, filtersKey],
|
|
29
31
|
)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
if (data === undefined) {
|
|
34
|
+
return { conversations: [], total: 0, loading, error, refetch }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { conversations: conversationsOf(data), total: totalOf(data), loading, error, refetch }
|
|
32
38
|
}
|
|
@@ -10,7 +10,7 @@ export interface UseConversationMessagesResult {
|
|
|
10
10
|
refetch: () => Promise<void>
|
|
11
11
|
sendMessage: (text: string) => Promise<MessagePayload>
|
|
12
12
|
sendMedia: (data: { base64: string; mimeType: string; filename: string; caption?: string }) => Promise<MessagePayload>
|
|
13
|
-
sendTemplate: (data: { templateName
|
|
13
|
+
sendTemplate: (data: { templateName?: string; languageCode?: string; bodyParams?: string[] }) => Promise<void>
|
|
14
14
|
markRead: () => Promise<void>
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -51,7 +51,7 @@ export function useConversationMessages(
|
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
const sendTemplate = useCallback(
|
|
54
|
-
async (templateData: { templateName
|
|
54
|
+
async (templateData: { templateName?: string; languageCode?: string; bodyParams?: string[] }) => {
|
|
55
55
|
await api.sendTemplate(conversationId, templateData)
|
|
56
56
|
await refetch()
|
|
57
57
|
},
|