@sarujan/s_bot_creator 1.0.1 → 1.0.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/index.js +10 -21
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,23 +13,14 @@ export const BotWidget = ({ botId }) => {
|
|
|
13
13
|
const [input, setInput] = useState('');
|
|
14
14
|
const msgEndRef = useRef(null);
|
|
15
15
|
|
|
16
|
-
// useEffect(() => {
|
|
17
|
-
// // 1. Fetch config for colors and branding
|
|
18
|
-
// fetch(`https://api.botbuilder.ai/v1/config/${botId}`)
|
|
19
|
-
// .then(res => res.json())
|
|
20
|
-
// .then(data => {
|
|
21
|
-
// setConfig(data);
|
|
22
|
-
// setMessages([{ role: 'model', text: data.greetingMessage }]);
|
|
23
|
-
// });
|
|
24
|
-
// }, [botId]);
|
|
25
|
-
// Temporarily replace your useEffect fetch with this to test UI:
|
|
26
16
|
useEffect(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
// 1. Fetch config for colors and branding
|
|
18
|
+
fetch(`http://127.0.0.1:8000/api/config/${botId}`)
|
|
19
|
+
.then(res => res.json())
|
|
20
|
+
.then(data => {
|
|
21
|
+
setConfig(data);
|
|
22
|
+
setMessages([{ role: 'model', text: data.greetingMessage }]);
|
|
23
|
+
});
|
|
33
24
|
}, [botId]);
|
|
34
25
|
|
|
35
26
|
useEffect(() => {
|
|
@@ -44,13 +35,13 @@ export const BotWidget = ({ botId }) => {
|
|
|
44
35
|
setMessages(prev => [...prev, userMsg]);
|
|
45
36
|
setInput('');
|
|
46
37
|
|
|
47
|
-
const res = await fetch('
|
|
38
|
+
const res = await fetch('http://127.0.0.1:8000/api/chat/', {
|
|
48
39
|
method: 'POST',
|
|
49
40
|
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
body: JSON.stringify({ botId, message: input })
|
|
41
|
+
body: JSON.stringify({ botId, message: input, history: messages })
|
|
51
42
|
});
|
|
52
43
|
const data = await res.json();
|
|
53
|
-
setMessages(prev => [...prev, { role: 'model', text: data.
|
|
44
|
+
setMessages(prev => [...prev, { role: 'model', text: data.response }]);
|
|
54
45
|
};
|
|
55
46
|
|
|
56
47
|
if (!config) return null;
|
|
@@ -108,5 +99,3 @@ export const BotWidget = ({ botId }) => {
|
|
|
108
99
|
document.body
|
|
109
100
|
);
|
|
110
101
|
};
|
|
111
|
-
|
|
112
|
-
export default BotWidget;
|