@menuia/react 1.7.0 → 1.7.1
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -5
- package/dist/index.mjs +24 -5
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -34,7 +34,7 @@ interface MenuIAChatProps extends Omit<MenuIAConfig, 'widgetId' | 'agentId'> {
|
|
|
34
34
|
/** Show powered by MenuIA */
|
|
35
35
|
showPoweredBy?: boolean;
|
|
36
36
|
}
|
|
37
|
-
declare function MenuIAChat({ title, subtitle, avatar, primaryColor, theme, position, welcomeMessage, placeholder, defaultOpen, inline, width, height, showPoweredBy, widgetId, agentId, apiUrl, sessionId, customFields, metadata, channel, sessionToken, visitorName, visitorEmail, visitorPhone, onMessage, onStatusChange, onTicketCreated, onError, }: MenuIAChatProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
declare function MenuIAChat({ title, subtitle, avatar, primaryColor, theme, position, welcomeMessage, placeholder, defaultOpen, inline, width, height, showPoweredBy, widgetId, agentId, apiUrl, sessionId, customFields, metadata, channel, sessionToken, visitorName, visitorEmail, visitorPhone, onMessage, onStatusChange, onTicketCreated, onError, onSessionTokenExpired, }: MenuIAChatProps): react_jsx_runtime.JSX.Element;
|
|
38
38
|
|
|
39
39
|
interface UseMenuIAReturn {
|
|
40
40
|
messages: ChatMessage[];
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ interface MenuIAChatProps extends Omit<MenuIAConfig, 'widgetId' | 'agentId'> {
|
|
|
34
34
|
/** Show powered by MenuIA */
|
|
35
35
|
showPoweredBy?: boolean;
|
|
36
36
|
}
|
|
37
|
-
declare function MenuIAChat({ title, subtitle, avatar, primaryColor, theme, position, welcomeMessage, placeholder, defaultOpen, inline, width, height, showPoweredBy, widgetId, agentId, apiUrl, sessionId, customFields, metadata, channel, sessionToken, visitorName, visitorEmail, visitorPhone, onMessage, onStatusChange, onTicketCreated, onError, }: MenuIAChatProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
declare function MenuIAChat({ title, subtitle, avatar, primaryColor, theme, position, welcomeMessage, placeholder, defaultOpen, inline, width, height, showPoweredBy, widgetId, agentId, apiUrl, sessionId, customFields, metadata, channel, sessionToken, visitorName, visitorEmail, visitorPhone, onMessage, onStatusChange, onTicketCreated, onError, onSessionTokenExpired, }: MenuIAChatProps): react_jsx_runtime.JSX.Element;
|
|
38
38
|
|
|
39
39
|
interface UseMenuIAReturn {
|
|
40
40
|
messages: ChatMessage[];
|
package/dist/index.js
CHANGED
|
@@ -64,16 +64,30 @@ function useMenuIA(config) {
|
|
|
64
64
|
const [error, setError] = (0, import_react.useState)(null);
|
|
65
65
|
const [ticketId, setTicketId] = (0, import_react.useState)(null);
|
|
66
66
|
const [aiPaused, setAiPaused] = (0, import_react.useState)(false);
|
|
67
|
+
const configRef = (0, import_react.useRef)(config);
|
|
68
|
+
configRef.current = config;
|
|
67
69
|
(0, import_react.useEffect)(() => {
|
|
68
70
|
const client = new import_core.MenuIAClient({
|
|
69
71
|
...config,
|
|
70
|
-
onStatusChange: (s) =>
|
|
72
|
+
onStatusChange: (s) => {
|
|
73
|
+
setStatus(s);
|
|
74
|
+
configRef.current.onStatusChange?.(s);
|
|
75
|
+
},
|
|
71
76
|
onMessage: (msg) => {
|
|
72
77
|
if (vazia(msg)) return;
|
|
73
78
|
setMessages((prev) => mesmaMensagem(prev, msg) ? prev : [...prev, msg]);
|
|
79
|
+
configRef.current.onMessage?.(msg);
|
|
80
|
+
},
|
|
81
|
+
onTicketCreated: (id) => {
|
|
82
|
+
setTicketId(id);
|
|
83
|
+
configRef.current.onTicketCreated?.(id);
|
|
74
84
|
},
|
|
75
|
-
|
|
76
|
-
onError: (err) =>
|
|
85
|
+
// ⚠️ Antes o hook trocava os callbacks do app pelos dele: o onError do app nunca era chamado.
|
|
86
|
+
onError: (err) => {
|
|
87
|
+
setError(err.message);
|
|
88
|
+
configRef.current.onError?.(err);
|
|
89
|
+
},
|
|
90
|
+
onSessionTokenExpired: () => configRef.current.onSessionTokenExpired?.()
|
|
77
91
|
});
|
|
78
92
|
clientRef.current = client;
|
|
79
93
|
client.loadHistory().then((msgs) => {
|
|
@@ -86,6 +100,9 @@ function useMenuIA(config) {
|
|
|
86
100
|
clientRef.current = null;
|
|
87
101
|
};
|
|
88
102
|
}, [config.widgetId, config.agentId, config.apiUrl]);
|
|
103
|
+
(0, import_react.useEffect)(() => {
|
|
104
|
+
if (config.sessionToken) clientRef.current?.setSessionToken(config.sessionToken);
|
|
105
|
+
}, [config.sessionToken]);
|
|
89
106
|
const anexosPorBolha = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
90
107
|
const sendMessage = (0, import_react.useCallback)(async (content, attachments) => {
|
|
91
108
|
const text = content.trim();
|
|
@@ -588,7 +605,8 @@ function MenuIAChat({
|
|
|
588
605
|
onMessage,
|
|
589
606
|
onStatusChange,
|
|
590
607
|
onTicketCreated,
|
|
591
|
-
onError
|
|
608
|
+
onError,
|
|
609
|
+
onSessionTokenExpired
|
|
592
610
|
}) {
|
|
593
611
|
const [isOpen, setIsOpen] = (0, import_react2.useState)(defaultOpen || inline);
|
|
594
612
|
const [input, setInput] = (0, import_react2.useState)("");
|
|
@@ -621,7 +639,8 @@ function MenuIAChat({
|
|
|
621
639
|
onMessage,
|
|
622
640
|
onStatusChange,
|
|
623
641
|
onTicketCreated,
|
|
624
|
-
onError
|
|
642
|
+
onError,
|
|
643
|
+
onSessionTokenExpired
|
|
625
644
|
});
|
|
626
645
|
const styles = getStyles(primaryColor, theme);
|
|
627
646
|
(0, import_react2.useEffect)(() => {
|
package/dist/index.mjs
CHANGED
|
@@ -26,16 +26,30 @@ function useMenuIA(config) {
|
|
|
26
26
|
const [error, setError] = useState(null);
|
|
27
27
|
const [ticketId, setTicketId] = useState(null);
|
|
28
28
|
const [aiPaused, setAiPaused] = useState(false);
|
|
29
|
+
const configRef = useRef(config);
|
|
30
|
+
configRef.current = config;
|
|
29
31
|
useEffect(() => {
|
|
30
32
|
const client = new MenuIAClient({
|
|
31
33
|
...config,
|
|
32
|
-
onStatusChange: (s) =>
|
|
34
|
+
onStatusChange: (s) => {
|
|
35
|
+
setStatus(s);
|
|
36
|
+
configRef.current.onStatusChange?.(s);
|
|
37
|
+
},
|
|
33
38
|
onMessage: (msg) => {
|
|
34
39
|
if (vazia(msg)) return;
|
|
35
40
|
setMessages((prev) => mesmaMensagem(prev, msg) ? prev : [...prev, msg]);
|
|
41
|
+
configRef.current.onMessage?.(msg);
|
|
42
|
+
},
|
|
43
|
+
onTicketCreated: (id) => {
|
|
44
|
+
setTicketId(id);
|
|
45
|
+
configRef.current.onTicketCreated?.(id);
|
|
36
46
|
},
|
|
37
|
-
|
|
38
|
-
onError: (err) =>
|
|
47
|
+
// ⚠️ Antes o hook trocava os callbacks do app pelos dele: o onError do app nunca era chamado.
|
|
48
|
+
onError: (err) => {
|
|
49
|
+
setError(err.message);
|
|
50
|
+
configRef.current.onError?.(err);
|
|
51
|
+
},
|
|
52
|
+
onSessionTokenExpired: () => configRef.current.onSessionTokenExpired?.()
|
|
39
53
|
});
|
|
40
54
|
clientRef.current = client;
|
|
41
55
|
client.loadHistory().then((msgs) => {
|
|
@@ -48,6 +62,9 @@ function useMenuIA(config) {
|
|
|
48
62
|
clientRef.current = null;
|
|
49
63
|
};
|
|
50
64
|
}, [config.widgetId, config.agentId, config.apiUrl]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (config.sessionToken) clientRef.current?.setSessionToken(config.sessionToken);
|
|
67
|
+
}, [config.sessionToken]);
|
|
51
68
|
const anexosPorBolha = useRef(/* @__PURE__ */ new Map());
|
|
52
69
|
const sendMessage = useCallback(async (content, attachments) => {
|
|
53
70
|
const text = content.trim();
|
|
@@ -550,7 +567,8 @@ function MenuIAChat({
|
|
|
550
567
|
onMessage,
|
|
551
568
|
onStatusChange,
|
|
552
569
|
onTicketCreated,
|
|
553
|
-
onError
|
|
570
|
+
onError,
|
|
571
|
+
onSessionTokenExpired
|
|
554
572
|
}) {
|
|
555
573
|
const [isOpen, setIsOpen] = useState2(defaultOpen || inline);
|
|
556
574
|
const [input, setInput] = useState2("");
|
|
@@ -583,7 +601,8 @@ function MenuIAChat({
|
|
|
583
601
|
onMessage,
|
|
584
602
|
onStatusChange,
|
|
585
603
|
onTicketCreated,
|
|
586
|
-
onError
|
|
604
|
+
onError,
|
|
605
|
+
onSessionTokenExpired
|
|
587
606
|
});
|
|
588
607
|
const styles = getStyles(primaryColor, theme);
|
|
589
608
|
useEffect2(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@menuia/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "MenuIA Chat SDK - React Component",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"react-dom": ">=17.0.0"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@menuia/core": "^1.7.
|
|
20
|
+
"@menuia/core": "^1.7.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^18.2.0",
|