@adatechnology/conversations-ui 0.16.0 → 0.17.0
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/README.md +23 -0
- package/dist/{chunk-Y326LLEP.js → chunk-7OLYCCLX.js} +1 -1
- package/dist/{chunk-WCZNIJ3M.js → chunk-Z7U22M3K.js} +7 -0
- package/dist/flows/index.d.ts +19 -3
- package/dist/flows/index.js +426 -238
- package/dist/index.d.ts +34 -3
- package/dist/index.js +88 -23
- package/dist/participant/index.js +1 -1
- package/dist/preview/index.js +2 -2
- package/package.json +2 -2
- package/src/flows/FlowNodeCard.tsx +17 -7
- package/src/flows/FlowNodePanel.tsx +10 -0
- package/src/flows/FlowPossibleNextField.tsx +89 -0
- package/src/flows/FlowRunnerFields.tsx +70 -16
- package/src/flows/flowCanvasModel.ts +16 -1
- package/src/flows/flowEditorOps.ts +19 -2
- package/src/flows/flowGraph.ts +37 -7
- package/src/flows/flowPossibleNext.test.ts +70 -0
- package/src/flows/labels.ts +28 -1
- package/src/index.ts +2 -1
- package/src/lib/phone.test.ts +20 -0
- package/src/lib/phone.ts +13 -0
- package/src/workspace/ConversationPane.tsx +13 -2
- package/src/workspace/ConversationsWorkspace.tsx +117 -18
- package/src/workspace/index.ts +1 -0
- package/src/workspace/labels.ts +2 -0
- package/src/workspace/workspaceTestContactDom.test.tsx +96 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { ReactNode } from 'react'
|
|
10
10
|
import type { FlowAnswerValidation, FlowNodeData } from './flowGraph'
|
|
11
|
-
import type
|
|
11
|
+
import { OPTIONAL_RUNNER_FIELD_LABEL_DEFAULTS, type FlowRunnerFieldLabels } from './labels'
|
|
12
12
|
import { FlowKeywordRoutesField } from './FlowKeywordRoutesField'
|
|
13
13
|
import { PANEL_FIELD_CLASSNAME, PANEL_HINT_CLASSNAME, PANEL_LABEL_CLASSNAME } from './flowPanelStyles'
|
|
14
14
|
|
|
@@ -50,7 +50,67 @@ function NumberField(props: {
|
|
|
50
50
|
)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function
|
|
53
|
+
function ContextKeyField(props: {
|
|
54
|
+
label: string
|
|
55
|
+
hint?: string
|
|
56
|
+
value: string | undefined
|
|
57
|
+
knownContextKeys: readonly string[]
|
|
58
|
+
onValueChange: (value: string | undefined) => void
|
|
59
|
+
}) {
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
<label className={PANEL_LABEL_CLASSNAME}>{props.label}</label>
|
|
63
|
+
<input
|
|
64
|
+
value={props.value ?? ''}
|
|
65
|
+
list="runner-context-keys"
|
|
66
|
+
onChange={(event) => props.onValueChange(event.target.value || undefined)}
|
|
67
|
+
className={`w-full mt-1 ${PANEL_FIELD_CLASSNAME}`}
|
|
68
|
+
/>
|
|
69
|
+
<datalist id="runner-context-keys">
|
|
70
|
+
{props.knownContextKeys.map((key) => (
|
|
71
|
+
<option key={key} value={key} />
|
|
72
|
+
))}
|
|
73
|
+
</datalist>
|
|
74
|
+
{props.hint && <p className={PANEL_HINT_CLASSNAME}>{props.hint}</p>}
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function TimeValidationFields({ draft, onDraftChange, knownContextKeys, labels }: FlowRunnerFieldsProps) {
|
|
80
|
+
const validation = draft.validation ?? {}
|
|
81
|
+
const update = (patch: Partial<FlowAnswerValidation>) => onDraftChange((previous) => withValidation(previous, patch))
|
|
82
|
+
const defaults = OPTIONAL_RUNNER_FIELD_LABEL_DEFAULTS
|
|
83
|
+
const timeInput = (label: string, value: string | undefined, onValueChange: (value: string | undefined) => void) => (
|
|
84
|
+
<div className="flex-1">
|
|
85
|
+
<label className={PANEL_LABEL_CLASSNAME}>{label}</label>
|
|
86
|
+
<input
|
|
87
|
+
type="time"
|
|
88
|
+
value={value ?? ''}
|
|
89
|
+
onChange={(event) => onValueChange(event.target.value || undefined)}
|
|
90
|
+
className={`w-full mt-1 ${PANEL_FIELD_CLASSNAME}`}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className="space-y-2">
|
|
97
|
+
<div className="flex gap-2">
|
|
98
|
+
{timeInput(labels.minTime ?? defaults.minTime, validation.minTime, (minTime) => update({ minTime }))}
|
|
99
|
+
{timeInput(labels.maxTime ?? defaults.maxTime, validation.maxTime, (maxTime) => update({ maxTime }))}
|
|
100
|
+
</div>
|
|
101
|
+
<ContextKeyField
|
|
102
|
+
label={labels.timeWindowsContextKey ?? defaults.timeWindowsContextKey}
|
|
103
|
+
hint={labels.timeWindowsContextKeyHint ?? defaults.timeWindowsContextKeyHint}
|
|
104
|
+
value={validation.windowsContextKey}
|
|
105
|
+
knownContextKeys={knownContextKeys}
|
|
106
|
+
onValueChange={(windowsContextKey) => update({ windowsContextKey })}
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function ValidationFields(props: FlowRunnerFieldsProps) {
|
|
113
|
+
const { draft, onDraftChange, knownContextKeys, labels } = props
|
|
54
114
|
const validation = draft.validation ?? {}
|
|
55
115
|
const update = (patch: Partial<FlowAnswerValidation>) => onDraftChange((previous) => withValidation(previous, patch))
|
|
56
116
|
|
|
@@ -65,24 +125,18 @@ function ValidationFields({ draft, onDraftChange, knownContextKeys, labels }: Fl
|
|
|
65
125
|
/>
|
|
66
126
|
{labels.minDateToday}
|
|
67
127
|
</label>
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
className={`w-full mt-1 ${PANEL_FIELD_CLASSNAME}`}
|
|
75
|
-
/>
|
|
76
|
-
<datalist id="runner-context-keys">
|
|
77
|
-
{knownContextKeys.map((key) => (
|
|
78
|
-
<option key={key} value={key} />
|
|
79
|
-
))}
|
|
80
|
-
</datalist>
|
|
81
|
-
</div>
|
|
128
|
+
<ContextKeyField
|
|
129
|
+
label={labels.afterContextKey}
|
|
130
|
+
value={validation.afterContextKey}
|
|
131
|
+
knownContextKeys={knownContextKeys}
|
|
132
|
+
onValueChange={(afterContextKey) => update({ afterContextKey })}
|
|
133
|
+
/>
|
|
82
134
|
</div>
|
|
83
135
|
)
|
|
84
136
|
}
|
|
85
137
|
|
|
138
|
+
if (draft.questionType === 'time') return <TimeValidationFields {...props} />
|
|
139
|
+
|
|
86
140
|
if (draft.questionType === 'int' || draft.questionType === 'money') {
|
|
87
141
|
return (
|
|
88
142
|
<div className="flex gap-2">
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
slugifyNodeId,
|
|
21
21
|
targetsOf,
|
|
22
22
|
keywordHandle,
|
|
23
|
+
possibleNextHandle,
|
|
23
24
|
type FlowGraphData,
|
|
24
25
|
type FlowNodeData,
|
|
25
26
|
} from './flowGraph'
|
|
@@ -207,7 +208,7 @@ export function buildFlowEdges(params: {
|
|
|
207
208
|
for (const [nodeId, node] of Object.entries(graph.nodes)) {
|
|
208
209
|
const live = (liveCounts[nodeId] ?? 0) > 0
|
|
209
210
|
|
|
210
|
-
for (const { target, optionId: answerId, keyword, isDefault } of targetsOf(node)) {
|
|
211
|
+
for (const { target, optionId: answerId, keyword, isDefault, isPossible } of targetsOf(node)) {
|
|
211
212
|
const optionId = keyword !== undefined ? keywordHandle(keyword) : answerId
|
|
212
213
|
// Destino vazio é estado NORMAL, não anomalia: apagar um nó zera quem apontava para ele, e
|
|
213
214
|
// `targetsOf` devolve o `default` mesmo em branco. Emitir a aresta criaria ligação para um nó
|
|
@@ -238,6 +239,20 @@ export function buildFlowEdges(params: {
|
|
|
238
239
|
// repetição na linha de saída, dentro do card (ver `FlowNodeCard`).
|
|
239
240
|
if (source === edgeTarget) continue
|
|
240
241
|
|
|
242
|
+
// Caminho que a action PODE escolher: tracejado como o fallback, nunca animado.
|
|
243
|
+
if (isPossible) {
|
|
244
|
+
edges.push({
|
|
245
|
+
id: `${source}->${edgeTarget}-possible`,
|
|
246
|
+
source,
|
|
247
|
+
target: edgeTarget,
|
|
248
|
+
sourceHandle: possibleNextHandle(target),
|
|
249
|
+
kind: 'fallback',
|
|
250
|
+
crossFlow,
|
|
251
|
+
live: false,
|
|
252
|
+
})
|
|
253
|
+
continue
|
|
254
|
+
}
|
|
255
|
+
|
|
241
256
|
if (isDefault) {
|
|
242
257
|
edges.push({
|
|
243
258
|
id: `${source}->${edgeTarget}-default`,
|
|
@@ -17,7 +17,7 @@ import type { FlowGraphData, FlowNodeData, FlowNodeNext } from '@adatechnology/m
|
|
|
17
17
|
|
|
18
18
|
// A constante vem do `flowGraph`, que já a define, e não do contracts: duas fontes do mesmo prefixo
|
|
19
19
|
// divergem em silêncio, e o sintoma seria salto entre fluxos que o motor do bot não reconhece.
|
|
20
|
-
import { CROSS_FLOW_PREFIX, crossFlowTargetsOf, keywordOfHandle } from './flowGraph'
|
|
20
|
+
import { CROSS_FLOW_PREFIX, crossFlowTargetsOf, keywordOfHandle, possibleNextOfHandle } from './flowGraph'
|
|
21
21
|
|
|
22
22
|
const NAMESPACE_SEPARATOR = '::'
|
|
23
23
|
|
|
@@ -50,7 +50,10 @@ export function removeNodeAndCleanRefs(
|
|
|
50
50
|
|
|
51
51
|
for (const [id, node] of Object.entries(nodes)) {
|
|
52
52
|
if (id === removedId) continue
|
|
53
|
-
|
|
53
|
+
const cleaned: FlowNodeData = { ...node, next: cleanNext(node.next, removedId) }
|
|
54
|
+
// Destino possível não é linha visível de opção: some junto com o nó apagado.
|
|
55
|
+
if (node.possibleNext) cleaned.possibleNext = node.possibleNext.filter((target) => target !== removedId)
|
|
56
|
+
remaining[id] = cleaned
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
return remaining
|
|
@@ -151,6 +154,9 @@ export function applyConnection(node: FlowNodeData, resolved: ResolvedConnection
|
|
|
151
154
|
|
|
152
155
|
if (resolved.handle === 'next') return { ...node, next: resolved.targetValue }
|
|
153
156
|
|
|
157
|
+
const possible = possibleNextOfHandle(resolved.handle)
|
|
158
|
+
if (possible !== undefined) return withPossibleNext(node, possible, resolved.targetValue)
|
|
159
|
+
|
|
154
160
|
if (resolved.handle === '__default') {
|
|
155
161
|
return { ...node, next: { ...currentNext, byAnswer: currentNext?.byAnswer ?? {}, default: resolved.targetValue } }
|
|
156
162
|
}
|
|
@@ -197,7 +203,18 @@ export function isGraphDirty(working: FlowGraphData | undefined, published: Flow
|
|
|
197
203
|
* opção sem `byAnswer` some do card — e some junto o botão que o cliente via no WhatsApp, o que se
|
|
198
204
|
* lê como "o editor apagou minha opção". Vazio mantém a linha visível, cobrando a religação.
|
|
199
205
|
*/
|
|
206
|
+
function withPossibleNext(node: FlowNodeData, replaced: string, target: string | undefined): FlowNodeData {
|
|
207
|
+
const current = node.possibleNext ?? []
|
|
208
|
+
const updated = current.flatMap((entry) => (entry === replaced ? (target ? [target] : []) : [entry]))
|
|
209
|
+
if (!current.includes(replaced) && target) updated.push(target)
|
|
210
|
+
return { ...node, possibleNext: [...new Set(updated)] }
|
|
211
|
+
}
|
|
212
|
+
|
|
200
213
|
export function clearConnection(node: FlowNodeData, handle: string): FlowNodeData {
|
|
214
|
+
// Destino possível sem alvo não tem o que mostrar: desligar é tirá-lo da lista.
|
|
215
|
+
const possible = possibleNextOfHandle(handle)
|
|
216
|
+
if (possible !== undefined) return withPossibleNext(node, possible, undefined)
|
|
217
|
+
|
|
201
218
|
if (handle === 'next' || typeof node.next === 'string' || node.next === undefined) {
|
|
202
219
|
return { ...node, next: '' }
|
|
203
220
|
}
|
package/src/flows/flowGraph.ts
CHANGED
|
@@ -68,6 +68,16 @@ export function keywordOfHandle(handle: string): string | undefined {
|
|
|
68
68
|
return handle.startsWith(KEYWORD_HANDLE_PREFIX) ? handle.slice(KEYWORD_HANDLE_PREFIX.length) : undefined
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Handle do card para um destino de `possibleNext` — `maybe:<destino>`. A action escolhe o caminho em
|
|
73
|
+
* tempo de execução (o `next` que o handler devolve); o editor só desenha o que o nó declara.
|
|
74
|
+
*/
|
|
75
|
+
export const POSSIBLE_NEXT_HANDLE_PREFIX = 'maybe:'
|
|
76
|
+
export const possibleNextHandle = (target: string): string => `${POSSIBLE_NEXT_HANDLE_PREFIX}${target}`
|
|
77
|
+
export function possibleNextOfHandle(handle: string): string | undefined {
|
|
78
|
+
return handle.startsWith(POSSIBLE_NEXT_HANDLE_PREFIX) ? handle.slice(POSSIBLE_NEXT_HANDLE_PREFIX.length) : undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
export const CROSS_FLOW_PREFIX = 'flow:'
|
|
72
82
|
export const isCrossFlowTarget = (target: string): boolean => target.startsWith(CROSS_FLOW_PREFIX)
|
|
73
83
|
export const crossFlowKey = (target: string): string => target.slice(CROSS_FLOW_PREFIX.length)
|
|
@@ -84,10 +94,9 @@ export function estimateNodeHeight(node: FlowNodeData): number {
|
|
|
84
94
|
const ROW_HEIGHT = 34
|
|
85
95
|
const rowCount =
|
|
86
96
|
node.type === 'action'
|
|
87
|
-
? // Ação de passagem desenha uma linha de saída; terminal não desenha nenhuma.
|
|
88
|
-
|
|
89
|
-
? 1
|
|
90
|
-
: 0
|
|
97
|
+
? // Ação de passagem desenha uma linha de saída; terminal não desenha nenhuma. Cada destino
|
|
98
|
+
// declarado em `possibleNext` é mais uma linha.
|
|
99
|
+
(isPassThroughAction(node) ? 1 : 0) + (node.possibleNext?.length ?? 0)
|
|
91
100
|
: node.type === 'condition'
|
|
92
101
|
? 2
|
|
93
102
|
: node.type === 'menu' || node.questionType === 'choice'
|
|
@@ -134,9 +143,16 @@ export function rendersAsButtons(
|
|
|
134
143
|
return !hasDetails && (options?.length ?? 0) <= WHATSAPP_LIMITS.MAX_BUTTONS
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
146
|
+
export type FlowNodeTarget = {
|
|
147
|
+
target: string
|
|
148
|
+
optionId?: string
|
|
149
|
+
keyword?: string
|
|
150
|
+
isDefault?: boolean
|
|
151
|
+
/** Destino de `possibleNext`: a action pode escolher, não é garantido. */
|
|
152
|
+
isPossible?: boolean
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function nextTargetsOf(node: FlowNodeData): FlowNodeTarget[] {
|
|
140
156
|
if (!node.next) return []
|
|
141
157
|
if (typeof node.next === 'string') return [{ target: node.next }]
|
|
142
158
|
return [
|
|
@@ -146,6 +162,11 @@ export function targetsOf(
|
|
|
146
162
|
]
|
|
147
163
|
}
|
|
148
164
|
|
|
165
|
+
export function targetsOf(node: FlowNodeData): FlowNodeTarget[] {
|
|
166
|
+
const possible = (node.possibleNext ?? []).map((target) => ({ target, isPossible: true }))
|
|
167
|
+
return [...nextTargetsOf(node), ...possible]
|
|
168
|
+
}
|
|
169
|
+
|
|
149
170
|
export type GraphIssue = {
|
|
150
171
|
severity: 'error' | 'warning'
|
|
151
172
|
nodeId?: string
|
|
@@ -174,6 +195,7 @@ export function validateGraph(
|
|
|
174
195
|
descriptionTooLong?: (id: string, label: string) => string
|
|
175
196
|
dynamicChoiceWithoutProvider?: (id: string) => string
|
|
176
197
|
choiceDefaultIgnored?: (id: string) => string
|
|
198
|
+
possibleNextIgnored?: (id: string) => string
|
|
177
199
|
},
|
|
178
200
|
): GraphIssue[] {
|
|
179
201
|
const issues: GraphIssue[] = []
|
|
@@ -236,6 +258,14 @@ export function validateGraph(
|
|
|
236
258
|
}
|
|
237
259
|
}
|
|
238
260
|
|
|
261
|
+
// Só a action devolve `next` em tempo de execução: em outro nó a lista desenharia caminho que não existe.
|
|
262
|
+
if ((node.possibleNext?.length ?? 0) > 0 && (node.type !== 'action' || !node.actionKind)) {
|
|
263
|
+
const message =
|
|
264
|
+
issueText.possibleNextIgnored?.(node.id) ??
|
|
265
|
+
`${node.id}: "destinos que a ação pode escolher" só valem em nó de ação com tipo de ação.`
|
|
266
|
+
issues.push({ severity: 'warning', nodeId: node.id, message })
|
|
267
|
+
}
|
|
268
|
+
|
|
239
269
|
if (node.type === 'dynamic_choice' && !node.choiceProvider) {
|
|
240
270
|
const message =
|
|
241
271
|
issueText.dynamicChoiceWithoutProvider?.(node.id) ?? `${node.id}: escolha dinâmica sem provedor de opções.`
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
3
|
+
*
|
|
4
|
+
* `possibleNext`: destinos que a action pode devolver em tempo de execução. O editor desenha, valida
|
|
5
|
+
* e limpa esses caminhos como qualquer outro, sem mudar o `next` do nó.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from 'bun:test'
|
|
9
|
+
import { buildFlowEdges } from './flowCanvasModel'
|
|
10
|
+
import { applyConnection, clearConnection, removeNodeAndCleanRefs, resolveConnection } from './flowEditorOps'
|
|
11
|
+
import { estimateNodeHeight, possibleNextHandle, validateGraph, type FlowGraphData } from './flowGraph'
|
|
12
|
+
import { DEFAULT_FLOW_EDITOR_LABELS } from './labels'
|
|
13
|
+
|
|
14
|
+
function bookingGraph(): FlowGraphData {
|
|
15
|
+
return {
|
|
16
|
+
key: 'main',
|
|
17
|
+
label: 'Main',
|
|
18
|
+
startNodeId: 'check',
|
|
19
|
+
version: 1,
|
|
20
|
+
nodes: {
|
|
21
|
+
check: { id: 'check', type: 'action', actionKind: 'check_slot', possibleNext: ['full'], next: 'confirm' },
|
|
22
|
+
confirm: { id: 'confirm', type: 'action', directMessage: 'Reservado!' },
|
|
23
|
+
full: { id: 'full', type: 'action', directMessage: 'Lotado.' },
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('possibleNext in the flow editor', () => {
|
|
29
|
+
it('draws a dashed edge from its own handle and keeps the target reachable', () => {
|
|
30
|
+
const graph = bookingGraph()
|
|
31
|
+
const edges = buildFlowEdges({ openKeys: ['main'], graphs: { main: graph }, rootFlowKey: 'main' })
|
|
32
|
+
expect(edges).toContainEqual(
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
source: 'main::check',
|
|
35
|
+
target: 'main::full',
|
|
36
|
+
sourceHandle: possibleNextHandle('full'),
|
|
37
|
+
kind: 'fallback',
|
|
38
|
+
live: false,
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
const messages = validateGraph(graph, DEFAULT_FLOW_EDITOR_LABELS.validation).map((issue) => issue.message)
|
|
42
|
+
expect(messages.filter((message) => message.includes('full'))).toEqual([])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('flags a broken possible target and possibleNext on a node that cannot branch', () => {
|
|
46
|
+
const graph = bookingGraph()
|
|
47
|
+
graph.nodes.check = { ...graph.nodes.check!, possibleNext: ['ghost'] }
|
|
48
|
+
graph.nodes.confirm = { ...graph.nodes.confirm!, possibleNext: ['full'] }
|
|
49
|
+
const issues = validateGraph(graph, DEFAULT_FLOW_EDITOR_LABELS.validation)
|
|
50
|
+
expect(issues.some((issue) => issue.severity === 'error' && issue.message.includes('ghost'))).toBe(true)
|
|
51
|
+
expect(issues.some((issue) => issue.severity === 'warning' && issue.nodeId === 'confirm')).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('reconnects, disconnects and cleans possible targets without touching next', () => {
|
|
55
|
+
const graphs = { main: bookingGraph() }
|
|
56
|
+
const check = graphs.main.nodes.check!
|
|
57
|
+
const resolved = resolveConnection({
|
|
58
|
+
connection: { source: 'main::check', target: 'main::confirm', sourceHandle: possibleNextHandle('full') },
|
|
59
|
+
graphs,
|
|
60
|
+
})
|
|
61
|
+
expect(resolved && applyConnection(check, resolved)).toMatchObject({ possibleNext: ['confirm'], next: 'confirm' })
|
|
62
|
+
expect(clearConnection(check, possibleNextHandle('full'))).toMatchObject({ possibleNext: [], next: 'confirm' })
|
|
63
|
+
expect(removeNodeAndCleanRefs(graphs.main.nodes, 'full').check).toMatchObject({ possibleNext: [], next: 'confirm' })
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('makes the card taller by one row per possible target', () => {
|
|
67
|
+
const check = bookingGraph().nodes.check!
|
|
68
|
+
expect(estimateNodeHeight(check)).toBeGreaterThan(estimateNodeHeight({ ...check, possibleNext: undefined }))
|
|
69
|
+
})
|
|
70
|
+
})
|
package/src/flows/labels.ts
CHANGED
|
@@ -9,6 +9,16 @@ export interface FlowRunnerFieldLabels {
|
|
|
9
9
|
maxInvalidAnswersHint: string
|
|
10
10
|
minDateToday: string
|
|
11
11
|
afterContextKey: string
|
|
12
|
+
// Opcionais para não quebrar quem monta os textos à mão; ausentes, vale o padrão.
|
|
13
|
+
minTime?: string
|
|
14
|
+
maxTime?: string
|
|
15
|
+
timeWindowsContextKey?: string
|
|
16
|
+
timeWindowsContextKeyHint?: string
|
|
17
|
+
possibleNext?: string
|
|
18
|
+
possibleNextHint?: string
|
|
19
|
+
addPossibleNext?: string
|
|
20
|
+
removePossibleNext?: string
|
|
21
|
+
possibleNextRowLabel?: string
|
|
12
22
|
minValue: string
|
|
13
23
|
maxValue: string
|
|
14
24
|
minLength: string
|
|
@@ -50,7 +60,8 @@ export interface FlowEditorLabels {
|
|
|
50
60
|
// (ex.: 'trigger_simulation') em vez do pacote assumir algum como padrão.
|
|
51
61
|
actionKindLabels: Record<string, string>
|
|
52
62
|
conditionOperatorLabels: Record<FlowConditionOperator, string>
|
|
53
|
-
|
|
63
|
+
/** `time` opcional: quem já passava a lista inteira continua compilando; ausente, vale o padrão. */
|
|
64
|
+
questionTypeLabels: Record<Exclude<FlowQuestionType, 'time'>, string> & { time?: string }
|
|
54
65
|
/** Opcional para não quebrar quem monta os textos à mão; ausente, vale o padrão pt-BR. */
|
|
55
66
|
runnerFields?: FlowRunnerFieldLabels
|
|
56
67
|
nodePanel: {
|
|
@@ -205,6 +216,20 @@ export interface FlowValidationLabels {
|
|
|
205
216
|
choiceDefaultIgnored?: (id: string) => string
|
|
206
217
|
}
|
|
207
218
|
|
|
219
|
+
/** Padrões dos rótulos opcionais de `FlowRunnerFieldLabels` — o componente cai neles quando o host não passa. */
|
|
220
|
+
export const OPTIONAL_RUNNER_FIELD_LABEL_DEFAULTS = {
|
|
221
|
+
minTime: 'A partir de',
|
|
222
|
+
maxTime: 'Até',
|
|
223
|
+
timeWindowsContextKey: 'Faixas permitidas guardadas em',
|
|
224
|
+
timeWindowsContextKeyHint:
|
|
225
|
+
'Chave do contexto com as faixas (ex.: ["11:00-14:00"]), preenchida pelo sistema antes da pergunta.',
|
|
226
|
+
possibleNext: 'Destinos que a ação pode escolher',
|
|
227
|
+
possibleNextHint: 'A ação decide o caminho na hora. Liste aqui os destinos possíveis para eles aparecerem no mapa.',
|
|
228
|
+
addPossibleNext: 'Adicionar destino',
|
|
229
|
+
removePossibleNext: 'Remover destino',
|
|
230
|
+
possibleNextRowLabel: 'Pode seguir para',
|
|
231
|
+
} as const satisfies Partial<FlowRunnerFieldLabels>
|
|
232
|
+
|
|
208
233
|
export const DEFAULT_FLOW_RUNNER_FIELD_LABELS: FlowRunnerFieldLabels = {
|
|
209
234
|
section: 'Resposta do cliente',
|
|
210
235
|
fallbackMessage: 'Mensagem quando a resposta não serve',
|
|
@@ -213,6 +238,7 @@ export const DEFAULT_FLOW_RUNNER_FIELD_LABELS: FlowRunnerFieldLabels = {
|
|
|
213
238
|
maxInvalidAnswersHint: 'Vazio = padrão do bot (2).',
|
|
214
239
|
minDateToday: 'Só aceitar de hoje em diante',
|
|
215
240
|
afterContextKey: 'Depois da data guardada em',
|
|
241
|
+
...OPTIONAL_RUNNER_FIELD_LABEL_DEFAULTS,
|
|
216
242
|
minValue: 'Mínimo',
|
|
217
243
|
maxValue: 'Máximo',
|
|
218
244
|
minLength: 'Mínimo de caracteres',
|
|
@@ -274,6 +300,7 @@ export const DEFAULT_FLOW_EDITOR_LABELS: FlowEditorLabels = {
|
|
|
274
300
|
text: 'Texto livre',
|
|
275
301
|
money: 'Valor em R$',
|
|
276
302
|
date: 'Data',
|
|
303
|
+
time: 'Horário',
|
|
277
304
|
int: 'Número inteiro',
|
|
278
305
|
cpf: 'CPF',
|
|
279
306
|
choice: 'Escolha (botões/lista)',
|
package/src/index.ts
CHANGED
|
@@ -181,7 +181,7 @@ export { parseWhatsAppFormatting, waToHTML, htmlToWA, waToHTMLInline } from './l
|
|
|
181
181
|
export { WhatsAppMessagePreview } from './lib/WhatsAppMessagePreview'
|
|
182
182
|
export type { WhatsAppMessagePreviewProps } from './lib/WhatsAppMessagePreview'
|
|
183
183
|
export { WHATSAPP_MARKER_BY_ACTION } from './lib/composer-formatting'
|
|
184
|
-
export { formatPhone, phoneInitials } from './lib/phone'
|
|
184
|
+
export { formatPhone, phoneInitials, isTestContactNumber, TEST_CONTACT_LABEL } from './lib/phone'
|
|
185
185
|
// `formatDateTime` e `isSameDay` já eram usados pelas bolhas e pelo divisor de data; exportá-los
|
|
186
186
|
// evita que cada host mantenha a própria cópia e acabe com timeline e transcript divergindo.
|
|
187
187
|
export { formatTimestamp, formatFileSize, formatDateTime, isSameDay } from './lib/format'
|
|
@@ -299,6 +299,7 @@ export type {
|
|
|
299
299
|
ConversationsWorkspaceSimulator,
|
|
300
300
|
SimulatorTransportFactory,
|
|
301
301
|
SimulatorTransportParams,
|
|
302
|
+
SimulatorTestContact,
|
|
302
303
|
ConversationsWorkspaceLabels,
|
|
303
304
|
ConversationPaneProps,
|
|
304
305
|
ConversationsInboxListProps,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { formatPhone, isTestContactNumber, phoneCountryFlag } from './phone'
|
|
4
|
+
|
|
5
|
+
describe('número de teste do simulador', () => {
|
|
6
|
+
it('começando com 0 não vira telefone mascarado nem ganha bandeira', () => {
|
|
7
|
+
expect(isTestContactNumber('05511900001234')).toBe(true)
|
|
8
|
+
expect(formatPhone('05511900001234')).toBe('Contato de teste 1234')
|
|
9
|
+
expect(phoneCountryFlag('05511900001234')).toBe('')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('telefone real continua formatado', () => {
|
|
13
|
+
expect(isTestContactNumber('5511900001234')).toBe(false)
|
|
14
|
+
expect(formatPhone('5511900001234')).toBe('+55 (11) 90000-1234')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('id opaco com letras não é confundido com número de teste', () => {
|
|
18
|
+
expect(isTestContactNumber('0a1b2c3d-uuid')).toBe(false)
|
|
19
|
+
})
|
|
20
|
+
})
|
package/src/lib/phone.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
/** Rótulo do número de teste do simulador, no lugar de uma máscara de telefone que não existe. */
|
|
2
|
+
export const TEST_CONTACT_LABEL = 'Contato de teste'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Nenhum código de país começa com 0, então um número só de dígitos começando com 0 não é telefone
|
|
6
|
+
* de verdade: é o contato de teste do simulador. Formatá-lo como telefone inventa um DDD.
|
|
7
|
+
*/
|
|
8
|
+
export function isTestContactNumber(number: string): boolean {
|
|
9
|
+
return /^0\d{3,}$/.test(number.replace(/[\s()+-]/g, ''))
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
export function formatPhone(number: string): string {
|
|
2
13
|
const digits = number.replace(/\D/g, '')
|
|
3
14
|
|
|
15
|
+
if (isTestContactNumber(number)) return `${TEST_CONTACT_LABEL} ${digits.slice(-4)}`
|
|
16
|
+
|
|
4
17
|
if (digits.length === 13) {
|
|
5
18
|
return `+${digits.slice(0, 2)} (${digits.slice(2, 4)}) ${digits.slice(4, 9)}-${digits.slice(9, 13)}`
|
|
6
19
|
}
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
9
9
|
|
|
10
10
|
import { AudioRecorderButton } from '../AudioRecorderButton'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
ConversationContextPanel,
|
|
13
|
+
type ConversationContextEntry,
|
|
14
|
+
type ConversationContextPanelLabels,
|
|
15
|
+
} from '../ConversationContextPanel'
|
|
12
16
|
import { ConversationDocumentsPanel } from '../ConversationDocumentsPanel'
|
|
13
17
|
import { ConversationHeader, type ConversationHeaderUtility } from '../ConversationHeader'
|
|
14
18
|
import { ConversationWallpaper } from '../Wallpaper'
|
|
@@ -50,6 +54,8 @@ export interface ConversationPaneProps {
|
|
|
50
54
|
readonly extraUtilities?: readonly ConversationHeaderUtility[]
|
|
51
55
|
/** Traduz o contexto cru do produto nas linhas do painel. Ausente, o painel não aparece. */
|
|
52
56
|
readonly contextEntriesOf?: (context: Record<string, unknown> | undefined) => readonly ConversationContextEntry[]
|
|
57
|
+
/** Vocabulário do painel de contexto (`title`, `empty`, `notCollected`...). */
|
|
58
|
+
readonly contextLabels?: Partial<ConversationContextPanelLabels>
|
|
53
59
|
readonly quickReplies?: readonly QuickReply[]
|
|
54
60
|
/**
|
|
55
61
|
* Recebe o contexto junto porque o dado que interessa à variável (o nome que o bot perguntou,
|
|
@@ -131,6 +137,7 @@ export function ConversationPane({
|
|
|
131
137
|
onBack,
|
|
132
138
|
extraUtilities,
|
|
133
139
|
contextEntriesOf,
|
|
140
|
+
contextLabels,
|
|
134
141
|
quickReplies,
|
|
135
142
|
quickReplyVariablesFor,
|
|
136
143
|
flowLabel,
|
|
@@ -355,7 +362,11 @@ export function ConversationPane({
|
|
|
355
362
|
/>
|
|
356
363
|
|
|
357
364
|
{(contextEntries && contextEntries.length > 0) || flowLabel ? (
|
|
358
|
-
<ConversationContextPanel
|
|
365
|
+
<ConversationContextPanel
|
|
366
|
+
entries={contextEntries ?? []}
|
|
367
|
+
{...(flowLabel ? { flowLabel } : {})}
|
|
368
|
+
{...(contextLabels ? { labels: contextLabels } : {})}
|
|
369
|
+
/>
|
|
359
370
|
) : null}
|
|
360
371
|
<ConversationDocumentsPanel conversationId={conversation.id} open={documentsOpen} />
|
|
361
372
|
|