shopify-chatbot-widget 0.0.4 → 0.2.2
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/jaweb-chatbot.css +1 -0
- package/dist/jaweb-chatbot.iife.js +685 -0
- package/dist/vite.svg +1 -0
- package/package.json +1 -1
- package/src/App.css +0 -42
- package/src/App.tsx +0 -13
- package/src/Chatbot/Chatbot.css +0 -154
- package/src/Chatbot/Chatbot.tsx +0 -207
- package/src/Chatbot/components/ChatInput.css +0 -127
- package/src/Chatbot/components/ChatInput.tsx +0 -262
- package/src/Chatbot/components/Messages/Addcart.tsx +0 -70
- package/src/Chatbot/components/Messages/AgentStatus.tsx +0 -37
- package/src/Chatbot/components/Messages/AssistantMesage.tsx +0 -316
- package/src/Chatbot/components/Messages/AudioMessage.tsx +0 -123
- package/src/Chatbot/components/Messages/CartWidget.tsx +0 -116
- package/src/Chatbot/components/Messages/ChatImage.tsx +0 -46
- package/src/Chatbot/components/Messages/ChatImageText.tsx +0 -74
- package/src/Chatbot/components/Messages/ChatImageTextAssis.tsx +0 -72
- package/src/Chatbot/components/Messages/ChatMessages.css +0 -5
- package/src/Chatbot/components/Messages/ChatMessages.tsx +0 -284
- package/src/Chatbot/components/Messages/Support.tsx +0 -177
- package/src/Chatbot/components/Messages/Typing.css +0 -27
- package/src/Chatbot/components/Messages/Typing.tsx +0 -14
- package/src/Chatbot/components/Messages/ZidAssistantMesage.tsx +0 -142
- package/src/Chatbot/components/Messenger/Messenger.tsx +0 -521
- package/src/Chatbot/components/Notification.tsx +0 -27
- package/src/Chatbot/components/Powered.css +0 -16
- package/src/Chatbot/components/Powered.tsx +0 -13
- package/src/Chatbot/components/Sessions/CreateSession.tsx +0 -139
- package/src/Chatbot/components/Sessions/RenderList.tsx +0 -202
- package/src/Chatbot/components/Suggestions.css +0 -34
- package/src/Chatbot/components/Suggestions.tsx +0 -28
- package/src/assets/react.svg +0 -1
- package/src/chatbot-widget/index.tsx +0 -14
- package/src/hooks/config.tsx +0 -13
- package/src/hooks/useCart.tsx +0 -99
- package/src/hooks/useChatbotAPI.tsx +0 -160
- package/src/hooks/useChatbotData.tsx +0 -129
- package/src/hooks/useSessionMessages.tsx +0 -51
- package/src/hooks/useWebsocke.tsx +0 -45
- package/src/i18n.tsx +0 -30
- package/src/index.css +0 -1
- package/src/main.tsx +0 -10
- package/src/types/chatbot.ts +0 -38
- package/src/utils/cookies.tsx +0 -14
- package/src/vite-env.d.ts +0 -1
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { getCookie } from '../utils/cookies';
|
|
4
|
-
import config from './config';
|
|
5
|
-
import type { ChatMessage } from '../types/chatbot';
|
|
6
|
-
|
|
7
|
-
export const useChatbotMessage = (sessionId: string | null) => {
|
|
8
|
-
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
|
9
|
-
const [isFetchingMessages, setisFetchingMessages] = useState(false);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const loadHistory = async () => {
|
|
13
|
-
const sid = sessionId
|
|
14
|
-
if (!sid) return;
|
|
15
|
-
|
|
16
|
-
setisFetchingMessages(true);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const res = await axios.get<{ messages: ChatMessage[] }>(
|
|
21
|
-
`${config.apiUrl}chat-message-history/`,
|
|
22
|
-
{
|
|
23
|
-
withCredentials: true,
|
|
24
|
-
params: {
|
|
25
|
-
session_id: sid,
|
|
26
|
-
username: getCookie('company_username'),
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (res.data?.messages?.length > 0) {
|
|
33
|
-
setMessages(res.data.messages);
|
|
34
|
-
setisFetchingMessages(false)
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
console.error("Couldn't load history", err);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
loadHistory();
|
|
44
|
-
}, [sessionId]);
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
messages,
|
|
48
|
-
setMessages,
|
|
49
|
-
isFetchingMessages
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// hooks/useChatSocket.ts
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
-
import config from './config';
|
|
4
|
-
|
|
5
|
-
export default function useChatSocket(
|
|
6
|
-
session_id: string,
|
|
7
|
-
onMessage: (data: any) => void
|
|
8
|
-
) {
|
|
9
|
-
const socketRef = useRef<WebSocket | null>(null);
|
|
10
|
-
// keep a stable ref to the latest onMessage
|
|
11
|
-
const onMessageRef = useRef(onMessage);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
onMessageRef.current = onMessage;
|
|
14
|
-
}, [onMessage]);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (!session_id) return;
|
|
18
|
-
|
|
19
|
-
const ws = new WebSocket(`${config.websocketUrl}/chat/${session_id}/`);
|
|
20
|
-
socketRef.current = ws;
|
|
21
|
-
|
|
22
|
-
// precise add/remove so we never leak handlers
|
|
23
|
-
const handle = (event: MessageEvent) => {
|
|
24
|
-
try {
|
|
25
|
-
const data = JSON.parse(event.data);
|
|
26
|
-
onMessageRef.current(data);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.error('Invalid JSON', e);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
ws.addEventListener('message', handle);
|
|
32
|
-
|
|
33
|
-
// you can still do onopen/onclose, but tear them down too if you attach them
|
|
34
|
-
const handleClose = () => { /* reconnect logic… */ };
|
|
35
|
-
ws.addEventListener('close', handleClose);
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
ws.removeEventListener('message', handle);
|
|
39
|
-
ws.removeEventListener('close', handleClose);
|
|
40
|
-
ws.close();
|
|
41
|
-
};
|
|
42
|
-
}, [session_id]);
|
|
43
|
-
|
|
44
|
-
return socketRef.current;
|
|
45
|
-
}
|
package/src/i18n.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/i18n.ts
|
|
2
|
-
import i18n from 'i18next';
|
|
3
|
-
import { initReactI18next } from 'react-i18next';
|
|
4
|
-
|
|
5
|
-
const resources = {
|
|
6
|
-
en: {
|
|
7
|
-
translation: {
|
|
8
|
-
welcome: "Hi there, you’re speaking with Jaweb AI Assistant.",
|
|
9
|
-
// Add more English translations here
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
ar: {
|
|
13
|
-
translation: {
|
|
14
|
-
welcome: "مرحبًا، أنت تتحدث إلى مساعد Jaweb AI.",
|
|
15
|
-
// Add more Arabic translations here
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
i18n.use(initReactI18next).init({
|
|
21
|
-
resources,
|
|
22
|
-
lng: 'en', // default language
|
|
23
|
-
fallbackLng: 'en',
|
|
24
|
-
|
|
25
|
-
interpolation: {
|
|
26
|
-
escapeValue: false, // React already escapes
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export default i18n;
|
package/src/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import "tailwindcss";
|
package/src/main.tsx
DELETED
package/src/types/chatbot.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// types/chatbot.ts
|
|
2
|
-
|
|
3
|
-
export interface ChatbotDetailsResponse {
|
|
4
|
-
data: {
|
|
5
|
-
language: string;
|
|
6
|
-
chatbot_form: boolean;
|
|
7
|
-
chatbot_color: string;
|
|
8
|
-
chatbot_logo: string;
|
|
9
|
-
disable_chatbot_globally: boolean;
|
|
10
|
-
remove_powered_by_jaweb: boolean;
|
|
11
|
-
chatbot_initial_msg: string;
|
|
12
|
-
status: string;
|
|
13
|
-
calendly_link?: string | null;
|
|
14
|
-
phone_number_id?: string | null;
|
|
15
|
-
mode:string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface SuggestionResponse {
|
|
20
|
-
data?: string[]; // when data is returned directly
|
|
21
|
-
user_questions?: string[] | null; // when API sends it here
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export interface ChatMessage {
|
|
26
|
-
role?: 'user' | 'bot' | 'assistant' | 'system';
|
|
27
|
-
content?:string;
|
|
28
|
-
isBusiness?:boolean;
|
|
29
|
-
sender?:string;
|
|
30
|
-
typing?: boolean;
|
|
31
|
-
id?:Number;
|
|
32
|
-
image_url?:string;
|
|
33
|
-
status?:string;
|
|
34
|
-
audio_url?: string;
|
|
35
|
-
isConnect?:boolean;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
package/src/utils/cookies.tsx
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// utils/cookies.ts
|
|
2
|
-
import Cookies from 'js-cookie';
|
|
3
|
-
|
|
4
|
-
export const getCookie = (key: string): string | undefined => {
|
|
5
|
-
return Cookies.get(key);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const setCookie = (key: string, value: string, days = 30): void => {
|
|
9
|
-
Cookies.set(key, value, { expires: days });
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const removeCookie = (key: string): void => {
|
|
13
|
-
Cookies.remove(key);
|
|
14
|
-
};
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|