blip-cards 3.61.0 → 3.63.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 +40 -6
- package/dist/blip-cards.css +1 -1
- package/dist/blip-cards.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,12 +148,15 @@ translation: {
|
|
|
148
148
|
direction: 'received' // optional, 'received' | 'sent'
|
|
149
149
|
}), // or null when there is no translation for the message
|
|
150
150
|
onTranslate: (fullDocument) => {}, // optional, may return a Promise; called by the "Traduzir"/"Tentar novamente" actions
|
|
151
|
+
onToggleOriginal: (fullDocument, showingOriginal) => {}, // optional; called when the footer action switches between the translation and the original (state "done")
|
|
151
152
|
canTranslate: (fullDocument) => true // optional, defaults to `position === 'left'` (received messages)
|
|
152
153
|
}
|
|
153
154
|
```
|
|
154
155
|
|
|
155
156
|
`fullDocument` is the original message envelope (`id`, `type`, `content`, ...).
|
|
156
157
|
|
|
158
|
+
`onToggleOriginal` is called only when the footer action is clicked in the `done` state, after the local toggle was applied, in both directions. `showingOriginal` is `true` when the bubble switched to the original content (for sent messages, the content actually sent) and `false` when it switched back to the translation. It is not called in the `translate`, `pending` or `error` states (those use `onTranslate` or nothing). Errors thrown or promises rejected by the callback are swallowed by the cards.
|
|
159
|
+
|
|
157
160
|
| Field returned by `getTranslation` | Replaces (while the translation is shown) |
|
|
158
161
|
|---|---|
|
|
159
162
|
| `text` | Plain text (`text/plain`) content, select header text, media caption (image and file `text`) and the text of a received reply (`application/vnd.lime.reply+json` with a `text/plain` replied value) |
|
|
@@ -234,6 +237,8 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
234
237
|
{ "id": "account", "label": "Account number", "type": "number", "min": 1 },
|
|
235
238
|
{ "id": "visit", "label": "Visit date", "type": "date", "min": "2026-01-01" },
|
|
236
239
|
{ "id": "reason", "label": "Reason", "type": "select", "required": true, "options": [{ "value": "bill", "label": "Bill copy" }] },
|
|
240
|
+
{ "id": "state", "label": "State", "type": "select", "required": true, "searchable": true, "options": [{ "value": "MT", "label": "Mato Grosso" }, { "value": "SP", "label": "São Paulo" }] },
|
|
241
|
+
{ "id": "city", "label": "City", "type": "select", "required": true, "searchable": true, "dependsOn": "state", "options": { "MT": [{ "value": "5103403", "label": "Cuiabá" }], "SP": [{ "value": "3550308", "label": "São Paulo" }] } },
|
|
237
242
|
{ "id": "topics", "label": "Topics", "type": "checkbox", "options": [{ "value": "bill", "label": "Bill" }, { "value": "meter", "label": "Meter" }] },
|
|
238
243
|
{ "id": "photo", "label": "Meter photo", "type": "file", "accept": "image/*,application/pdf", "maxSizeMb": 5 },
|
|
239
244
|
{ "id": "comprovantes", "label": "Supporting documents", "type": "file", "multiple": true, "maxFiles": 5, "accept": "image/*,application/pdf" }
|
|
@@ -250,7 +255,7 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
250
255
|
| `fields` | Fields of a single-step form. |
|
|
251
256
|
| `steps` | `[{ "title"?: string, "fields": Field[] }]`. When present and non-empty, `fields` is ignored. Steps left without valid fields are dropped. |
|
|
252
257
|
| `submitLabel` / `nextLabel` / `backLabel` | Button labels. Defaults: `Enviar`, `Continuar`, `Voltar`. |
|
|
253
|
-
| `messages` | Overrides the default (pt-BR) validation messages by key: `required`, `email`, `tel`, `minLength`, `maxLength`, `min`, `max`, `pattern`, `mask`, `fileType`, `fileSize`, `uploadFailed`, `uploading`, `maxFiles`. `{min}`, `{max}` and `{
|
|
258
|
+
| `messages` | Overrides the default (pt-BR) validation messages by key: `required`, `email`, `tel`, `minLength`, `maxLength`, `min`, `max`, `pattern`, `mask`, `fileType`, `fileSize`, `uploadFailed`, `uploading`, `maxFiles`, `option`, `dependsOn`, `noOptions`, `noResults`, `lookupLoading`, `lookupPending`, `lookupNotFound`, `lookupFailed`. `{min}`, `{max}`, `{mask}` and `{field}` (label of the field a dependent field waits for) are replaced. |
|
|
254
259
|
|
|
255
260
|
**Field types** (unknown types are rendered as `text`)
|
|
256
261
|
|
|
@@ -262,12 +267,12 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
262
267
|
| `tel` | phone input; without `mask`, 8 to 15 digits are required | string |
|
|
263
268
|
| `date` | date input (`min`/`max` as `YYYY-MM-DD`) | `YYYY-MM-DD` |
|
|
264
269
|
| `textarea` | multi-line text | string |
|
|
265
|
-
| `select` | dropdown (`options`) | option `value` |
|
|
270
|
+
| `select` | dropdown (`options`); with `searchable: true`, a text box that filters the options while typing | option `value` |
|
|
266
271
|
| `radio` | radio group (`options`) | option `value` |
|
|
267
272
|
| `checkbox` | checkbox group (`options`) | array of option `value`s (`[]` when none) |
|
|
268
273
|
| `file` | file picker (`accept`, `maxSizeMb`, default 20) — requires `on-upload-file`. With `multiple: true`, a list of files (`maxFiles`, default 10) | uploaded media URI; with `multiple: true`, array of uploaded media URIs in the order the files were picked (`[]` when none) |
|
|
269
274
|
|
|
270
|
-
**Field properties**: `id` and `label` (required; ids must be unique across all steps), `required`, `placeholder`, `helpText`, `minLength`/`maxLength` (text, email, tel, textarea), `min`/`max` (number, date), `pattern` (JS regex source that must match the whole value; invalid expressions are ignored), `mask` (text and tel), `errorMessage` (replaces any validation message of the field, except the "wait for the upload"
|
|
275
|
+
**Field properties**: `id` and `label` (required; ids must be unique across all steps), `required`, `placeholder`, `helpText`, `minLength`/`maxLength` (text, email, tel, textarea), `min`/`max` (number, date), `pattern` (JS regex source that must match the whole value; invalid expressions are ignored), `mask` (text and tel), `errorMessage` (replaces any validation message of the field, except the "wait for the upload", "too many files", dependent field and postal code lookup notices, which can only be changed with `messages.uploading`, `messages.maxFiles`, `messages.dependsOn`/`noOptions`/`noResults` and the `messages.lookup*` keys), `options` (`[{ "value", "label" }]`, or grouped by the value of another field with `dependsOn`, see below), `searchable` (select: the boolean `true` shows a search box instead of the native dropdown), `dependsOn` (select, radio, checkbox: `id` of the field whose value chooses the options), `accept` and `maxSizeMb` (file, checked for each file), `multiple` (file: the boolean `true` accepts several files in the same field; any other value, including the string `"true"`, is ignored. Turning it on or off on an existing id resets the field, like a type change) and `maxFiles` (file with `multiple`: maximum number of files, rounded down; missing, invalid or below 1 means 10), `lookup` (text and tel with `mask`: fills other fields from a web service, see "Postal code lookup" below), `value` (pre-fill, see below), `showWhen` (conditional field, see below).
|
|
271
276
|
|
|
272
277
|
- **Pre-fill** (`value`): fills a field with data the bot already knows, usually a Builder variable such as `{{contact.extras.cpf}}`. Pre-filled values are editable, validated like typed values and sent in the content and summary.
|
|
273
278
|
- `text`, `number`, `email`, `tel`, `date`, `textarea`: a string, trimmed (numbers are converted to strings). With a `mask`, the value is formatted with it (`"12345678909"` → `123.456.789-09`). `number` values must follow the HTML number format (`42`, `-1.5`, `2.5e1`; not `+5`, `0x10` or `1.`) and `date` values must be a valid `YYYY-MM-DD`; anything else is ignored.
|
|
@@ -284,12 +289,40 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
284
289
|
{ "id": "cpf", "label": "CPF do titular", "type": "text", "mask": "000.000.000-00", "required": true, "value": "{{contact.extras.cpf}}" }
|
|
285
290
|
```
|
|
286
291
|
|
|
292
|
+
- **Searchable select** (`"searchable": true`, select only): for long lists such as cities. The user types and the list shows the options whose label contains the text, ignoring case and accents (`sao` finds `São Paulo`): the exact label first, then the ones that start with the text, then the others. Arrow keys move through the options, Enter or a tap chooses one, Escape closes the list. At most 50 options are listed at a time, with "Mostrando 50 de N. Digite para filtrar."; typing narrows the list down. Typing an exact label (ignoring case and accents) chooses it. Text that is not an option is not an answer: it shows the `option` error ("Escolha uma opção da lista.") and blocks sending. The value sent is the option `value`, as in a plain select. Any other value of `searchable` keeps the native dropdown.
|
|
293
|
+
- **Options that depend on another field** (`dependsOn`, select, radio and checkbox): `options` is an object whose keys are the values of the field named in `dependsOn` and whose values are the option lists for each one (e.g. cities grouped by state). The field shows only the group of the current value of that field:
|
|
294
|
+
- Until that field has a valid value, the field shows the `dependsOn` notice ("Escolha primeiro: Estado.") and cannot be answered (a select is disabled; radio and checkbox groups show no options). When the user tries to continue, the focus goes to the field it waits for. When the flow sent no group for the chosen value, the field shows the `noOptions` notice ("Nenhuma opção disponível."), does not block sending and is sent empty.
|
|
295
|
+
- When that field changes, the answer of the dependent field is cleared (unless it is also an option of the new group), without showing an error before the user answers again. Dependencies can be chained (state → city → district).
|
|
296
|
+
- The field it depends on must come before it (same or earlier step) and hold a single value (`text`, `number`, `email`, `tel`, `date`, `textarea`, `select` or `radio`); its value is matched to the keys as text (`"SP"`, `"5103403"`). A field with grouped `options` but without such a `dependsOn` is ignored, and `dependsOn` is ignored when `options` is a list.
|
|
297
|
+
- A `value` pre-fill may be an option of any group: it counts only while it belongs to the group of the current value of the field it depends on, and when that value changes it is kept only if it belongs to the new group (like any answer). Pre-fill both fields together (e.g. the state and the city of the contact).
|
|
298
|
+
- Every group travels in the bot message: for very long lists (e.g. every city of Brazil), send only the states/regions the journey needs.
|
|
299
|
+
|
|
300
|
+
```json
|
|
301
|
+
{ "id": "cidade", "label": "Cidade", "type": "select", "required": true, "searchable": true, "dependsOn": "estado",
|
|
302
|
+
"options": { "MT": [{ "value": "5103403", "label": "Cuiabá" }, { "value": "5108402", "label": "Várzea Grande" }],
|
|
303
|
+
"MS": [{ "value": "5002704", "label": "Campo Grande" }] } }
|
|
304
|
+
```
|
|
305
|
+
|
|
287
306
|
- **Masks**: `0` is a digit, `A` a letter, `*` a letter or digit; any other character is a literal inserted automatically, e.g. `000.000.000-00`, `(00) 00000-0000`, `00000-000`. The value is formatted while typing and is sent as displayed. A masked field is valid only when completely filled.
|
|
307
|
+
- **Postal code lookup** (`lookup`): when the `mask` of the field is complete, the card looks the value up in a web service chosen by the bot flow and fills other fields of the same form with the answer, so the address is asked in a single form.
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{ "id": "cep", "label": "CEP", "type": "text", "mask": "00000-000", "required": true,
|
|
311
|
+
"lookup": { "provider": "viacep", "fill": { "rua": "logradouro", "bairro": "bairro", "cidade": "localidade", "uf": "uf" } } }
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
- `provider: "viacep"` uses `https://viacep.com.br/ws/{value}/json/`. Another service is set with `url` (which wins over `provider`), e.g. `"url": "https://api.example.com/cep/{value}"`. The address must be `https` and contain `{value}`, which is replaced by the characters typed in the mask slots (`01001-000` → `01001000`). The request is a `GET` with `Accept: application/json`, without cookies (`credentials: 'omit'`) nor referrer, and gives up after 8 seconds. Nothing is looked up while the value is incomplete or invalid (e.g. it does not match `pattern`), in fields without `mask`, nor when `hide-options` is true.
|
|
315
|
+
- `fill` maps the id of a field of the same form (any step) to the property of the JSON answer that fills it; nested properties use dots (`"endereco.rua"`). Only `text`, `number`, `email`, `tel`, `date`, `textarea` and `select` fields are filled; the found text (control characters turned into spaces, trimmed) goes through the same rules as a pre-fill `value` (mask formatting, `select` only when it matches an option `value`). A lookup without any usable entry is ignored.
|
|
316
|
+
- Filled fields that are valid stay fixed (`readonly`, `select` disabled, grey background) and are sent as found. Fields left empty by the answer (e.g. a city-wide postal code without street) and invalid values stay editable. A field the user edits while the lookup runs keeps what the user typed. Editing the looked-up value again clears and unlocks what it filled; answers of a previous value are ignored.
|
|
317
|
+
- A `400`/`404` answer, an answer with `"erro": true` (ViaCEP) or without a value for any mapped field shows `lookupNotFound` under the looked-up field; a network error, another HTTP error, a timeout or a service blocked by the host page shows `lookupFailed`. In both cases the fields stay free and nothing blocks sending. While the lookup runs, `lookupLoading` is shown and the form waits for it before moving on (`lookupPending`).
|
|
318
|
+
- A pre-filled `value` is looked up when the card is created only when every mapped field is empty, so an address the flow already sent is kept on load; looking up another value typed by the user replaces it.
|
|
319
|
+
- With `showWhen`, a hidden looked-up field is not looked up on load and does not lock the fields it filled, and a hidden filled field is sent empty, like any hidden field.
|
|
320
|
+
- The service is called from the user's browser: it must accept cross-origin requests (CORS) and be allowed by the host page's `Content-Security-Policy` `connect-src` (Blip Chat allows `https://viacep.com.br`). Do not put secrets in the address: the message content is visible to the user. A service that needs credentials cannot be called by the card: it has to be reached through a backend that keeps the credentials (not provided by the card). Only the typed value is sent to the service; the answer itself is not sent to the bot, only the field values.
|
|
288
321
|
- **Validation** happens in real time: errors are shown under a field after it is left (or after the user tries to continue) and update while typing. The form cannot be advanced/sent while there are errors in the current step; focus goes to the first invalid field.
|
|
289
322
|
- **Steps**: with more than one step, a "Etapa n de N" header with a progress bar is shown; `Voltar` keeps the values and only the current step is validated before moving on. Single-step forms have no header nor back button.
|
|
290
323
|
- **Conditional fields** (`showWhen`): `{ "field": "<id of another field, any step>", "in": [values] }` or `{ "field": "…", "equals": value }` (string, number or boolean) shows the field only while that field holds one of the values (`in` is used when it has string, number or boolean values, others being ignored, otherwise `equals`; values are compared as strings; a `checkbox` source matches when any selected option is one of them). The field appears and disappears as the answer changes, keeping its position.
|
|
291
324
|
- A hidden field is not validated (`required` and every other rule apply only while it is shown, and a pending or failed upload does not block), is sent empty (`""`, `[]` for `checkbox` and `file` with `multiple`) whatever was typed, and is left out of the summary text and of the read-only summary. What was typed is kept while the card is open and comes back if the field is shown again; it shows no error until it is left or the user tries to continue.
|
|
292
|
-
- A field whose source is hidden is hidden too (chains collapse). Invalid conditions are ignored and the field is always shown: not an object, unknown source (including ignored fields), the field itself, a `file` source, no values, or a cycle (A → B → A).
|
|
325
|
+
- A field whose source is hidden is hidden too (chains collapse). The same applies to a field with `dependsOn` whose parent is hidden: it could not be answered, so it is hidden and sent empty. Invalid conditions are ignored and the field is always shown: not an object, unknown source (including ignored fields), the field itself, a `file` source, no values, or a cycle (A → B → A, also through `dependsOn`, e.g. a state shown only for a city that depends on that state).
|
|
293
326
|
- With `steps`, a step whose fields are all hidden is skipped by `Continuar`/`Voltar` and not counted in "Etapa n de N"; the last visible step shows the submit button. The "Etapa n de N" header, its count and the back button follow the visible steps, so they may change as the user answers (a step that appears before the current one does not move the user).
|
|
294
327
|
- In Builder, a hidden field reads as empty (`{{formulario@nome_conjuge}}` → empty).
|
|
295
328
|
|
|
@@ -299,11 +332,11 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
299
332
|
{ "id": "orgao_expedidor", "label": "Órgão expedidor", "type": "select", "options": [{ "value": "ssp", "label": "SSP" }, { "value": "outro", "label": "Outro" }] },
|
|
300
333
|
{ "id": "outro_orgao", "label": "Outro órgão expedidor", "type": "text", "required": true, "showWhen": { "field": "orgao_expedidor", "equals": "outro" } }
|
|
301
334
|
```
|
|
302
|
-
- Fields without an `id`, `select`/`radio`/`checkbox` fields without `options` and `file` fields when the host does not provide `on-upload-file` are ignored. Labels are rendered as plain text.
|
|
335
|
+
- Fields without an `id`, `select`/`radio`/`checkbox` fields without `options` (or with grouped `options` without a valid `dependsOn`) and `file` fields when the host does not provide `on-upload-file` are ignored. Labels are rendered as plain text.
|
|
303
336
|
- **Upload**: hosts enable `file` fields by passing `on-upload-file` to `blip-card`/`blip-group-card`: `(file: File) => Promise<string | { uri: string }>`. The file type (`accept`, MIME type or extension, wildcards such as `image/*`) and size are checked before calling it; the form cannot be sent while an upload is pending, and a rejected promise shows an error so the user can choose another file.
|
|
304
337
|
- With `multiple: true`, several files can be picked at once or added one by one (`Escolher arquivos` / `Adicionar arquivo`, with a "n de N arquivos" counter). Each file is checked and uploaded on its own, at most 3 at a time per form (the others are shown as `Enviando…` and start when an upload finishes), is listed with its status (with the reason when it failed) and a `Remover` button, and the picker is disabled once `maxFiles` is reached. Files picked beyond the limit are left out with the `maxFiles` notice, which does not block sending. A file that failed (type, size or upload) blocks sending until it is removed; if the card receives a lower `maxFiles` after the files were picked, the extra files block sending (with the `maxFiles` message) until they are removed; `required` means at least one uploaded file.
|
|
305
338
|
- After the form is sent, the read-only summary shows the file name of each `file` field as a link (one link per file, separated by `, `, with `multiple`). It calls `on-media-selected(uri)` when the host provides it (blip-chat renews an expired link before opening it) and otherwise opens the address in a new tab. Only `http(s)` addresses are linked.
|
|
306
|
-
- `on-selected` is called with a `
|
|
339
|
+
- `on-selected` is called with a summary text with one `label: value` line per visible field, separated by line breaks (`\n`), which message bubbles keep, so the answer reads as a list. Empty fields show `—` (also in the card's read-only summary), and line breaks inside a value (e.g. a `textarea`) become ` / `, so each line is a field. Values use the display format (dates formatted with the browser locale, option labels for `select`/`radio`/`checkbox`, the file name as a link (`[name](https://…)`) for `file`, one per file separated by `, ` with `multiple`, so the file can still be opened from the conversation history). The second argument is `{ type: 'application/json', content: { [field.id]: value } }` containing the fields of all steps. Empty optional fields are sent as `""` (`[]` for `checkbox` and `file` with `multiple`). In the message bubble each link shows only the file name, and the collapsed preview ("Ver mais") counts only that name and never cuts a link in half. Once sent, the card shows a read-only summary.
|
|
307
340
|
- When `hide-options` is true, the fields and all buttons are disabled. Hosts such as blip-chat set it on every card that is not the latest message of the conversation.
|
|
308
341
|
|
|
309
342
|
**Reading the answers in Builder** (no backend change is required; verified against Take.Blip.Builder 0.7.524 and on HMG):
|
|
@@ -313,6 +346,7 @@ A structured form (several fields answered in a single interaction, optionally s
|
|
|
313
346
|
- Use only letters, digits and `_` in field ids (`data_visita`, not `data-visita`): the variable property syntax does not accept `-`, and `.` is read as a nested property.
|
|
314
347
|
- `checkbox` values are returned as a JSON array (`{{formulario@topicos}}` → `["conta","medidor"]`); indexes such as `@topicos[0]` are not supported, so use a script to split them.
|
|
315
348
|
- `file` fields with `multiple` are returned as a JSON array of links, like `checkbox` (`{{formulario@comprovantes}}` → `["https://…","https://…"]`); each link is signed for a limited time, as below.
|
|
349
|
+
- Fields filled by a postal code lookup are read like any other field (`{{formulario@rua}}`): the bot receives the postal code, the found address and what the user typed in the same answer.
|
|
316
350
|
- `file` values are media links signed for a limited time (30 minutes for blip-chat uploads on HMG). Forward or store the file within that window, or renew the link with the `set /refresh-media-uri` command to `postmaster@media.msging.net`.
|
|
317
351
|
|
|
318
352
|
## Contributions
|