@axos-web-dev/shared-components 1.0.77-patch.40 → 1.0.77-patch.42
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/Chatbot/Chatbot.js +14 -2
- package/package.json +1 -1
package/dist/Chatbot/Chatbot.js
CHANGED
|
@@ -93,8 +93,6 @@ const Chatbot = ({
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
const registerEventHandlers = () => {
|
|
96
|
-
clientRef.current?.on("ready", onReadyHandler);
|
|
97
|
-
clientRef.current?.on("authenticated", onAuthenticatedHandler);
|
|
98
96
|
clientRef.current?.on("chat.ongoing", onChatOngoingHandler);
|
|
99
97
|
clientRef.current?.on("chat.message", onChatMessageHandler);
|
|
100
98
|
clientRef.current?.on("chat.typingStarted", onChatTypingStartedHandler);
|
|
@@ -133,6 +131,8 @@ const Chatbot = ({
|
|
|
133
131
|
// or your region
|
|
134
132
|
authenticate
|
|
135
133
|
});
|
|
134
|
+
client?.on("ready", onReadyHandler);
|
|
135
|
+
client?.on("authenticated", onAuthenticatedHandler);
|
|
136
136
|
isMountedRef.current = true;
|
|
137
137
|
clientRef.current = client;
|
|
138
138
|
menuRef.current = await client.getMenus();
|
|
@@ -144,6 +144,17 @@ const Chatbot = ({
|
|
|
144
144
|
console.log("Starting chat");
|
|
145
145
|
const client = clientRef.current;
|
|
146
146
|
if (!client) return;
|
|
147
|
+
if (!menuRef.current || !menuRef.current.menus) {
|
|
148
|
+
let waited = 0;
|
|
149
|
+
while ((!menuRef.current || !menuRef.current.menus) && waited < 2e3) {
|
|
150
|
+
await new Promise((res) => setTimeout(res, 100));
|
|
151
|
+
waited += 100;
|
|
152
|
+
}
|
|
153
|
+
if (!menuRef.current || !menuRef.current.menus) {
|
|
154
|
+
console.error("Menu not loaded, cannot start chat");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
147
158
|
try {
|
|
148
159
|
const ongoingChat = await client.loadOngoingChat();
|
|
149
160
|
if (ongoingChat) {
|
|
@@ -161,6 +172,7 @@ const Chatbot = ({
|
|
|
161
172
|
const newChat = await client.createChat(menuId, { custom_data });
|
|
162
173
|
if (newChat !== null) {
|
|
163
174
|
chatRef.current = newChat;
|
|
175
|
+
agent_virtual.current = newChat.agent;
|
|
164
176
|
console.log("Chat created id:", newChat.id);
|
|
165
177
|
}
|
|
166
178
|
} catch (err) {
|
package/package.json
CHANGED