@baseportal/chat-widget 0.1.1 → 0.1.3
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/index.cjs.js +27 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +27 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +5 -5
- package/dist/index.iife.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -79,6 +79,9 @@ var ApiClient = class {
|
|
|
79
79
|
channelToken: this.channelToken
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
async getConversation(conversationId) {
|
|
83
|
+
return this.request("GET", `/conversations/${conversationId}`);
|
|
84
|
+
}
|
|
82
85
|
async getMessages(conversationId, params) {
|
|
83
86
|
const qs = new URLSearchParams();
|
|
84
87
|
if (params?.limit) qs.set("limit", String(params.limit));
|
|
@@ -199,6 +202,7 @@ var pt = {
|
|
|
199
202
|
placeholder: "Digite uma mensagem...",
|
|
200
203
|
closed: "Esta conversa foi encerrada.",
|
|
201
204
|
reopen: "Reabrir conversa",
|
|
205
|
+
newConversation: "Nova conversa",
|
|
202
206
|
attachFile: "Anexar arquivo",
|
|
203
207
|
uploading: "Enviando...",
|
|
204
208
|
fileTooLarge: "Arquivo muito grande (m\xE1x. 25MB)",
|
|
@@ -230,6 +234,7 @@ var en = {
|
|
|
230
234
|
placeholder: "Type a message...",
|
|
231
235
|
closed: "This conversation has been closed.",
|
|
232
236
|
reopen: "Reopen conversation",
|
|
237
|
+
newConversation: "New conversation",
|
|
233
238
|
attachFile: "Attach file",
|
|
234
239
|
uploading: "Uploading...",
|
|
235
240
|
fileTooLarge: "File too large (max 25MB)",
|
|
@@ -261,6 +266,7 @@ var es = {
|
|
|
261
266
|
placeholder: "Escribe un mensaje...",
|
|
262
267
|
closed: "Esta conversaci\xF3n ha sido cerrada.",
|
|
263
268
|
reopen: "Reabrir conversaci\xF3n",
|
|
269
|
+
newConversation: "Nueva conversaci\xF3n",
|
|
264
270
|
attachFile: "Adjuntar archivo",
|
|
265
271
|
uploading: "Subiendo...",
|
|
266
272
|
fileTooLarge: "Archivo demasiado grande (m\xE1x. 25MB)",
|
|
@@ -775,11 +781,14 @@ function ChatWindow({
|
|
|
775
781
|
const storedId = initialConversationId || storage.getConversationId();
|
|
776
782
|
if (storedId) {
|
|
777
783
|
try {
|
|
784
|
+
const conv = await apiClient.getConversation(storedId);
|
|
778
785
|
const msgs = await apiClient.getMessages(storedId, { limit: 50 });
|
|
779
786
|
setMessages(Array.isArray(msgs) ? msgs.reverse() : []);
|
|
780
|
-
setConversation(
|
|
787
|
+
setConversation(conv);
|
|
781
788
|
setView("chat");
|
|
782
|
-
|
|
789
|
+
if (conv.open) {
|
|
790
|
+
connectRealtime(storedId);
|
|
791
|
+
}
|
|
783
792
|
} catch {
|
|
784
793
|
storage.clear();
|
|
785
794
|
if (needsPreChat()) {
|
|
@@ -834,21 +843,6 @@ function ChatWindow({
|
|
|
834
843
|
);
|
|
835
844
|
if (!conv.open) {
|
|
836
845
|
events.emit("conversation:closed", conv);
|
|
837
|
-
setTimeout(() => {
|
|
838
|
-
realtimeClient.unsubscribe();
|
|
839
|
-
storage.clear();
|
|
840
|
-
setConversation(null);
|
|
841
|
-
setMessages([]);
|
|
842
|
-
if (allowViewHistory) {
|
|
843
|
-
apiClient.getVisitorConversations().then(setConversations).catch(() => {
|
|
844
|
-
});
|
|
845
|
-
setView("conversations");
|
|
846
|
-
} else if (needsPreChat()) {
|
|
847
|
-
setView("prechat");
|
|
848
|
-
} else {
|
|
849
|
-
startNewConversationRef.current();
|
|
850
|
-
}
|
|
851
|
-
}, 2e3);
|
|
852
846
|
}
|
|
853
847
|
}
|
|
854
848
|
});
|
|
@@ -984,6 +978,21 @@ function ChatWindow({
|
|
|
984
978
|
setSending(false);
|
|
985
979
|
}
|
|
986
980
|
}, [inputValue, uploadedFileId, conversation, sending, apiClient, events, realtimeClient, storage, allowViewHistory, needsPreChat]);
|
|
981
|
+
const handleNewConversation = (0, import_hooks5.useCallback)(async () => {
|
|
982
|
+
realtimeClient.unsubscribe();
|
|
983
|
+
storage.clear();
|
|
984
|
+
setConversation(null);
|
|
985
|
+
setMessages([]);
|
|
986
|
+
if (allowViewHistory) {
|
|
987
|
+
apiClient.getVisitorConversations().then(setConversations).catch(() => {
|
|
988
|
+
});
|
|
989
|
+
setView("conversations");
|
|
990
|
+
} else if (needsPreChat()) {
|
|
991
|
+
setView("prechat");
|
|
992
|
+
} else {
|
|
993
|
+
await startNewConversationRef.current();
|
|
994
|
+
}
|
|
995
|
+
}, [realtimeClient, storage, allowViewHistory, apiClient, needsPreChat]);
|
|
987
996
|
const handleReopen = (0, import_hooks5.useCallback)(async () => {
|
|
988
997
|
if (!conversation) return;
|
|
989
998
|
try {
|
|
@@ -1055,7 +1064,7 @@ function ChatWindow({
|
|
|
1055
1064
|
}
|
|
1056
1065
|
) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { class: "bp-closed-banner", children: [
|
|
1057
1066
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { class: "bp-closed-banner__text", children: t.chat.closed }),
|
|
1058
|
-
channelInfo.config.allowReopenConversation
|
|
1067
|
+
channelInfo.config.allowReopenConversation ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { class: "bp-closed-banner__reopen", onClick: handleReopen, children: t.chat.reopen }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { class: "bp-closed-banner__reopen", onClick: handleNewConversation, children: t.chat.newConversation })
|
|
1059
1068
|
] }),
|
|
1060
1069
|
channelInfo.config.privacyPolicyUrl && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { class: "bp-privacy-footer", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1061
1070
|
"a",
|