@liftitapp/wa-conversations 0.11.0 → 0.12.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 +37 -0
- package/dist/element/index.js +155 -10
- package/dist/react/index.d.ts +153 -4
- package/dist/react/index.js +690 -68
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -756,7 +756,7 @@ function dedupeByWamid(messages) {
|
|
|
756
756
|
//#endregion
|
|
757
757
|
//#region src/core/contract/operator-send.ts
|
|
758
758
|
/** El payload del cable es entrada NO confiable: se mira como diccionario, no como tipo. */
|
|
759
|
-
function asRecord$
|
|
759
|
+
function asRecord$2(value) {
|
|
760
760
|
return typeof value === "object" && value !== null ? value : {};
|
|
761
761
|
}
|
|
762
762
|
/** Un string útil, o `null`. El vacío es tan inútil como el ausente. */
|
|
@@ -833,7 +833,7 @@ function optimisticMessage(text, at, clientMessageId) {
|
|
|
833
833
|
* hacerle perder al operador el mensaje que acaba de mandar.
|
|
834
834
|
*/
|
|
835
835
|
function normalizeReplyMessage(payload) {
|
|
836
|
-
const record = asRecord$
|
|
836
|
+
const record = asRecord$2(payload);
|
|
837
837
|
return {
|
|
838
838
|
id: asNonEmptyString(record.wamid) ?? asNonEmptyString(record.id),
|
|
839
839
|
at: asNonEmptyString(record.at) ?? asNonEmptyString(record.occurred_at),
|
|
@@ -868,8 +868,8 @@ const UNSTRUCTURED_ERROR_CODE = "unknown";
|
|
|
868
868
|
* exactamente el atajo que en FlexOS terminaba mandando plantillas facturadas.
|
|
869
869
|
*/
|
|
870
870
|
function readSendError(cause) {
|
|
871
|
-
const fromError = asRecord$
|
|
872
|
-
const direct = asRecord$
|
|
871
|
+
const fromError = asRecord$2(asRecord$2(cause).body);
|
|
872
|
+
const direct = asRecord$2(cause);
|
|
873
873
|
const body = typeof fromError.error_code === "string" ? fromError : typeof direct.error_code === "string" ? direct : {};
|
|
874
874
|
const errorCode = asNonEmptyString(body.error_code);
|
|
875
875
|
if (errorCode === null) return {
|
|
@@ -903,9 +903,119 @@ function sendFailureCopy(failure) {
|
|
|
903
903
|
case "takeover_unavailable": return "No se pudo pausar el bot, así que el mensaje no se envió. Reintenta en un momento.";
|
|
904
904
|
case "send_failed": return "WhatsApp rechazó el envío. El mensaje quedó registrado en el hilo como no entregado.";
|
|
905
905
|
case "write_forbidden": return "No tienes permiso para responder en esta conversación.";
|
|
906
|
+
case "invalid_phone": return "El número de destino no es un celular válido en formato E.164.";
|
|
907
|
+
case "template_not_allowed": return "La plantilla no está habilitada para este número.";
|
|
908
|
+
case "invalid_template_params": return "Los parámetros no coinciden con la plantilla.";
|
|
906
909
|
default: return failure.serverMessage ?? "No se pudo enviar el mensaje.";
|
|
907
910
|
}
|
|
908
911
|
}
|
|
912
|
+
function asRecord$1(value) {
|
|
913
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
914
|
+
}
|
|
915
|
+
function asString$1(value) {
|
|
916
|
+
return typeof value === "string" ? value : "";
|
|
917
|
+
}
|
|
918
|
+
function asNullableString$1(value) {
|
|
919
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Estrecha una plantilla del cable. Sin `name` o `language` no hay qué mandar: se descarta. Un
|
|
923
|
+
* `body_param_count` fuera de 0–10 o no entero también: ofrecerla sería un formulario que el store
|
|
924
|
+
* siempre rechaza.
|
|
925
|
+
*/
|
|
926
|
+
function normalizeTemplate(value) {
|
|
927
|
+
const record = asRecord$1(value);
|
|
928
|
+
const name = asNullableString$1(record.name);
|
|
929
|
+
const language = asNullableString$1(record.language);
|
|
930
|
+
const count = record.body_param_count;
|
|
931
|
+
if (name === null || language === null) return null;
|
|
932
|
+
if (typeof count !== "number" || !Number.isInteger(count)) return null;
|
|
933
|
+
if (count < 0 || count > 10) return null;
|
|
934
|
+
return {
|
|
935
|
+
name,
|
|
936
|
+
language,
|
|
937
|
+
label: asNullableString$1(record.label),
|
|
938
|
+
body_param_count: count,
|
|
939
|
+
body_text: asNullableString$1(record.body_text)
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* El 200 de la lista. `can_start` es fail-closed (sólo el `true` literal), como `can_reply`.
|
|
944
|
+
*/
|
|
945
|
+
function normalizeTemplates(payload) {
|
|
946
|
+
const record = asRecord$1(payload);
|
|
947
|
+
const items = Array.isArray(record.items) ? record.items.map(normalizeTemplate).filter((item) => item !== null) : [];
|
|
948
|
+
return {
|
|
949
|
+
phone_number_id: asString$1(record.phone_number_id),
|
|
950
|
+
can_start: record.can_start === true,
|
|
951
|
+
items
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
/** El 201/200 del envío: la burbuja es el MISMO `ThreadMessage` del hilo y de `/reply`. */
|
|
955
|
+
function normalizeStartResponse(payload) {
|
|
956
|
+
const record = asRecord$1(payload);
|
|
957
|
+
return {
|
|
958
|
+
phone_e164: asString$1(record.phone_e164),
|
|
959
|
+
phone_number_id: asString$1(record.phone_number_id),
|
|
960
|
+
message: normalizeReplyMessage(record.message)
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* ¿El rechazo del hilo dice «no hay conversación con este número»?
|
|
965
|
+
*
|
|
966
|
+
* El store responde 404 genérico a un par inexistente (no revela qué teléfonos existen). Se
|
|
967
|
+
* reconocen las dos formas que llegan hoy: `status === 404` (el `WaFetchError` del default-fetcher
|
|
968
|
+
* del entry `./element`, o cualquier error con `.status`) y la marca `code: 'wa_no_conversation'`
|
|
969
|
+
* del fetcher de `lms-web-app`. Cualquier otra cosa es un error de verdad y se pinta como tal.
|
|
970
|
+
*/
|
|
971
|
+
function isNoThreadError(error) {
|
|
972
|
+
const record = asRecord$1(error);
|
|
973
|
+
return record.status === 404 || record.code === "wa_no_conversation";
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* La regla de cuándo se ofrece la plantilla (DEV-8758).
|
|
977
|
+
*
|
|
978
|
+
* 🔴 Sólo `closed` la abre: `unverified` NO. «No pudimos leer la ventana» no es «está cerrada», y
|
|
979
|
+
* ofrecer una plantilla —que Meta cobra— por un parpadeo de Postgres es exactamente el bug de
|
|
980
|
+
* FlexOS que el composer ya evita (`CLAUDE.md`).
|
|
981
|
+
*
|
|
982
|
+
* Con un hilo existente hace falta además `can_reply`: un operador de solo lectura ve el visor como
|
|
983
|
+
* siempre. Sin hilo no hay `can_reply` que leer, y quien decide es el `can_start` de la lista.
|
|
984
|
+
*/
|
|
985
|
+
function templateOffer(input) {
|
|
986
|
+
if (!(input.noThread || input.canReply && input.windowState === "closed")) return "none";
|
|
987
|
+
const { templates } = input;
|
|
988
|
+
if (templates.status === "idle" || templates.status === "loading") return "loading";
|
|
989
|
+
if (templates.status === "error") return "unavailable";
|
|
990
|
+
if (!templates.canStart) return "read_only";
|
|
991
|
+
if (templates.itemCount === 0) return "no_templates";
|
|
992
|
+
return "form";
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* ¿Los parámetros que tipeó el operador pasan las reglas del contrato? Es la misma validación que
|
|
996
|
+
* hace el store (422 `invalid_template_params`) y se repite acá sólo para no habilitar «Enviar
|
|
997
|
+
* plantilla» con algo que va a volver rechazado. El store sigue siendo quien decide.
|
|
998
|
+
*/
|
|
999
|
+
function templateParamsValid(params, expectedCount) {
|
|
1000
|
+
if (params.length !== expectedCount) return false;
|
|
1001
|
+
return params.every((raw) => {
|
|
1002
|
+
const value = raw.trim();
|
|
1003
|
+
if (value === "" || value.length > 1024) return false;
|
|
1004
|
+
if (/[\n\r\t]/.test(value)) return false;
|
|
1005
|
+
return !/ {5,}/.test(value);
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* La vista previa: el `body_text` aprobado con cada `{{n}}` reemplazado por su parámetro. Un
|
|
1010
|
+
* parámetro vacío deja el `{{n}}` a la vista, para que se note qué falta. Sin `body_text`, `null`.
|
|
1011
|
+
*/
|
|
1012
|
+
function renderTemplatePreview(bodyText, params) {
|
|
1013
|
+
if (bodyText === null) return null;
|
|
1014
|
+
return bodyText.replace(/\{\{(\d+)\}\}/g, (match, index) => {
|
|
1015
|
+
const value = params[Number(index) - 1]?.trim() ?? "";
|
|
1016
|
+
return value === "" ? match : value;
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
909
1019
|
//#endregion
|
|
910
1020
|
//#region src/core/data/fetcher.ts
|
|
911
1021
|
/**
|
|
@@ -1108,6 +1218,25 @@ async function loadConversations(fetcher, request = {}, options) {
|
|
|
1108
1218
|
next_cursor: asNullableString(payload.next_cursor)
|
|
1109
1219
|
};
|
|
1110
1220
|
}
|
|
1221
|
+
/**
|
|
1222
|
+
* La lista de plantillas que se pueden mandar desde el número del host (DEV-8758). Coerción
|
|
1223
|
+
* defensiva como el resto: un payload deforme sale `can_start: false` e `items: []`. Los rechazos
|
|
1224
|
+
* se propagan tal cual: el panel decide qué pintar.
|
|
1225
|
+
*/
|
|
1226
|
+
async function loadTemplates(fetcher, options) {
|
|
1227
|
+
return normalizeTemplates(await fetcher({ resource: "templates" }, options));
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Inicia la conversación con la plantilla (DEV-8758, 201 o 200 idempotente). Los rechazos se
|
|
1231
|
+
* propagan TAL CUAL y se leen con `readSendError` — el cuerpo plano `{error_code, retryable,
|
|
1232
|
+
* message}` es el mismo molde que el de `/reply`.
|
|
1233
|
+
*/
|
|
1234
|
+
async function startConversation(fetcher, request, options) {
|
|
1235
|
+
return normalizeStartResponse(await fetcher({
|
|
1236
|
+
resource: "startConversation",
|
|
1237
|
+
...request
|
|
1238
|
+
}, options));
|
|
1239
|
+
}
|
|
1111
1240
|
//#endregion
|
|
1112
1241
|
//#region src/core/usePolling.ts
|
|
1113
1242
|
/**
|
|
@@ -1994,7 +2123,7 @@ function ReleaseToBot({ composer }) {
|
|
|
1994
2123
|
]
|
|
1995
2124
|
});
|
|
1996
2125
|
}
|
|
1997
|
-
function Composer({ canReply, composer, onRetryWindow, prefill, locked = false, takeoverNotice = null, focusRequest = null }) {
|
|
2126
|
+
function Composer({ canReply, composer, onRetryWindow, prefill, locked = false, takeoverNotice = null, focusRequest = null, templateStart = null }) {
|
|
1998
2127
|
/**
|
|
1999
2128
|
* Lo que el operador tipeó, junto con **de qué precarga vino** (DEC-G).
|
|
2000
2129
|
*
|
|
@@ -2043,6 +2172,14 @@ function Composer({ canReply, composer, onRetryWindow, prefill, locked = false,
|
|
|
2043
2172
|
/** El id del aviso del pie, para que el lector de pantalla lo lea al enfocar el textarea. */
|
|
2044
2173
|
const noticeId = useId();
|
|
2045
2174
|
if (!canReply) return null;
|
|
2175
|
+
if (composer.windowState === "closed" && templateStart !== null) return /* @__PURE__ */ jsxs("div", {
|
|
2176
|
+
className: "wa-composer wa-composer--template",
|
|
2177
|
+
children: [
|
|
2178
|
+
/* @__PURE__ */ jsx(FailureNotice, { composer }),
|
|
2179
|
+
templateStart,
|
|
2180
|
+
/* @__PURE__ */ jsx(ReleaseToBot, { composer })
|
|
2181
|
+
]
|
|
2182
|
+
});
|
|
2046
2183
|
if (composer.windowState === "closed") return /* @__PURE__ */ jsxs("div", {
|
|
2047
2184
|
className: "wa-composer wa-composer--closed",
|
|
2048
2185
|
children: [
|
|
@@ -3961,6 +4098,151 @@ const THREAD_CSS = `
|
|
|
3961
4098
|
color: #52606d;
|
|
3962
4099
|
}
|
|
3963
4100
|
|
|
4101
|
+
/* DEV-8758 — «Iniciar con plantilla» (tableros 391/392): con la ventana cerrada o sin hilo, el
|
|
4102
|
+
composer es un formulario de plantilla. Mismo fondo y bordes que el composer de texto. */
|
|
4103
|
+
.wa-composer--template {
|
|
4104
|
+
gap: 10px;
|
|
4105
|
+
}
|
|
4106
|
+
.wa-template {
|
|
4107
|
+
display: flex;
|
|
4108
|
+
flex-direction: column;
|
|
4109
|
+
gap: 10px;
|
|
4110
|
+
}
|
|
4111
|
+
.wa-template__notice {
|
|
4112
|
+
margin: 0;
|
|
4113
|
+
padding: 8px 12px;
|
|
4114
|
+
border: 1px solid #F5E7C8;
|
|
4115
|
+
border-radius: 8px;
|
|
4116
|
+
font-size: 12px;
|
|
4117
|
+
color: #8A5A10;
|
|
4118
|
+
background: #FFFBF2;
|
|
4119
|
+
}
|
|
4120
|
+
.wa-template__route {
|
|
4121
|
+
display: flex;
|
|
4122
|
+
flex-direction: column;
|
|
4123
|
+
gap: 2px;
|
|
4124
|
+
padding: 8px 12px;
|
|
4125
|
+
border-radius: 8px;
|
|
4126
|
+
font-size: 12px;
|
|
4127
|
+
color: #2D3340;
|
|
4128
|
+
background: #F4F5F7;
|
|
4129
|
+
}
|
|
4130
|
+
.wa-template__route-line {
|
|
4131
|
+
margin: 0;
|
|
4132
|
+
}
|
|
4133
|
+
.wa-template__route-key {
|
|
4134
|
+
font-weight: 600;
|
|
4135
|
+
color: #616e7c;
|
|
4136
|
+
}
|
|
4137
|
+
.wa-template__note {
|
|
4138
|
+
margin: 0;
|
|
4139
|
+
font-size: 12px;
|
|
4140
|
+
color: #8A91A0;
|
|
4141
|
+
}
|
|
4142
|
+
.wa-template__link {
|
|
4143
|
+
padding: 0;
|
|
4144
|
+
border: 0;
|
|
4145
|
+
font: inherit;
|
|
4146
|
+
color: #4F5AED;
|
|
4147
|
+
background: none;
|
|
4148
|
+
cursor: pointer;
|
|
4149
|
+
}
|
|
4150
|
+
.wa-template__form {
|
|
4151
|
+
display: flex;
|
|
4152
|
+
flex-direction: column;
|
|
4153
|
+
gap: 8px;
|
|
4154
|
+
}
|
|
4155
|
+
.wa-template__field {
|
|
4156
|
+
display: flex;
|
|
4157
|
+
flex-direction: column;
|
|
4158
|
+
gap: 4px;
|
|
4159
|
+
}
|
|
4160
|
+
.wa-template__label {
|
|
4161
|
+
font-size: 11px;
|
|
4162
|
+
font-weight: 600;
|
|
4163
|
+
color: #616e7c;
|
|
4164
|
+
}
|
|
4165
|
+
.wa-template__select,
|
|
4166
|
+
.wa-template__input {
|
|
4167
|
+
padding: 7px 10px;
|
|
4168
|
+
border: 1px solid #E4E7EE;
|
|
4169
|
+
border-radius: 8px;
|
|
4170
|
+
font: inherit;
|
|
4171
|
+
font-size: 13px;
|
|
4172
|
+
color: #2D3340;
|
|
4173
|
+
background: #F4F5F7;
|
|
4174
|
+
}
|
|
4175
|
+
.wa-template__select:focus,
|
|
4176
|
+
.wa-template__input:focus {
|
|
4177
|
+
border-color: #4F5AED;
|
|
4178
|
+
outline: 2px solid rgba(79, 90, 237, 0.25);
|
|
4179
|
+
outline-offset: 0;
|
|
4180
|
+
}
|
|
4181
|
+
/* La vista previa como burbuja de salida: es lo que va a leer la persona. */
|
|
4182
|
+
.wa-template__preview {
|
|
4183
|
+
align-self: flex-end;
|
|
4184
|
+
max-width: 85%;
|
|
4185
|
+
padding: 8px 12px;
|
|
4186
|
+
border-radius: 12px 12px 4px 12px;
|
|
4187
|
+
background: #EEF1FE;
|
|
4188
|
+
}
|
|
4189
|
+
.wa-template__preview-tag {
|
|
4190
|
+
display: block;
|
|
4191
|
+
margin-bottom: 4px;
|
|
4192
|
+
font-size: 10.5px;
|
|
4193
|
+
font-weight: 600;
|
|
4194
|
+
color: #4F5AED;
|
|
4195
|
+
}
|
|
4196
|
+
.wa-template__preview-body {
|
|
4197
|
+
margin: 0;
|
|
4198
|
+
font-size: 13px;
|
|
4199
|
+
color: #2D3340;
|
|
4200
|
+
white-space: pre-wrap;
|
|
4201
|
+
}
|
|
4202
|
+
.wa-template__error {
|
|
4203
|
+
display: flex;
|
|
4204
|
+
flex-wrap: wrap;
|
|
4205
|
+
align-items: center;
|
|
4206
|
+
justify-content: space-between;
|
|
4207
|
+
gap: 8px;
|
|
4208
|
+
padding: 8px 10px;
|
|
4209
|
+
border: 1px solid #e5b9b6;
|
|
4210
|
+
border-radius: 6px;
|
|
4211
|
+
background: #fdf6f6;
|
|
4212
|
+
}
|
|
4213
|
+
.wa-template__error-text {
|
|
4214
|
+
margin: 0;
|
|
4215
|
+
font-size: 12px;
|
|
4216
|
+
color: #7d1f1a;
|
|
4217
|
+
}
|
|
4218
|
+
.wa-template__retry {
|
|
4219
|
+
padding: 4px 12px;
|
|
4220
|
+
border: 1px solid #F0C9C5;
|
|
4221
|
+
border-radius: 999px;
|
|
4222
|
+
font: inherit;
|
|
4223
|
+
font-size: 12px;
|
|
4224
|
+
color: #D93025;
|
|
4225
|
+
background: #ffffff;
|
|
4226
|
+
cursor: pointer;
|
|
4227
|
+
}
|
|
4228
|
+
.wa-template__sent {
|
|
4229
|
+
margin: 0;
|
|
4230
|
+
font-size: 12px;
|
|
4231
|
+
color: #1E7F4F;
|
|
4232
|
+
}
|
|
4233
|
+
.wa-template__footer {
|
|
4234
|
+
display: flex;
|
|
4235
|
+
align-items: center;
|
|
4236
|
+
justify-content: space-between;
|
|
4237
|
+
gap: 8px;
|
|
4238
|
+
}
|
|
4239
|
+
.wa-template__hint {
|
|
4240
|
+
margin-right: auto;
|
|
4241
|
+
min-width: 0;
|
|
4242
|
+
font-size: 10.5px;
|
|
4243
|
+
color: #9AA1AE;
|
|
4244
|
+
}
|
|
4245
|
+
|
|
3964
4246
|
/* El envío que no salió: el porqué y qué se puede hacer, junto a la caja donde se escribió. */
|
|
3965
4247
|
.wa-composer__failures {
|
|
3966
4248
|
display: flex;
|
|
@@ -4863,6 +5145,296 @@ function useSuggestion({ fetcher, phone, messages, outgoing = [], onPrefill }) {
|
|
|
4863
5145
|
};
|
|
4864
5146
|
}
|
|
4865
5147
|
//#endregion
|
|
5148
|
+
//#region src/core/thread/TemplateStartPanel.tsx
|
|
5149
|
+
/**
|
|
5150
|
+
* «Iniciar con plantilla» (DEV-8758) — el composer cuando WhatsApp sólo deja escribir con una
|
|
5151
|
+
* plantilla aprobada: ventana de 24 h cerrada (tablero 391) o sin hilo (tablero 392).
|
|
5152
|
+
*
|
|
5153
|
+
* Presentacional: qué modo se pinta lo decide `templateOffer` y la red vive en `useTemplateStart`.
|
|
5154
|
+
* Interno del hilo — NO sale al barrel (mismo criterio que `Composer`).
|
|
5155
|
+
*
|
|
5156
|
+
* 🔴 Todo lo que viene del store (`label`, `body_text`) y el nombre del contacto entran como hijos
|
|
5157
|
+
* de texto, que React escapa. Nada de `dangerouslySetInnerHTML`.
|
|
5158
|
+
*/
|
|
5159
|
+
/** El primer nombre para prellenar `{{1}}`: «Nelson Chaves» ⇒ «Nelson». */
|
|
5160
|
+
function firstName$1(name) {
|
|
5161
|
+
return (typeof name === "string" ? name.trim().split(/\s+/)[0] : "") ?? "";
|
|
5162
|
+
}
|
|
5163
|
+
function TemplateStartPanel({ mode, start, noThread, phone, contactName, senderLabel }) {
|
|
5164
|
+
const selectId = useId();
|
|
5165
|
+
const items = start.response?.items ?? [];
|
|
5166
|
+
const [selected, setSelected] = useState(0);
|
|
5167
|
+
/** Lo que tipeó el operador, por plantilla: cambiar de plantilla no mezcla parámetros. */
|
|
5168
|
+
const [typed, setTyped] = useState({});
|
|
5169
|
+
if (mode === "none") return null;
|
|
5170
|
+
const template = items[Math.min(selected, Math.max(items.length - 1, 0))] ?? null;
|
|
5171
|
+
const templateKey = template !== null ? `${template.name}#${template.language}` : "";
|
|
5172
|
+
const params = template === null ? [] : typed[templateKey] ?? Array.from({ length: template.body_param_count }, (_, index) => index === 0 ? firstName$1(contactName) : "");
|
|
5173
|
+
const sending = start.sendState === "sending";
|
|
5174
|
+
const canSend = mode === "form" && template !== null && !sending && templateParamsValid(params, template.body_param_count);
|
|
5175
|
+
const preview = template !== null ? renderTemplatePreview(template.body_text, params) : null;
|
|
5176
|
+
const setParam = (index, value) => {
|
|
5177
|
+
const next = [...params];
|
|
5178
|
+
next[index] = value;
|
|
5179
|
+
setTyped({
|
|
5180
|
+
...typed,
|
|
5181
|
+
[templateKey]: next
|
|
5182
|
+
});
|
|
5183
|
+
};
|
|
5184
|
+
const submit = () => {
|
|
5185
|
+
if (!canSend || template === null) return;
|
|
5186
|
+
start.send(template.name, template.language, params);
|
|
5187
|
+
};
|
|
5188
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
5189
|
+
className: "wa-template",
|
|
5190
|
+
"data-mode": mode,
|
|
5191
|
+
children: [
|
|
5192
|
+
noThread ? /* @__PURE__ */ jsxs("div", {
|
|
5193
|
+
className: "wa-template__route",
|
|
5194
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
5195
|
+
className: "wa-template__route-line",
|
|
5196
|
+
children: [
|
|
5197
|
+
/* @__PURE__ */ jsx("span", {
|
|
5198
|
+
className: "wa-template__route-key",
|
|
5199
|
+
children: "Para:"
|
|
5200
|
+
}),
|
|
5201
|
+
" ",
|
|
5202
|
+
phone,
|
|
5203
|
+
contactName !== null && ` · ${contactName}`
|
|
5204
|
+
]
|
|
5205
|
+
}), senderLabel !== null && /* @__PURE__ */ jsxs("p", {
|
|
5206
|
+
className: "wa-template__route-line",
|
|
5207
|
+
children: [
|
|
5208
|
+
/* @__PURE__ */ jsx("span", {
|
|
5209
|
+
className: "wa-template__route-key",
|
|
5210
|
+
children: "Desde:"
|
|
5211
|
+
}),
|
|
5212
|
+
" ",
|
|
5213
|
+
senderLabel
|
|
5214
|
+
]
|
|
5215
|
+
})]
|
|
5216
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
5217
|
+
className: "wa-template__notice",
|
|
5218
|
+
role: "status",
|
|
5219
|
+
children: "La ventana de 24 h está cerrada: solo se puede escribir con una plantilla aprobada. Al enviarla, el bot se pausa."
|
|
5220
|
+
}),
|
|
5221
|
+
mode === "loading" && /* @__PURE__ */ jsx("p", {
|
|
5222
|
+
className: "wa-template__note",
|
|
5223
|
+
children: "Cargando plantillas…"
|
|
5224
|
+
}),
|
|
5225
|
+
mode === "unavailable" && /* @__PURE__ */ jsxs("div", {
|
|
5226
|
+
className: "wa-template__note",
|
|
5227
|
+
role: "alert",
|
|
5228
|
+
children: [
|
|
5229
|
+
"No se pudieron cargar las plantillas.",
|
|
5230
|
+
" ",
|
|
5231
|
+
/* @__PURE__ */ jsx("button", {
|
|
5232
|
+
type: "button",
|
|
5233
|
+
className: "wa-template__link",
|
|
5234
|
+
onClick: start.reloadTemplates,
|
|
5235
|
+
children: "Reintentar"
|
|
5236
|
+
})
|
|
5237
|
+
]
|
|
5238
|
+
}),
|
|
5239
|
+
mode === "read_only" && /* @__PURE__ */ jsx("p", {
|
|
5240
|
+
className: "wa-template__note",
|
|
5241
|
+
children: "Tu rol puede ver conversaciones, pero no iniciarlas."
|
|
5242
|
+
}),
|
|
5243
|
+
mode === "no_templates" && /* @__PURE__ */ jsx("p", {
|
|
5244
|
+
className: "wa-template__note",
|
|
5245
|
+
children: "No hay plantillas habilitadas para este número."
|
|
5246
|
+
}),
|
|
5247
|
+
mode === "form" && template !== null && /* @__PURE__ */ jsxs("form", {
|
|
5248
|
+
className: "wa-template__form",
|
|
5249
|
+
onSubmit: (event) => {
|
|
5250
|
+
event.preventDefault();
|
|
5251
|
+
submit();
|
|
5252
|
+
},
|
|
5253
|
+
children: [
|
|
5254
|
+
/* @__PURE__ */ jsxs("label", {
|
|
5255
|
+
className: "wa-template__field",
|
|
5256
|
+
htmlFor: selectId,
|
|
5257
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
5258
|
+
className: "wa-template__label",
|
|
5259
|
+
children: "Plantilla"
|
|
5260
|
+
}), /* @__PURE__ */ jsx("select", {
|
|
5261
|
+
id: selectId,
|
|
5262
|
+
className: "wa-template__select",
|
|
5263
|
+
value: selected,
|
|
5264
|
+
disabled: sending,
|
|
5265
|
+
onChange: (event) => setSelected(Number(event.target.value)),
|
|
5266
|
+
children: items.map((item, index) => /* @__PURE__ */ jsx("option", {
|
|
5267
|
+
value: index,
|
|
5268
|
+
children: item.label ?? item.name
|
|
5269
|
+
}, `${item.name}#${item.language}`))
|
|
5270
|
+
})]
|
|
5271
|
+
}),
|
|
5272
|
+
params.map((value, index) => /* @__PURE__ */ jsxs("label", {
|
|
5273
|
+
className: "wa-template__field",
|
|
5274
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
5275
|
+
className: "wa-template__label",
|
|
5276
|
+
children: [
|
|
5277
|
+
index === 0 ? "Nombre del lifter" : "Parámetro",
|
|
5278
|
+
" · ",
|
|
5279
|
+
`{{${index + 1}}}`
|
|
5280
|
+
]
|
|
5281
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
5282
|
+
className: "wa-template__input",
|
|
5283
|
+
value,
|
|
5284
|
+
maxLength: 1024,
|
|
5285
|
+
disabled: sending,
|
|
5286
|
+
onChange: (event) => setParam(index, event.target.value)
|
|
5287
|
+
})]
|
|
5288
|
+
}, index)),
|
|
5289
|
+
preview !== null && /* @__PURE__ */ jsxs("div", {
|
|
5290
|
+
className: "wa-template__preview",
|
|
5291
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
5292
|
+
className: "wa-template__preview-tag",
|
|
5293
|
+
children: ["Plantilla · ", template.name]
|
|
5294
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
5295
|
+
className: "wa-template__preview-body",
|
|
5296
|
+
children: preview
|
|
5297
|
+
})]
|
|
5298
|
+
}),
|
|
5299
|
+
start.sendState === "error" && start.failure !== null && /* @__PURE__ */ jsxs("div", {
|
|
5300
|
+
className: "wa-template__error",
|
|
5301
|
+
role: "alert",
|
|
5302
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
5303
|
+
className: "wa-template__error-text",
|
|
5304
|
+
children: sendFailureCopy(start.failure)
|
|
5305
|
+
}), start.failure.retryable && /* @__PURE__ */ jsx("button", {
|
|
5306
|
+
type: "button",
|
|
5307
|
+
className: "wa-template__retry",
|
|
5308
|
+
onClick: submit,
|
|
5309
|
+
children: "Reintentar"
|
|
5310
|
+
})]
|
|
5311
|
+
}),
|
|
5312
|
+
start.sendState === "sent" && /* @__PURE__ */ jsx("p", {
|
|
5313
|
+
className: "wa-template__sent",
|
|
5314
|
+
role: "status",
|
|
5315
|
+
children: "Plantilla enviada. El bot quedó en pausa."
|
|
5316
|
+
}),
|
|
5317
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5318
|
+
className: "wa-template__footer",
|
|
5319
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
5320
|
+
className: "wa-template__hint",
|
|
5321
|
+
children: "Se envía a tu nombre · pausa el bot"
|
|
5322
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
5323
|
+
type: "submit",
|
|
5324
|
+
className: "wa-composer__send",
|
|
5325
|
+
disabled: !canSend,
|
|
5326
|
+
children: sending ? "Enviando…" : "Enviar plantilla"
|
|
5327
|
+
})]
|
|
5328
|
+
})
|
|
5329
|
+
]
|
|
5330
|
+
})
|
|
5331
|
+
]
|
|
5332
|
+
});
|
|
5333
|
+
}
|
|
5334
|
+
//#endregion
|
|
5335
|
+
//#region src/core/thread/useTemplateStart.ts
|
|
5336
|
+
/**
|
|
5337
|
+
* El estado de «Iniciar con plantilla» (DEV-8758): la lista de plantillas del número y el envío.
|
|
5338
|
+
*
|
|
5339
|
+
* Mismo molde que `useThread`/`useComposer` (DEC-G): lo cargado se guarda JUNTO con de qué
|
|
5340
|
+
* consulta vino (`fetcher` + `phone`), y "estoy pidiendo otra cosa" se DERIVA en el render — nada
|
|
5341
|
+
* de `setState` síncrono dentro de un efecto.
|
|
5342
|
+
*
|
|
5343
|
+
* La lista se pide sólo con `active` (ventana cerrada con permiso de escritura, o sin hilo): con la
|
|
5344
|
+
* ventana abierta no hay por qué molestar al store.
|
|
5345
|
+
*
|
|
5346
|
+
* 🔴 Sin `console.*`: los parámetros llevan el nombre del lifter y el teléfono es dato personal.
|
|
5347
|
+
*/
|
|
5348
|
+
function useTemplateStart({ fetcher, phone, active, onStarted }) {
|
|
5349
|
+
const [attempt, setAttempt] = useState(0);
|
|
5350
|
+
const [loaded, setLoaded] = useState(null);
|
|
5351
|
+
const [outcome, setOutcome] = useState(null);
|
|
5352
|
+
const onStartedRef = useRef(onStarted);
|
|
5353
|
+
useEffect(() => {
|
|
5354
|
+
onStartedRef.current = onStarted;
|
|
5355
|
+
}, [onStarted]);
|
|
5356
|
+
useEffect(() => {
|
|
5357
|
+
if (!active) return;
|
|
5358
|
+
const controller = new AbortController();
|
|
5359
|
+
loadTemplates(fetcher, { signal: controller.signal }).then((response) => {
|
|
5360
|
+
if (controller.signal.aborted) return;
|
|
5361
|
+
setLoaded({
|
|
5362
|
+
fetcher,
|
|
5363
|
+
phone,
|
|
5364
|
+
attempt,
|
|
5365
|
+
response,
|
|
5366
|
+
failed: false
|
|
5367
|
+
});
|
|
5368
|
+
}, () => {
|
|
5369
|
+
if (controller.signal.aborted) return;
|
|
5370
|
+
setLoaded({
|
|
5371
|
+
fetcher,
|
|
5372
|
+
phone,
|
|
5373
|
+
attempt,
|
|
5374
|
+
response: null,
|
|
5375
|
+
failed: true
|
|
5376
|
+
});
|
|
5377
|
+
});
|
|
5378
|
+
return () => controller.abort();
|
|
5379
|
+
}, [
|
|
5380
|
+
active,
|
|
5381
|
+
fetcher,
|
|
5382
|
+
phone,
|
|
5383
|
+
attempt
|
|
5384
|
+
]);
|
|
5385
|
+
const current = loaded !== null && loaded.fetcher === fetcher && loaded.phone === phone && loaded.attempt === attempt ? loaded : null;
|
|
5386
|
+
let templates;
|
|
5387
|
+
if (!active) templates = { status: "idle" };
|
|
5388
|
+
else if (current === null) templates = { status: "loading" };
|
|
5389
|
+
else if (current.failed || current.response === null) templates = { status: "error" };
|
|
5390
|
+
else templates = {
|
|
5391
|
+
status: "ready",
|
|
5392
|
+
canStart: current.response.can_start,
|
|
5393
|
+
itemCount: current.response.items.length
|
|
5394
|
+
};
|
|
5395
|
+
const currentOutcome = outcome !== null && outcome.fetcher === fetcher && outcome.phone === phone ? outcome : null;
|
|
5396
|
+
const send = useCallback((templateName, language, bodyParams) => {
|
|
5397
|
+
const clientMessageId = newClientMessageId();
|
|
5398
|
+
setOutcome({
|
|
5399
|
+
fetcher,
|
|
5400
|
+
phone,
|
|
5401
|
+
state: "sending",
|
|
5402
|
+
failure: null
|
|
5403
|
+
});
|
|
5404
|
+
startConversation(fetcher, {
|
|
5405
|
+
phone,
|
|
5406
|
+
templateName,
|
|
5407
|
+
language,
|
|
5408
|
+
bodyParams: bodyParams.map((value) => value.trim()),
|
|
5409
|
+
clientMessageId
|
|
5410
|
+
}).then(() => {
|
|
5411
|
+
setOutcome({
|
|
5412
|
+
fetcher,
|
|
5413
|
+
phone,
|
|
5414
|
+
state: "sent",
|
|
5415
|
+
failure: null
|
|
5416
|
+
});
|
|
5417
|
+
onStartedRef.current?.();
|
|
5418
|
+
}, (cause) => {
|
|
5419
|
+
setOutcome({
|
|
5420
|
+
fetcher,
|
|
5421
|
+
phone,
|
|
5422
|
+
state: "error",
|
|
5423
|
+
failure: readSendError(cause)
|
|
5424
|
+
});
|
|
5425
|
+
});
|
|
5426
|
+
}, [fetcher, phone]);
|
|
5427
|
+
const reloadTemplates = useCallback(() => setAttempt((value) => value + 1), []);
|
|
5428
|
+
return {
|
|
5429
|
+
templates,
|
|
5430
|
+
response: templates.status === "ready" && current !== null ? current.response : null,
|
|
5431
|
+
sendState: currentOutcome?.state ?? "idle",
|
|
5432
|
+
failure: currentOutcome?.failure ?? null,
|
|
5433
|
+
send,
|
|
5434
|
+
reloadTemplates
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5437
|
+
//#endregion
|
|
4866
5438
|
//#region src/core/thread/useThread.ts
|
|
4867
5439
|
/**
|
|
4868
5440
|
* El estado del hilo de conversación: pide el hilo por el `fetcher` del host y sostiene los estados
|
|
@@ -5391,7 +5963,7 @@ function firstName(takenBy) {
|
|
|
5391
5963
|
const first = typeof takenBy === "string" ? takenBy.trim().split(/\s+/)[0] : "";
|
|
5392
5964
|
return first !== void 0 && first !== "" ? first : "Otra persona";
|
|
5393
5965
|
}
|
|
5394
|
-
function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, saveDocument, className }) {
|
|
5966
|
+
function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, saveDocument, senderLabel = null, className }) {
|
|
5395
5967
|
const { messages: serverMessages, status, error, windowState, canReply, takenBy, takenUntil, takenByMe, takenAt, takenByRole, hasOlder, loadOlder, retry, refresh } = useThread({
|
|
5396
5968
|
fetcher,
|
|
5397
5969
|
phone,
|
|
@@ -5529,6 +6101,33 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, sa
|
|
|
5529
6101
|
* se ofrece; el bloqueo por ventana sigue mandando.
|
|
5530
6102
|
*/
|
|
5531
6103
|
const hasComposer = canReply && composer.windowState !== "closed";
|
|
6104
|
+
/**
|
|
6105
|
+
* DEV-8758 — «Iniciar con plantilla». Sin hilo (el 404 genérico del store) o con la ventana
|
|
6106
|
+
* cerrada y permiso de escritura, WhatsApp sólo deja escribir con una plantilla. Tras el envío el
|
|
6107
|
+
* hilo se vuelve a leer: sin hilo, entero (`retry`, ahora sí existe); con hilo, el latido
|
|
6108
|
+
* (`refresh`), que trae la burbuja y la barra «Bot en pausa».
|
|
6109
|
+
*/
|
|
6110
|
+
const noThread = status === "error" && serverMessages.length === 0 && isNoThreadError(error);
|
|
6111
|
+
const templateStart = useTemplateStart({
|
|
6112
|
+
fetcher,
|
|
6113
|
+
phone,
|
|
6114
|
+
active: noThread || canReply && composer.windowState === "closed",
|
|
6115
|
+
onStarted: noThread ? retry : refresh
|
|
6116
|
+
});
|
|
6117
|
+
const offer = templateOffer({
|
|
6118
|
+
noThread,
|
|
6119
|
+
windowState: composer.windowState,
|
|
6120
|
+
canReply,
|
|
6121
|
+
templates: templateStart.templates
|
|
6122
|
+
});
|
|
6123
|
+
const templatePanel = offer === "none" ? null : /* @__PURE__ */ jsx(TemplateStartPanel, {
|
|
6124
|
+
mode: offer,
|
|
6125
|
+
start: templateStart,
|
|
6126
|
+
noThread,
|
|
6127
|
+
phone,
|
|
6128
|
+
contactName: typeof displayName === "string" && displayName.trim() !== "" ? displayName : null,
|
|
6129
|
+
senderLabel
|
|
6130
|
+
});
|
|
5532
6131
|
const messagesRef = useRef(null);
|
|
5533
6132
|
/** De qué consulta ya se hizo el scroll inicial: una vez por hilo, no en cada página. */
|
|
5534
6133
|
const scrolledForRef = useRef(null);
|
|
@@ -5587,7 +6186,7 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, sa
|
|
|
5587
6186
|
className: "wa-thread__note",
|
|
5588
6187
|
children: "Cargando conversación…"
|
|
5589
6188
|
}),
|
|
5590
|
-
error !== null && /* @__PURE__ */ jsxs("div", {
|
|
6189
|
+
error !== null && !noThread && /* @__PURE__ */ jsxs("div", {
|
|
5591
6190
|
className: "wa-thread__error",
|
|
5592
6191
|
role: "alert",
|
|
5593
6192
|
children: [/* @__PURE__ */ jsxs("p", { children: ["No se pudo cargar la conversación: ", error.message] }), /* @__PURE__ */ jsx("button", {
|
|
@@ -5602,70 +6201,87 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, sa
|
|
|
5602
6201
|
}),
|
|
5603
6202
|
/* @__PURE__ */ jsxs("div", {
|
|
5604
6203
|
className: "wa-thread__header",
|
|
5605
|
-
children: [
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
className: "wa-thread__avatar",
|
|
5609
|
-
"aria-hidden": "true",
|
|
5610
|
-
children: initials(name, phone)
|
|
5611
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
5612
|
-
className: "wa-thread__who",
|
|
6204
|
+
children: [
|
|
6205
|
+
/* @__PURE__ */ jsxs("div", {
|
|
6206
|
+
className: "wa-thread__identity",
|
|
5613
6207
|
children: [/* @__PURE__ */ jsx("span", {
|
|
5614
|
-
className: "wa-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
6208
|
+
className: "wa-thread__avatar",
|
|
6209
|
+
"aria-hidden": "true",
|
|
6210
|
+
children: initials(name, phone)
|
|
6211
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
6212
|
+
className: "wa-thread__who",
|
|
6213
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
6214
|
+
className: "wa-thread__name",
|
|
6215
|
+
children: name ?? phone
|
|
6216
|
+
}), name !== null && /* @__PURE__ */ jsx("span", {
|
|
6217
|
+
className: "wa-thread__phone",
|
|
6218
|
+
children: phone
|
|
6219
|
+
})]
|
|
5619
6220
|
})]
|
|
5620
|
-
})
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
6221
|
+
}),
|
|
6222
|
+
noThread && /* @__PURE__ */ jsx("div", {
|
|
6223
|
+
className: "wa-thread__chips",
|
|
6224
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
6225
|
+
className: "wa-thread__step",
|
|
6226
|
+
children: "Sin conversación"
|
|
6227
|
+
})
|
|
6228
|
+
}),
|
|
6229
|
+
currentStep !== null && /* @__PURE__ */ jsx("div", {
|
|
6230
|
+
className: "wa-thread__chips",
|
|
6231
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
6232
|
+
className: "wa-thread__step",
|
|
6233
|
+
title: currentStep,
|
|
6234
|
+
children: ["Paso: ", serviceStateLabel(currentStep)]
|
|
6235
|
+
})
|
|
5627
6236
|
})
|
|
5628
|
-
|
|
6237
|
+
]
|
|
5629
6238
|
}),
|
|
5630
6239
|
/* @__PURE__ */ jsxs("div", {
|
|
5631
6240
|
className: "wa-thread__messages",
|
|
5632
6241
|
ref: messagesRef,
|
|
5633
|
-
children: [
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
children:
|
|
5645
|
-
}),
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
6242
|
+
children: [
|
|
6243
|
+
noThread && /* @__PURE__ */ jsx("p", {
|
|
6244
|
+
className: "wa-thread__note",
|
|
6245
|
+
children: "Todavía no hay conversación con este número."
|
|
6246
|
+
}),
|
|
6247
|
+
hasOlder && /* @__PURE__ */ jsx("button", {
|
|
6248
|
+
ref: sentinel,
|
|
6249
|
+
type: "button",
|
|
6250
|
+
className: "wa-thread__older",
|
|
6251
|
+
onClick: handleLoadOlder,
|
|
6252
|
+
disabled: status === "loading-older",
|
|
6253
|
+
children: status === "loading-older" ? "Cargando…" : "Cargar mensajes anteriores"
|
|
6254
|
+
}),
|
|
6255
|
+
groups.map((group, groupIndex) => /* @__PURE__ */ jsxs("div", {
|
|
6256
|
+
className: "wa-thread__group",
|
|
6257
|
+
children: [group.label !== null && /* @__PURE__ */ jsx("div", {
|
|
6258
|
+
className: "wa-thread__day",
|
|
6259
|
+
children: group.label
|
|
6260
|
+
}), group.items.map(({ message, position }) => /* @__PURE__ */ jsxs(Fragment, { children: [showServiceState[position] && typeof message.service_state === "string" && message.service_state !== "" && /* @__PURE__ */ jsxs("div", {
|
|
6261
|
+
className: "wa-thread__flow-pill",
|
|
6262
|
+
children: ["El flujo pasó a ", serviceStateLabel(message.service_state)]
|
|
6263
|
+
}), isSuggestion(message) ? /* @__PURE__ */ jsx(SuggestionBubble, {
|
|
6264
|
+
message,
|
|
6265
|
+
canDiscard: canReply,
|
|
6266
|
+
state: suggestion.state,
|
|
6267
|
+
error: suggestion.error,
|
|
6268
|
+
onDiscard: suggestion.discard,
|
|
6269
|
+
canUse: canReply && composer.windowState !== "closed",
|
|
6270
|
+
armed: suggestion.armed,
|
|
6271
|
+
onUse: suggestion.use,
|
|
6272
|
+
onDisarm: suggestion.disarm
|
|
6273
|
+
}) : /* @__PURE__ */ jsx(MessageBubble, {
|
|
5664
6274
|
message,
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
6275
|
+
optimistic: optimistic.has(message),
|
|
6276
|
+
fetcher,
|
|
6277
|
+
savedDocument: savedDocumentMark(message, saveDocument),
|
|
6278
|
+
onSaveAsDocument: canSaveAsDocument(message, saveDocument) ? () => setSaveTarget({
|
|
6279
|
+
message,
|
|
6280
|
+
phone
|
|
6281
|
+
}) : void 0
|
|
6282
|
+
})] }, message.id ?? `sin-wamid-${position}`))]
|
|
6283
|
+
}, group.key ?? `sin-dia-${groupIndex}`))
|
|
6284
|
+
]
|
|
5669
6285
|
}),
|
|
5670
6286
|
/* @__PURE__ */ jsx(TakeoverBar, {
|
|
5671
6287
|
takenBy,
|
|
@@ -5685,7 +6301,12 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, sa
|
|
|
5685
6301
|
prefill,
|
|
5686
6302
|
locked: foreignLive && !unlocked,
|
|
5687
6303
|
takeoverNotice: foreignLive && unlocked ? `${firstName(takenBy)} está atendiendo · el lifter verá a dos personas` : null,
|
|
5688
|
-
focusRequest: unlocked && writeAnyway !== null ? writeAnyway.focus : null
|
|
6304
|
+
focusRequest: unlocked && writeAnyway !== null ? writeAnyway.focus : null,
|
|
6305
|
+
templateStart: !noThread && offer === "form" ? templatePanel : null
|
|
6306
|
+
}),
|
|
6307
|
+
noThread && templatePanel !== null && /* @__PURE__ */ jsx("div", {
|
|
6308
|
+
className: "wa-composer wa-composer--template",
|
|
6309
|
+
children: templatePanel
|
|
5689
6310
|
}),
|
|
5690
6311
|
showSaveDialog && saveDocument !== void 0 && saveTarget !== null && /* @__PURE__ */ jsx(SaveDocumentDialog, {
|
|
5691
6312
|
message: saveTarget.message,
|
|
@@ -5780,7 +6401,7 @@ const SHELL_CSS = `
|
|
|
5780
6401
|
color: #8A91A0;
|
|
5781
6402
|
}
|
|
5782
6403
|
`;
|
|
5783
|
-
function WaConversations({ fetcher, initialPhone, pinned = false, refreshIntervalMs, saveDocument, className }) {
|
|
6404
|
+
function WaConversations({ fetcher, initialPhone, pinned = false, refreshIntervalMs, saveDocument, contactName, senderLabel, className }) {
|
|
5784
6405
|
/**
|
|
5785
6406
|
* El layout lo decide el ancho de ESTE contenedor, no el del viewport: el visor va embebido
|
|
5786
6407
|
* (en lms-web-app vive dentro del layout del LMS, no a pantalla completa).
|
|
@@ -5801,7 +6422,7 @@ function WaConversations({ fetcher, initialPhone, pinned = false, refreshInterva
|
|
|
5801
6422
|
* `initialPhone` siembra SÓLO el teléfono: sin summary no hay nombre que sembrar y no se
|
|
5802
6423
|
* inventa uno. El header cae al teléfono, como la fila de la lista.
|
|
5803
6424
|
*/
|
|
5804
|
-
const [selectedName, setSelectedName] = useState(null);
|
|
6425
|
+
const [selectedName, setSelectedName] = useState(initialPhone !== void 0 && typeof contactName === "string" && contactName.trim() !== "" ? contactName : null);
|
|
5805
6426
|
const rootClass = className ? `wa-conversations ${className}` : "wa-conversations";
|
|
5806
6427
|
if (fetcher === void 0) return /* @__PURE__ */ jsx("div", {
|
|
5807
6428
|
className: rootClass,
|
|
@@ -5838,7 +6459,8 @@ function WaConversations({ fetcher, initialPhone, pinned = false, refreshInterva
|
|
|
5838
6459
|
phone: selectedPhone,
|
|
5839
6460
|
displayName: selectedName,
|
|
5840
6461
|
refreshIntervalMs,
|
|
5841
|
-
saveDocument: anchored ? saveDocument : void 0
|
|
6462
|
+
saveDocument: anchored ? saveDocument : void 0,
|
|
6463
|
+
senderLabel: senderLabel ?? null
|
|
5842
6464
|
})]
|
|
5843
6465
|
}) : layout === "wide" && /* @__PURE__ */ jsx("p", {
|
|
5844
6466
|
className: "wa-conversations__empty",
|
|
@@ -5868,4 +6490,4 @@ const WA_CONVERSATIONS_TAG = "wa-conversations";
|
|
|
5868
6490
|
*/
|
|
5869
6491
|
const SAVE_DOCUMENT_EVENT = "wa-conversations:save-document";
|
|
5870
6492
|
//#endregion
|
|
5871
|
-
export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SAVE_DOCUMENT_EVENT, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, dedupeByWamid, discardSuggestion, isCtaLink, isSuggestion, loadConversations, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeWindowState, readSendError, releaseConversation, sendFailureCopy, sendReply, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
|
|
6493
|
+
export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SAVE_DOCUMENT_EVENT, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, dedupeByWamid, discardSuggestion, isCtaLink, isNoThreadError, isSuggestion, loadConversations, loadTemplates, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeStartResponse, normalizeTemplates, normalizeWindowState, readSendError, releaseConversation, renderTemplatePreview, sendFailureCopy, sendReply, startConversation, templateOffer, templateParamsValid, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
|