react-native-chatbot-ai 0.1.42 → 0.1.44
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/lib/module/components/Drawer/DeleteSessionPopup.js +13 -1
- package/lib/module/components/Drawer/DeleteSessionPopup.js.map +1 -1
- package/lib/module/components/Drawer/RenameSessionPopup.js +11 -2
- package/lib/module/components/Drawer/RenameSessionPopup.js.map +1 -1
- package/lib/module/components/Drawer/ShareSessionPopup.js +11 -2
- package/lib/module/components/Drawer/ShareSessionPopup.js.map +1 -1
- package/lib/module/components/chat/footer/index.js +15 -12
- package/lib/module/components/chat/footer/index.js.map +1 -1
- package/lib/module/components/chat/footer/item/UploadFileItem.js +4 -3
- package/lib/module/components/chat/footer/item/UploadFileItem.js.map +1 -1
- package/lib/module/components/chat/footer/item/UploadImageItem.js +4 -4
- package/lib/module/components/chat/footer/item/UploadImageItem.js.map +1 -1
- package/lib/module/components/portal/Popup.js +10 -3
- package/lib/module/components/portal/Popup.js.map +1 -1
- package/lib/module/context/ChatContext.js +6 -3
- package/lib/module/context/ChatContext.js.map +1 -1
- package/lib/module/hooks/message/useStreamMessage.js +19 -2
- package/lib/module/hooks/message/useStreamMessage.js.map +1 -1
- package/lib/module/hooks/messageActions/useAudioPlayer.js +40 -9
- package/lib/module/hooks/messageActions/useAudioPlayer.js.map +1 -1
- package/lib/module/hooks/messageActions/useCopyToClipboard.js +13 -2
- package/lib/module/hooks/messageActions/useCopyToClipboard.js.map +1 -1
- package/lib/module/hooks/messageActions/useFeedback.js +20 -4
- package/lib/module/hooks/messageActions/useFeedback.js.map +1 -1
- package/lib/module/hooks/messageActions/useShareMessage.js +21 -4
- package/lib/module/hooks/messageActions/useShareMessage.js.map +1 -1
- package/lib/module/hooks/upload/useUploadItem.js +17 -4
- package/lib/module/hooks/upload/useUploadItem.js.map +1 -1
- package/lib/module/types/chat.js.map +1 -1
- package/lib/typescript/src/components/Drawer/DeleteSessionPopup.d.ts.map +1 -1
- package/lib/typescript/src/components/Drawer/RenameSessionPopup.d.ts.map +1 -1
- package/lib/typescript/src/components/Drawer/ShareSessionPopup.d.ts.map +1 -1
- package/lib/typescript/src/components/chat/footer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/chat/footer/item/UploadFileItem.d.ts.map +1 -1
- package/lib/typescript/src/components/portal/Popup.d.ts.map +1 -1
- package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
- package/lib/typescript/src/hooks/message/useStreamMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/messageActions/useAudioPlayer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/messageActions/useCopyToClipboard.d.ts.map +1 -1
- package/lib/typescript/src/hooks/messageActions/useFeedback.d.ts.map +1 -1
- package/lib/typescript/src/hooks/messageActions/useShareMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/upload/useUploadItem.d.ts +1 -1
- package/lib/typescript/src/hooks/upload/useUploadItem.d.ts.map +1 -1
- package/lib/typescript/src/types/chat.d.ts +9 -0
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Drawer/DeleteSessionPopup.tsx +14 -1
- package/src/components/Drawer/RenameSessionPopup.tsx +21 -2
- package/src/components/Drawer/ShareSessionPopup.tsx +13 -2
- package/src/components/chat/footer/index.tsx +20 -13
- package/src/components/chat/footer/item/UploadFileItem.tsx +5 -4
- package/src/components/chat/footer/item/UploadImageItem.tsx +3 -3
- package/src/components/portal/Popup.tsx +24 -3
- package/src/context/ChatContext.tsx +3 -0
- package/src/hooks/message/useStreamMessage.ts +32 -2
- package/src/hooks/messageActions/useAudioPlayer.ts +49 -8
- package/src/hooks/messageActions/useCopyToClipboard.ts +39 -23
- package/src/hooks/messageActions/useFeedback.ts +24 -4
- package/src/hooks/messageActions/useShareMessage.ts +34 -6
- package/src/hooks/upload/useUploadItem.ts +23 -7
- package/src/types/chat.ts +13 -0
|
@@ -22,7 +22,7 @@ export const useShareMessage = (
|
|
|
22
22
|
messageContent: string,
|
|
23
23
|
productImages?: string[]
|
|
24
24
|
) => {
|
|
25
|
-
const logGA = useChatContext()
|
|
25
|
+
const { logGA, notifyError } = useChatContext();
|
|
26
26
|
const shareState = useMessageActionsStore((state) =>
|
|
27
27
|
state.getShareState(messageId)
|
|
28
28
|
);
|
|
@@ -77,9 +77,19 @@ export const useShareMessage = (
|
|
|
77
77
|
|
|
78
78
|
localImagePaths.push(`file://${imagePath}`);
|
|
79
79
|
} catch (imageError) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
const errorObj =
|
|
81
|
+
imageError instanceof Error
|
|
82
|
+
? imageError
|
|
83
|
+
: new Error(String(imageError));
|
|
84
|
+
notifyError?.(
|
|
85
|
+
{
|
|
86
|
+
errorClass: 'ChatbotAI',
|
|
87
|
+
errorMessage: errorObj.message,
|
|
88
|
+
name: 'ShareImageDownloadError',
|
|
89
|
+
message: `[Share] Failed to download image ${i} (${imageUrl}): ${errorObj.message}`,
|
|
90
|
+
stack: errorObj?.stack,
|
|
91
|
+
},
|
|
92
|
+
'error'
|
|
83
93
|
);
|
|
84
94
|
// Continue with other images
|
|
85
95
|
}
|
|
@@ -125,7 +135,18 @@ export const useShareMessage = (
|
|
|
125
135
|
setShareState(messageId, ShareState.idle);
|
|
126
136
|
}
|
|
127
137
|
} catch (error: any) {
|
|
128
|
-
|
|
138
|
+
const errorObj =
|
|
139
|
+
error instanceof Error ? error : new Error(String(error));
|
|
140
|
+
notifyError?.(
|
|
141
|
+
{
|
|
142
|
+
errorClass: 'ChatbotAI',
|
|
143
|
+
errorMessage: errorObj.message,
|
|
144
|
+
name: 'ShareError',
|
|
145
|
+
message: `Share error: ${errorObj.message}`,
|
|
146
|
+
stack: errorObj?.stack,
|
|
147
|
+
},
|
|
148
|
+
'error'
|
|
149
|
+
);
|
|
129
150
|
|
|
130
151
|
// User cancelled share dialog
|
|
131
152
|
if (error?.message?.includes('User did not share')) {
|
|
@@ -136,7 +157,14 @@ export const useShareMessage = (
|
|
|
136
157
|
setShareState(messageId, ShareState.error);
|
|
137
158
|
UIUtils.toast.showError('Không thể chia sẻ. Vui lòng thử lại.');
|
|
138
159
|
}
|
|
139
|
-
}, [
|
|
160
|
+
}, [
|
|
161
|
+
messageId,
|
|
162
|
+
messageContent,
|
|
163
|
+
productImages,
|
|
164
|
+
setShareState,
|
|
165
|
+
logGA,
|
|
166
|
+
notifyError,
|
|
167
|
+
]);
|
|
140
168
|
|
|
141
169
|
return {
|
|
142
170
|
shareState: currentState,
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
} from '../../utils/device';
|
|
13
13
|
import { GAEvents } from '../../constants/events';
|
|
14
14
|
import useSessionStore from '../../store/session';
|
|
15
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
16
|
+
import debounce from 'lodash/debounce';
|
|
15
17
|
|
|
16
18
|
export interface ImageUpload extends Image {
|
|
17
19
|
streamId?: string;
|
|
@@ -190,13 +192,27 @@ export const useUploadItem = ({ logGA }: Props) => {
|
|
|
190
192
|
}
|
|
191
193
|
}, []);
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
196
|
+
const handleRemoveUploadItem = useCallback(
|
|
197
|
+
debounce(
|
|
198
|
+
(item: UploadItem) => {
|
|
199
|
+
if (item.uploadType === 'image') {
|
|
200
|
+
setImageUpload((prev) => {
|
|
201
|
+
const mImage = cloneDeep(prev);
|
|
202
|
+
return mImage.filter((i) => i?.path !== item?.path);
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
setDocumentUpload((prev) => {
|
|
206
|
+
const mDocument = cloneDeep(prev);
|
|
207
|
+
return mDocument.filter((i) => i?.uri !== item?.uri);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
200,
|
|
212
|
+
{ leading: false, trailing: true }
|
|
213
|
+
),
|
|
214
|
+
[]
|
|
215
|
+
);
|
|
200
216
|
|
|
201
217
|
const clearFileUpload = useCallback(() => {
|
|
202
218
|
setImageUpload([]);
|
package/src/types/chat.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface ChatContextType {
|
|
|
16
16
|
closeDrawer: () => void;
|
|
17
17
|
chatbotUrl: string;
|
|
18
18
|
logGA: (event: string, params?: any) => void;
|
|
19
|
+
notifyError?: ErrorLogger;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export interface ChatProviderProps {
|
|
@@ -30,8 +31,20 @@ export interface ChatProviderProps {
|
|
|
30
31
|
pushLinkTo?: (url: string, resParams?: any) => void;
|
|
31
32
|
chatbotUrl: string;
|
|
32
33
|
logGA: (event: string, params?: any) => void;
|
|
34
|
+
notifyError?: ErrorLogger;
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
export type ErrorLogger = (
|
|
38
|
+
p: {
|
|
39
|
+
errorClass: string | undefined;
|
|
40
|
+
errorMessage: string | undefined;
|
|
41
|
+
name: string;
|
|
42
|
+
message: string;
|
|
43
|
+
stack: string | undefined;
|
|
44
|
+
},
|
|
45
|
+
evt?: 'error' | 'info' | 'warning' | undefined
|
|
46
|
+
) => void;
|
|
47
|
+
|
|
35
48
|
export enum SessionLogType {
|
|
36
49
|
accessed = 'accessed',
|
|
37
50
|
newChatBtn = 'new_chat_btn',
|