@fayz-ai/plugin-conversations 0.34.0 → 0.35.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/dist/{ConversationsPage-32XXQKCP.js → ConversationsPage-AV34J5DY.js} +66 -64
- package/dist/ConversationsPage-AV34J5DY.js.map +1 -0
- package/dist/chunk-NWH5AIUH.js +322 -0
- package/dist/chunk-NWH5AIUH.js.map +1 -0
- package/dist/components/Composer.d.ts +4 -1
- package/dist/components/Composer.d.ts.map +1 -1
- package/dist/index.js +3 -223
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +2 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +33 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/views/ConversationList.d.ts.map +1 -1
- package/dist/views/MessageThread.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/ConversationsPage-32XXQKCP.js.map +0 -1
- package/dist/chunk-OJ3Q4S5Y.js +0 -102
- package/dist/chunk-OJ3Q4S5Y.js.map +0 -1
- package/dist/views/WhatsAppConnectionFooter.d.ts +0 -8
- package/dist/views/WhatsAppConnectionFooter.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isWaitingOnUs, assinarChegada, ConversationsContextProvider, MessagePreview, useConversationsStore } from './chunk-
|
|
2
|
-
export { isWaitingOnUs } from './chunk-
|
|
1
|
+
import { createConversationsStore, isWaitingOnUs, assinarChegada, ConversationsContextProvider, MessagePreview, useConversationsStore } from './chunk-NWH5AIUH.js';
|
|
2
|
+
export { isWaitingOnUs } from './chunk-NWH5AIUH.js';
|
|
3
3
|
import { T, listMessagingChannels, findDedicatedChannel, findFallbackChannel, isPendingChannelStatus, canClaimDedicated, CHANNEL_CLAIM_TIMELINE } from './chunk-W5VV6G35.js';
|
|
4
4
|
export { listMessagingChannels } from './chunk-W5VV6G35.js';
|
|
5
5
|
import { providersApi } from './chunk-HMWUU5O7.js';
|
|
@@ -12,7 +12,6 @@ import { defineSettingsTab, SettingsGroup, useNavContribution, playChime, notify
|
|
|
12
12
|
import { Input, Button, toast, defineKpiWidget, defineTableWidget, KpiCard, TableWidget } from '@fayz-ai/ui';
|
|
13
13
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
14
14
|
import { createConnectionStore, connectionRuns, connectionStatus, tl, lazyComponent, useActiveTenantId, registerTranslations, getSupabaseClientOptional, describeError, getActiveTenantId, countByTenant, CONNECTOR_RUNTIME_TOKEN_HEADER, connectorRuntimeToken, useTranslation, navigateApp } from '@fayz-ai/core';
|
|
15
|
-
import { createStore } from 'zustand/vanilla';
|
|
16
15
|
import { MIGRATIONS } from '#migrations/main';
|
|
17
16
|
|
|
18
17
|
var COPY = {
|
|
@@ -897,225 +896,6 @@ function createSupabaseConversationsProvider(config) {
|
|
|
897
896
|
}
|
|
898
897
|
};
|
|
899
898
|
}
|
|
900
|
-
var MEDIA_LIMIT_MB = { media: 16, document: 100 };
|
|
901
|
-
function toBase64(blob) {
|
|
902
|
-
return new Promise((resolve, reject) => {
|
|
903
|
-
const reader = new FileReader();
|
|
904
|
-
reader.onload = () => resolve(String(reader.result ?? "").replace(/^data:[^;]*;base64,/u, ""));
|
|
905
|
-
reader.onerror = () => reject(reader.error ?? new Error("N\xE3o foi poss\xEDvel ler o arquivo"));
|
|
906
|
-
reader.readAsDataURL(blob);
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
async function sendMedia(input) {
|
|
910
|
-
const client3 = getSupabaseClientOptional();
|
|
911
|
-
const tenantId = getActiveTenantId();
|
|
912
|
-
if (!client3 || !tenantId) throw new Error("Sem conex\xE3o com a casa");
|
|
913
|
-
const mimetype = input.file.type || "application/octet-stream";
|
|
914
|
-
const isDoc = !/^(image|video|audio)\//u.test(mimetype);
|
|
915
|
-
const limit = (isDoc ? MEDIA_LIMIT_MB.document : MEDIA_LIMIT_MB.media) * 1024 * 1024;
|
|
916
|
-
if (input.file.size > limit) throw new Error(`Arquivo maior que ${isDoc ? MEDIA_LIMIT_MB.document : MEDIA_LIMIT_MB.media} MB, o limite do WhatsApp`);
|
|
917
|
-
const data = await toBase64(input.file);
|
|
918
|
-
const { data: out, error } = await client3.functions.invoke("conversations-provider", {
|
|
919
|
-
body: {
|
|
920
|
-
tenantId,
|
|
921
|
-
action: "send_media",
|
|
922
|
-
conversationId: input.conversationId,
|
|
923
|
-
data,
|
|
924
|
-
mimetype,
|
|
925
|
-
fileName: input.fileName ?? input.file.name ?? null,
|
|
926
|
-
caption: input.caption ?? "",
|
|
927
|
-
ptt: input.ptt === true
|
|
928
|
-
}
|
|
929
|
-
});
|
|
930
|
-
if (error) {
|
|
931
|
-
const detail = await error.context?.json?.().catch(() => null);
|
|
932
|
-
throw new Error(detail?.message ?? error.message);
|
|
933
|
-
}
|
|
934
|
-
if (out?.error) throw new Error(out.message ?? out.error);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
// src/store.ts
|
|
938
|
-
async function currentUserId() {
|
|
939
|
-
try {
|
|
940
|
-
const sb = getSupabaseClientOptional();
|
|
941
|
-
const { data } = await sb?.auth?.getSession?.() ?? {};
|
|
942
|
-
return data?.session?.user?.id ?? null;
|
|
943
|
-
} catch {
|
|
944
|
-
return null;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
function handleKey(h) {
|
|
948
|
-
const v = (h ?? "").trim();
|
|
949
|
-
if (!v) return "";
|
|
950
|
-
return /[@a-z]/i.test(v) ? v.toLowerCase() : v.replace(/\D/g, "");
|
|
951
|
-
}
|
|
952
|
-
function createConversationsStore(provider) {
|
|
953
|
-
return createStore((set, get) => ({
|
|
954
|
-
conversations: [],
|
|
955
|
-
messages: [],
|
|
956
|
-
selectedId: null,
|
|
957
|
-
channelFilter: "all",
|
|
958
|
-
leadOwnerFilter: void 0,
|
|
959
|
-
search: "",
|
|
960
|
-
loading: false,
|
|
961
|
-
sending: false,
|
|
962
|
-
async load(opts) {
|
|
963
|
-
set({ loading: true });
|
|
964
|
-
const conversations = await provider.listConversations({
|
|
965
|
-
channel: get().channelFilter,
|
|
966
|
-
leadOwnerId: get().leadOwnerFilter,
|
|
967
|
-
search: get().search || void 0
|
|
968
|
-
});
|
|
969
|
-
const selectedId = get().selectedId ?? (opts?.autoSelect === false ? null : (conversations.find((c) => c.status !== "closed") ?? conversations[0])?.id ?? null);
|
|
970
|
-
set({ conversations, loading: false, selectedId });
|
|
971
|
-
if (selectedId) await get().select(selectedId);
|
|
972
|
-
},
|
|
973
|
-
/** Dar por vista sem abrir — o caso do "ok, obrigado" que não pede resposta. */
|
|
974
|
-
async markRead(id) {
|
|
975
|
-
await provider.markRead(id);
|
|
976
|
-
const agora = (/* @__PURE__ */ new Date()).toISOString();
|
|
977
|
-
set((s) => ({
|
|
978
|
-
conversations: s.conversations.map((c) => c.id === id ? { ...c, unreadCount: 0, acknowledgedAt: agora } : c)
|
|
979
|
-
}));
|
|
980
|
-
},
|
|
981
|
-
async select(id) {
|
|
982
|
-
set({ selectedId: id });
|
|
983
|
-
const messages = await provider.getMessages(id);
|
|
984
|
-
set({ messages });
|
|
985
|
-
const owner = get().conversations.find((c) => c.id === id)?.leadOwnerId;
|
|
986
|
-
if (owner && owner !== await currentUserId()) return;
|
|
987
|
-
await provider.markRead(id);
|
|
988
|
-
const agora = (/* @__PURE__ */ new Date()).toISOString();
|
|
989
|
-
set((s) => ({
|
|
990
|
-
conversations: s.conversations.map((c) => c.id === id ? { ...c, unreadCount: 0, acknowledgedAt: agora } : c)
|
|
991
|
-
}));
|
|
992
|
-
},
|
|
993
|
-
/** Relê as mensagens da conversa aberta, sem tocar em mais nada.
|
|
994
|
-
*
|
|
995
|
-
* O status de uma mensagem de WhatsApp muda DEPOIS do envio — entregue,
|
|
996
|
-
* lida, às vezes minutos depois — e quem avisa é o webhook, que escreve no
|
|
997
|
-
* banco sem a tela saber. Sem isto a caixa mostra para sempre o status do
|
|
998
|
-
* instante do envio: um tique só, numa mensagem que já foi lida.
|
|
999
|
-
*
|
|
1000
|
-
* Não usa `select()` de propósito: aquele marca a conversa como lida e
|
|
1001
|
-
* zera o contador, e uma releitura de fundo não é um gesto de ninguém. */
|
|
1002
|
-
async refreshMessages() {
|
|
1003
|
-
const id = get().selectedId;
|
|
1004
|
-
if (!id) return;
|
|
1005
|
-
try {
|
|
1006
|
-
const messages = await provider.getMessages(id);
|
|
1007
|
-
const before = get().messages;
|
|
1008
|
-
const same = before.length === messages.length && before.every((m, i) => m.id === messages[i].id && m.deliveryStatus === messages[i].deliveryStatus);
|
|
1009
|
-
if (!same) set({ messages });
|
|
1010
|
-
} catch {
|
|
1011
|
-
}
|
|
1012
|
-
},
|
|
1013
|
-
deselect() {
|
|
1014
|
-
set({ selectedId: null, messages: [] });
|
|
1015
|
-
},
|
|
1016
|
-
async setLeadOwnerFilter(ownerId) {
|
|
1017
|
-
set({ leadOwnerFilter: ownerId });
|
|
1018
|
-
await get().load();
|
|
1019
|
-
},
|
|
1020
|
-
async setChannelFilter(channel) {
|
|
1021
|
-
set({ channelFilter: channel });
|
|
1022
|
-
await get().load();
|
|
1023
|
-
},
|
|
1024
|
-
async setSearch(search) {
|
|
1025
|
-
set({ search });
|
|
1026
|
-
await get().load();
|
|
1027
|
-
},
|
|
1028
|
-
async create(input) {
|
|
1029
|
-
const created = await provider.createConversation(input);
|
|
1030
|
-
set((s) => ({
|
|
1031
|
-
channelFilter: "all",
|
|
1032
|
-
search: "",
|
|
1033
|
-
conversations: [created, ...s.conversations.filter((c) => c.id !== created.id)],
|
|
1034
|
-
selectedId: created.id
|
|
1035
|
-
}));
|
|
1036
|
-
void (async () => {
|
|
1037
|
-
try {
|
|
1038
|
-
const conversations = await provider.listConversations({});
|
|
1039
|
-
const merged = conversations.some((c) => c.id === created.id) ? conversations : [created, ...conversations];
|
|
1040
|
-
set({ conversations: merged });
|
|
1041
|
-
await get().select(created.id);
|
|
1042
|
-
} catch {
|
|
1043
|
-
}
|
|
1044
|
-
})();
|
|
1045
|
-
return created;
|
|
1046
|
-
},
|
|
1047
|
-
// Chegar aqui vindo de fora — da ficha de um lead, por exemplo — não pode
|
|
1048
|
-
// criar uma segunda thread com alguém com quem a casa já conversa. Procura
|
|
1049
|
-
// primeiro pela PESSOA, e só então pelo telefone: o vínculo é a verdade, e
|
|
1050
|
-
// o handle é o que resgata threads criadas antes de o vínculo existir.
|
|
1051
|
-
async openForPerson({ personId, name, handle, channel }) {
|
|
1052
|
-
if (get().conversations.length === 0 && !get().loading) {
|
|
1053
|
-
try {
|
|
1054
|
-
await get().load();
|
|
1055
|
-
} catch {
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
const key = handleKey(handle);
|
|
1059
|
-
const existing = get().conversations.find((c) => c.channel === channel && (personId && c.contactPersonId === personId || key !== "" && handleKey(c.contactHandle) === key));
|
|
1060
|
-
if (existing) {
|
|
1061
|
-
set({ channelFilter: "all", search: "" });
|
|
1062
|
-
await get().select(existing.id);
|
|
1063
|
-
return existing;
|
|
1064
|
-
}
|
|
1065
|
-
return get().create({
|
|
1066
|
-
contactName: name,
|
|
1067
|
-
contactPersonId: personId,
|
|
1068
|
-
contactHandle: handle,
|
|
1069
|
-
channel
|
|
1070
|
-
});
|
|
1071
|
-
},
|
|
1072
|
-
async sendMedia(input) {
|
|
1073
|
-
const id = get().selectedId;
|
|
1074
|
-
if (!id) return;
|
|
1075
|
-
set({ sending: true });
|
|
1076
|
-
try {
|
|
1077
|
-
await sendMedia({ conversationId: id, ...input });
|
|
1078
|
-
} finally {
|
|
1079
|
-
set({ sending: false });
|
|
1080
|
-
await get().refreshMessages();
|
|
1081
|
-
}
|
|
1082
|
-
},
|
|
1083
|
-
async send(body) {
|
|
1084
|
-
const id = get().selectedId;
|
|
1085
|
-
if (!id || !body.trim()) return;
|
|
1086
|
-
set({ sending: true });
|
|
1087
|
-
const created = await provider.sendMessage({ conversationId: id, body: body.trim() });
|
|
1088
|
-
set((s) => ({
|
|
1089
|
-
sending: false,
|
|
1090
|
-
messages: [...s.messages, created],
|
|
1091
|
-
conversations: s.conversations.map(
|
|
1092
|
-
(c) => (
|
|
1093
|
-
// `lastMessageDirection` acompanha a prévia, senão a fila mente. O
|
|
1094
|
-
// gatilho da migration 001 carimba a coluna no banco, mas a lista só
|
|
1095
|
-
// volta a ler no próximo `load()` — e até lá a thread que ACABOU de
|
|
1096
|
-
// ser respondida continua em "esperando nós", que é exatamente a
|
|
1097
|
-
// pergunta que essa coluna existe para responder.
|
|
1098
|
-
//
|
|
1099
|
-
// Antes da 001 isto não aparecia: a coluna vinha sempre indefinida e
|
|
1100
|
-
// `isWaitingOnUs` caía no `unreadCount`. A migration não criou o
|
|
1101
|
-
// defeito, tornou-o visível.
|
|
1102
|
-
c.id === id ? { ...c, lastMessagePreview: created.body, lastMessageAt: created.at, lastMessageDirection: "outbound" } : c
|
|
1103
|
-
)
|
|
1104
|
-
)
|
|
1105
|
-
}));
|
|
1106
|
-
},
|
|
1107
|
-
async setStatus(status) {
|
|
1108
|
-
const id = get().selectedId;
|
|
1109
|
-
if (!id) return;
|
|
1110
|
-
const updated = await provider.setStatus(id, status);
|
|
1111
|
-
set((s) => ({
|
|
1112
|
-
conversations: s.conversations.map((c) => c.id === id ? updated : c),
|
|
1113
|
-
// An archived conversation leaves the inbox, so it stops being the open one.
|
|
1114
|
-
...status === "closed" ? { selectedId: null } : {}
|
|
1115
|
-
}));
|
|
1116
|
-
}
|
|
1117
|
-
}));
|
|
1118
|
-
}
|
|
1119
899
|
|
|
1120
900
|
// src/locales/en.ts
|
|
1121
901
|
var en = {
|
|
@@ -2458,7 +2238,7 @@ function createConversationsPlugin(options) {
|
|
|
2458
2238
|
locales: conversationsLocales
|
|
2459
2239
|
};
|
|
2460
2240
|
}
|
|
2461
|
-
var ConversationsPage = React__default.lazy(() => import('./ConversationsPage-
|
|
2241
|
+
var ConversationsPage = React__default.lazy(() => import('./ConversationsPage-AV34J5DY.js').then((m) => ({ default: m.ConversationsPage })));
|
|
2462
2242
|
var AtendeAIPage = React__default.lazy(() => import('./AtendeAIPage-PBBMWIDW.js').then((m) => ({ default: m.AtendeAIPage })));
|
|
2463
2243
|
var ConversationsSettingsTab = lazyComponent(() => import('./ConversationsSettings-GORCWUHD.js').then((m) => m.ConversationsSettingsTab));
|
|
2464
2244
|
var CampaignsSurface = React__default.lazy(() => import('./CampaignsSurface-2LT24KSS.js').then((m) => ({ default: m.CampaignsSurface })));
|