@adatechnology/conversations-ui 0.15.1 → 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/{ConversationSimulatorPanel-P6eqTSAO.d.ts → ConversationSimulatorPanel-DSVIch04.d.ts} +3 -1
- 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 +90 -7
- package/dist/flows/index.js +1151 -455
- package/dist/index.d.ts +36 -5
- package/dist/index.js +88 -23
- package/dist/participant/index.js +1 -1
- package/dist/preview/index.d.ts +13 -29
- package/dist/preview/index.js +2 -2
- package/package.json +2 -2
- package/src/flows/FlowKeywordRoutesField.tsx +105 -0
- package/src/flows/FlowLegend.tsx +2 -2
- package/src/flows/FlowNodeCard.tsx +39 -10
- package/src/flows/FlowNodePanel.tsx +34 -10
- package/src/flows/FlowPalette.tsx +25 -2
- package/src/flows/FlowPossibleNextField.tsx +89 -0
- package/src/flows/FlowRunnerFields.tsx +321 -0
- package/src/flows/FlowWhatsAppPreview.tsx +39 -6
- package/src/flows/flowCanvasModel.test.ts +3 -2
- package/src/flows/flowCanvasModel.ts +28 -1
- package/src/flows/flowEditorOps.ts +41 -4
- package/src/flows/flowGraph.ts +124 -21
- package/src/flows/flowPanelStyles.ts +11 -0
- package/src/flows/flowPossibleNext.test.ts +70 -0
- package/src/flows/flowRunnerEditor.test.ts +116 -0
- package/src/flows/labels.ts +116 -2
- package/src/index.ts +2 -1
- package/src/lib/phone.test.ts +20 -0
- package/src/lib/phone.ts +13 -0
- package/src/preview/createPreviewBridgeClient.test.ts +23 -0
- package/src/preview/createPreviewBridgeClient.ts +13 -8
- package/src/preview/createPreviewWebhookClient.ts +2 -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
package/README.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
Telas de conversa parametrizáveis por endpoint, tema e capacidades. Subpaths: `.` (inbox/mensagens),
|
|
4
4
|
`/flows`, `/whatsapp`, `/preview`, `/participant` e `/styles.css`.
|
|
5
5
|
|
|
6
|
+
## Workspace: simulador e painel de contexto
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
<ConversationsWorkspace
|
|
10
|
+
simulator={{
|
|
11
|
+
transports: { whatsapp: ({ conversationId, handle }) => createBridgeClient({ conversationId, handle }) },
|
|
12
|
+
// Liga "Novo contato de teste" no cabeçalho: abre o simulador sem conversa selecionada.
|
|
13
|
+
createTestContact: () => ({ handle: `0${Date.now()}` }),
|
|
14
|
+
}}
|
|
15
|
+
contextEntriesOf={(context) => toEntries(context)}
|
|
16
|
+
contextLabels={{ title: 'Dados da reserva', empty: 'Nada informado ainda.', notCollected: 'a informar' }}
|
|
17
|
+
/>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- **Novo contato de teste:** `createTestContact` devolve `{ handle, channel?, conversationId? }`. O painel
|
|
21
|
+
abre com o transporte do canal, sem conversa selecionada; quando a conversa do contato aparece na lista
|
|
22
|
+
(primeiro envio), ela é selecionada e o painel segue sobre ela. Sem a prop, o botão não existe.
|
|
23
|
+
- **Número de teste:** número só de dígitos começando com `0` (nenhum país usa) não é mascarado como
|
|
24
|
+
telefone: aparece como "Contato de teste 1234" na lista, no cabeçalho e no simulador
|
|
25
|
+
(`isTestContactNumber`, `TEST_CONTACT_LABEL`).
|
|
26
|
+
- **`contextLabels`** troca o vocabulário do painel de contexto embutido (`title`, `empty`,
|
|
27
|
+
`notCollected`, ...), sem precisar desenhar o resumo em `renderAboveTranscript`.
|
|
28
|
+
|
|
6
29
|
## Visão do participante (`/participant`)
|
|
7
30
|
|
|
8
31
|
Tela de conversa do lado de **quem conversa com a empresa** (app de campo, portal do cliente). Não usa
|
package/dist/{ConversationSimulatorPanel-P6eqTSAO.d.ts → ConversationSimulatorPanel-DSVIch04.d.ts}
RENAMED
|
@@ -435,7 +435,9 @@ type SendPreviewMediaParams = {
|
|
|
435
435
|
type CreatePreviewWebhookClientParams = {
|
|
436
436
|
readonly webhookUrl: string;
|
|
437
437
|
readonly appSecret: string;
|
|
438
|
+
/** Usado como veio. Para contato de simulador, ver `createPreviewBridgeClient` (`from` + `features.previewContacts`). */
|
|
438
439
|
readonly from: string;
|
|
440
|
+
/** O `phone_number_id` do host. Sem ele o webhook descarta a entrega no filtro de número. */
|
|
439
441
|
readonly phoneNumberId?: string;
|
|
440
442
|
/**
|
|
441
443
|
* Rota que guarda o áudio gravado. Por padrão, `/v1/preview/media` na mesma origem do webhook.
|
|
@@ -636,4 +638,4 @@ type ConversationSimulatorPanelProps = Omit<ConversationPreviewProps, 'placehold
|
|
|
636
638
|
};
|
|
637
639
|
declare function ConversationSimulatorPanel({ onClose, channel, displayHandle, displayNumber, labels, headerActions, ...previewProps }: ConversationSimulatorPanelProps): react.JSX.Element;
|
|
638
640
|
|
|
639
|
-
export { AudioRecorderButton as A, acceptsMediaKind as B, type ConversationSummary as C, DEFAULT_AUDIO_RECORDER_BUTTON_LABELS as D, assertPreviewEnvironment as E, createPreviewMediaPoster as F, createPreviewMediaUploader as G, createPreviewWebhookClient as H, isConversationSimulatorClient as I, mediaKindOf as J, mediaTypeOf as K, type ListConversationsParams as L, signPreviewPayload as M, simulatorPanelLabelsOf as N, toConversationSimulatorClient as O, type PreviewUploadedMedia$1 as P, type ListDocumentsParams as Q, type ResolveMediaUrl as R, type SSEProvider as S, type ToSimulatorClientParams as T, type ConversationTemplate as U, type CompanyDocument as V, type CompanyDocumentPage as W, type ConversationDocumentPage as X, MediaRenderer as Y, type MediaRendererProps as Z, type ConversationEventSource as a, type ConversationsApi as b, type ConversationPage as c, type ConversationDocument as d, type
|
|
641
|
+
export { AudioRecorderButton as A, acceptsMediaKind as B, type ConversationSummary as C, DEFAULT_AUDIO_RECORDER_BUTTON_LABELS as D, assertPreviewEnvironment as E, createPreviewMediaPoster as F, createPreviewMediaUploader as G, createPreviewWebhookClient as H, isConversationSimulatorClient as I, mediaKindOf as J, mediaTypeOf as K, type ListConversationsParams as L, signPreviewPayload as M, simulatorPanelLabelsOf as N, toConversationSimulatorClient as O, type PreviewUploadedMedia$1 as P, type ListDocumentsParams as Q, type ResolveMediaUrl as R, type SSEProvider as S, type ToSimulatorClientParams as T, type ConversationTemplate as U, type CompanyDocument as V, type CompanyDocumentPage as W, type ConversationDocumentPage as X, MediaRenderer as Y, type MediaRendererProps as Z, type ConversationEventSource as a, type ConversationsApi as b, type ConversationPage as c, type ConversationDocument as d, type PreviewWebhookClient as e, type AudioRecorderButtonLabels as f, type AudioRecorderButtonProps as g, ConversationPreview as h, type ConversationPreviewProps as i, type ConversationSimulatorClient as j, ConversationSimulatorPanel as k, type ConversationSimulatorPanelLabels as l, type ConversationSimulatorPanelProps as m, type CreatePreviewMediaUploaderParams as n, type CreatePreviewWebhookClientParams as o, DEFAULT_CONVERSATION_SIMULATOR_PANEL_LABELS as p, DEFAULT_MEDIA_UPLOAD_PATH as q, PreviewInProductionError as r, PreviewMediaUploadRejectedError as s, type PreviewMediaUploadRequest as t, type PreviewUploadedMedia as u, PreviewWebhookRejectedError as v, SIMULATOR_FILE_MEDIA_KINDS as w, type SendPreviewMediaParams as x, type SendSimulatorMediaParams as y, type SimulatorMediaKind as z };
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// src/lib/phone.ts
|
|
2
|
+
var TEST_CONTACT_LABEL = "Contato de teste";
|
|
3
|
+
function isTestContactNumber(number) {
|
|
4
|
+
return /^0\d{3,}$/.test(number.replace(/[\s()+-]/g, ""));
|
|
5
|
+
}
|
|
2
6
|
function formatPhone(number) {
|
|
3
7
|
const digits = number.replace(/\D/g, "");
|
|
8
|
+
if (isTestContactNumber(number)) return `${TEST_CONTACT_LABEL} ${digits.slice(-4)}`;
|
|
4
9
|
if (digits.length === 13) {
|
|
5
10
|
return `+${digits.slice(0, 2)} (${digits.slice(2, 4)}) ${digits.slice(4, 9)}-${digits.slice(9, 13)}`;
|
|
6
11
|
}
|
|
@@ -247,6 +252,8 @@ function resolveRecordingFormat() {
|
|
|
247
252
|
}
|
|
248
253
|
|
|
249
254
|
export {
|
|
255
|
+
TEST_CONTACT_LABEL,
|
|
256
|
+
isTestContactNumber,
|
|
250
257
|
formatPhone,
|
|
251
258
|
phoneInitials,
|
|
252
259
|
CONVERSATION_CHANNEL,
|
package/dist/flows/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { NodeProps, EdgeProps } from '@xyflow/react';
|
|
4
4
|
import { LucideIcon } from 'lucide-react';
|
|
5
|
-
import { FlowConditionOperator, FlowGraphData, FlowNodeData, FlowNodeType, FlowQuestionType, FlowActionKind } from '@adatechnology/meta-whatsapp-contracts';
|
|
5
|
+
import { FlowConditionOperator, FlowGraphData, FlowNodeData, FlowOptionDetail, FlowNodeType, FlowQuestionType, FlowActionKind } from '@adatechnology/meta-whatsapp-contracts';
|
|
6
6
|
export { FlowActionKind, FlowConditionOperator, FlowGraphData, FlowNodeData, FlowNodeNext, FlowNodeType, FlowQuestionType } from '@adatechnology/meta-whatsapp-contracts';
|
|
7
7
|
|
|
8
8
|
declare const CONDITION_OPERATORS: FlowConditionOperator[];
|
|
@@ -26,19 +26,34 @@ declare const isCrossFlowTarget: (target: string) => boolean;
|
|
|
26
26
|
declare const crossFlowKey: (target: string) => string;
|
|
27
27
|
declare const NODE_CARD_WIDTH = 240;
|
|
28
28
|
declare function estimateNodeHeight(node: FlowNodeData): number;
|
|
29
|
+
/**
|
|
30
|
+
* Limites da Meta, lidos do contrato (`WHATSAPP_CHOICE_LIMIT`) — o mesmo número que o módulo usa
|
|
31
|
+
* para recusar a mensagem. Antes eram uma cópia local, e duas cópias divergem sem nada acusar.
|
|
32
|
+
* Nome mantido para não quebrar quem já importa.
|
|
33
|
+
*/
|
|
29
34
|
declare const WHATSAPP_LIMITS: {
|
|
30
35
|
readonly MAX_BUTTONS: 3;
|
|
31
36
|
readonly MAX_LIST_ROWS: 10;
|
|
32
37
|
readonly BUTTON_TITLE_MAX: 20;
|
|
33
38
|
readonly LIST_ROW_TITLE_MAX: 24;
|
|
39
|
+
readonly LIST_ROW_DESCRIPTION_MAX: 72;
|
|
40
|
+
readonly LIST_SECTION_TITLE_MAX: 24;
|
|
34
41
|
readonly BODY_MAX: 1024;
|
|
35
42
|
};
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Botão com até 3 opções simples; opção com descrição ou seção força lista — é a mesma regra do
|
|
45
|
+
* runner do módulo, para a prévia mostrar o que o cliente vai ver.
|
|
46
|
+
*/
|
|
47
|
+
declare function rendersAsButtons(options: [string, string][] | undefined, optionDetails?: Record<string, FlowOptionDetail>): boolean;
|
|
48
|
+
type FlowNodeTarget = {
|
|
38
49
|
target: string;
|
|
39
50
|
optionId?: string;
|
|
51
|
+
keyword?: string;
|
|
40
52
|
isDefault?: boolean;
|
|
41
|
-
|
|
53
|
+
/** Destino de `possibleNext`: a action pode escolher, não é garantido. */
|
|
54
|
+
isPossible?: boolean;
|
|
55
|
+
};
|
|
56
|
+
declare function targetsOf(node: FlowNodeData): FlowNodeTarget[];
|
|
42
57
|
type GraphIssue = {
|
|
43
58
|
severity: 'error' | 'warning';
|
|
44
59
|
nodeId?: string;
|
|
@@ -58,6 +73,10 @@ declare function validateGraph(graph: FlowGraphData, issueText: {
|
|
|
58
73
|
deadEndQuestion: (id: string) => string;
|
|
59
74
|
conditionIncomplete: (id: string) => string;
|
|
60
75
|
conditionBranchMissing: (id: string, branch: string) => string;
|
|
76
|
+
descriptionTooLong?: (id: string, label: string) => string;
|
|
77
|
+
dynamicChoiceWithoutProvider?: (id: string) => string;
|
|
78
|
+
choiceDefaultIgnored?: (id: string) => string;
|
|
79
|
+
possibleNextIgnored?: (id: string) => string;
|
|
61
80
|
}): GraphIssue[];
|
|
62
81
|
/**
|
|
63
82
|
* Auto-layout em cascata: avança para a direita a cada passo do fluxo e desce a cada card.
|
|
@@ -84,15 +103,70 @@ type CollectionChain = {
|
|
|
84
103
|
declare function findCollectionChains(graph: FlowGraphData): CollectionChain[];
|
|
85
104
|
declare function slugifyNodeId(label: string, existing: ReadonlySet<string>): string;
|
|
86
105
|
|
|
106
|
+
/** Campos do runner de fluxo do módulo (validação, palavras-chave, descrições, escolha dinâmica). */
|
|
107
|
+
interface FlowRunnerFieldLabels {
|
|
108
|
+
section: string;
|
|
109
|
+
fallbackMessage: string;
|
|
110
|
+
fallbackPlaceholder: string;
|
|
111
|
+
maxInvalidAnswers: string;
|
|
112
|
+
maxInvalidAnswersHint: string;
|
|
113
|
+
minDateToday: string;
|
|
114
|
+
afterContextKey: string;
|
|
115
|
+
minTime?: string;
|
|
116
|
+
maxTime?: string;
|
|
117
|
+
timeWindowsContextKey?: string;
|
|
118
|
+
timeWindowsContextKeyHint?: string;
|
|
119
|
+
possibleNext?: string;
|
|
120
|
+
possibleNextHint?: string;
|
|
121
|
+
addPossibleNext?: string;
|
|
122
|
+
removePossibleNext?: string;
|
|
123
|
+
possibleNextRowLabel?: string;
|
|
124
|
+
minValue: string;
|
|
125
|
+
maxValue: string;
|
|
126
|
+
minLength: string;
|
|
127
|
+
maxLength: string;
|
|
128
|
+
skipKeywords: string;
|
|
129
|
+
skipKeywordsHint: string;
|
|
130
|
+
keywordRoutes: string;
|
|
131
|
+
keywordRoutesHint: string;
|
|
132
|
+
addKeywordRoute: string;
|
|
133
|
+
removeKeywordRoute: string;
|
|
134
|
+
keywordPlaceholder: string;
|
|
135
|
+
optionDescription: string;
|
|
136
|
+
optionSection: string;
|
|
137
|
+
listButtonLabel: string;
|
|
138
|
+
unmatchedChoice: string;
|
|
139
|
+
unmatchedChoiceReask: string;
|
|
140
|
+
unmatchedChoiceDefault: string;
|
|
141
|
+
choiceProvider: string;
|
|
142
|
+
choiceProviderHint: string;
|
|
143
|
+
contextKey: string;
|
|
144
|
+
placeholdersHint: string;
|
|
145
|
+
paletteDynamicChoice: string;
|
|
146
|
+
paletteDynamicChoiceHint: string;
|
|
147
|
+
paletteMessage: string;
|
|
148
|
+
paletteMessageHint: string;
|
|
149
|
+
}
|
|
87
150
|
interface FlowEditorLabels {
|
|
88
|
-
|
|
151
|
+
/**
|
|
152
|
+
* `dynamic_choice` é opcional para não quebrar quem já monta a legenda inteira à mão; ausente, vale
|
|
153
|
+
* o texto padrão.
|
|
154
|
+
*/
|
|
155
|
+
legend: Record<Exclude<FlowNodeType, 'dynamic_choice'>, string> & {
|
|
156
|
+
dynamic_choice?: string;
|
|
157
|
+
};
|
|
89
158
|
startNodeTooltip: string;
|
|
90
159
|
detachedNodeTooltip: string;
|
|
91
160
|
liveCountTooltip: (count: number) => string;
|
|
92
161
|
edgeFallbackLabel: string;
|
|
93
162
|
actionKindLabels: Record<string, string>;
|
|
94
163
|
conditionOperatorLabels: Record<FlowConditionOperator, string>;
|
|
95
|
-
|
|
164
|
+
/** `time` opcional: quem já passava a lista inteira continua compilando; ausente, vale o padrão. */
|
|
165
|
+
questionTypeLabels: Record<Exclude<FlowQuestionType, 'time'>, string> & {
|
|
166
|
+
time?: string;
|
|
167
|
+
};
|
|
168
|
+
/** Opcional para não quebrar quem monta os textos à mão; ausente, vale o padrão pt-BR. */
|
|
169
|
+
runnerFields?: FlowRunnerFieldLabels;
|
|
96
170
|
nodePanel: {
|
|
97
171
|
title: string;
|
|
98
172
|
contextKey: string;
|
|
@@ -239,6 +313,9 @@ interface FlowValidationLabels {
|
|
|
239
313
|
deadEndQuestion: (id: string) => string;
|
|
240
314
|
conditionIncomplete: (id: string) => string;
|
|
241
315
|
conditionBranchMissing: (id: string, branch: string) => string;
|
|
316
|
+
descriptionTooLong?: (id: string, label: string) => string;
|
|
317
|
+
dynamicChoiceWithoutProvider?: (id: string) => string;
|
|
318
|
+
choiceDefaultIgnored?: (id: string) => string;
|
|
242
319
|
}
|
|
243
320
|
declare const DEFAULT_FLOW_EDITOR_LABELS: FlowEditorLabels;
|
|
244
321
|
declare function mergeFlowEditorLabels(override?: Partial<FlowEditorLabels>): FlowEditorLabels;
|
|
@@ -333,6 +410,10 @@ type NewNodeSpec = {
|
|
|
333
410
|
kind: 'decision';
|
|
334
411
|
} | {
|
|
335
412
|
kind: 'condition';
|
|
413
|
+
} | {
|
|
414
|
+
kind: 'dynamicChoice';
|
|
415
|
+
} | {
|
|
416
|
+
kind: 'message';
|
|
336
417
|
} | {
|
|
337
418
|
kind: 'action';
|
|
338
419
|
actionKind: FlowActionKind;
|
|
@@ -407,9 +488,11 @@ declare function FlowNodePanel({ graph, node, issues, otherFlows, onClose, onCha
|
|
|
407
488
|
interface FlowWhatsAppPreviewProps {
|
|
408
489
|
body: string;
|
|
409
490
|
options?: [string, string][];
|
|
491
|
+
/** Descrição e seção por id de opção — com qualquer uma, a mensagem sai como lista. */
|
|
492
|
+
optionDetails?: Record<string, FlowOptionDetail>;
|
|
410
493
|
labels?: FlowEditorLabels['nodePanel'];
|
|
411
494
|
}
|
|
412
|
-
declare function FlowWhatsAppPreview({ body, options, labels, }: FlowWhatsAppPreviewProps): react.JSX.Element;
|
|
495
|
+
declare function FlowWhatsAppPreview({ body, options, optionDetails, labels, }: FlowWhatsAppPreviewProps): react.JSX.Element;
|
|
413
496
|
|
|
414
497
|
/**
|
|
415
498
|
* Derivações puras do canvas do editor: posições, arestas, contagem de conversas vivas e o nó que
|