react-native-chatbot-ai 0.1.53 → 0.1.55

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.
Files changed (97) hide show
  1. package/lib/module/assets/images/img_empty_data.png +0 -0
  2. package/lib/module/assets/images/index.js +2 -1
  3. package/lib/module/assets/images/index.js.map +1 -1
  4. package/lib/module/components/Drawer/SessionList.js +2 -1
  5. package/lib/module/components/Drawer/SessionList.js.map +1 -1
  6. package/lib/module/components/chat/ChatMessageList.js +19 -18
  7. package/lib/module/components/chat/ChatMessageList.js.map +1 -1
  8. package/lib/module/components/chat/ChatProductList.js +77 -0
  9. package/lib/module/components/chat/ChatProductList.js.map +1 -0
  10. package/lib/module/components/chat/index.js +131 -4
  11. package/lib/module/components/chat/index.js.map +1 -1
  12. package/lib/module/components/chat/item/ChatAIAnswerMessageItem.js +0 -2
  13. package/lib/module/components/chat/item/ChatAIAnswerMessageItem.js.map +1 -1
  14. package/lib/module/components/chat/item/ChatTable.js +19 -24
  15. package/lib/module/components/chat/item/ChatTable.js.map +1 -1
  16. package/lib/module/components/product/Card.js +249 -183
  17. package/lib/module/components/product/Card.js.map +1 -1
  18. package/lib/module/components/product/CardHorizontal.js +32 -19
  19. package/lib/module/components/product/CardHorizontal.js.map +1 -1
  20. package/lib/module/constants/chatTab.js +23 -0
  21. package/lib/module/constants/chatTab.js.map +1 -0
  22. package/lib/module/constants/events.js +4 -2
  23. package/lib/module/constants/events.js.map +1 -1
  24. package/lib/module/constants/index.js +1 -0
  25. package/lib/module/constants/index.js.map +1 -1
  26. package/lib/module/constants/query.js +2 -1
  27. package/lib/module/constants/query.js.map +1 -1
  28. package/lib/module/context/ChatContext.js +13 -3
  29. package/lib/module/context/ChatContext.js.map +1 -1
  30. package/lib/module/hooks/message/useMessage.js +7 -1
  31. package/lib/module/hooks/message/useMessage.js.map +1 -1
  32. package/lib/module/hooks/message/useSendMessage.js +3 -1
  33. package/lib/module/hooks/message/useSendMessage.js.map +1 -1
  34. package/lib/module/hooks/session/useGetExternalSessionInfo.js +17 -0
  35. package/lib/module/hooks/session/useGetExternalSessionInfo.js.map +1 -0
  36. package/lib/module/services/endpoints.js +2 -1
  37. package/lib/module/services/endpoints.js.map +1 -1
  38. package/lib/module/translation/resources/i18n.js +7 -1
  39. package/lib/module/translation/resources/i18n.js.map +1 -1
  40. package/lib/module/types/chat.js.map +1 -1
  41. package/lib/typescript/src/assets/images/index.d.ts +1 -0
  42. package/lib/typescript/src/assets/images/index.d.ts.map +1 -1
  43. package/lib/typescript/src/components/Drawer/SessionList.d.ts.map +1 -1
  44. package/lib/typescript/src/components/chat/ChatMessageList.d.ts.map +1 -1
  45. package/lib/typescript/src/components/chat/ChatProductList.d.ts +7 -0
  46. package/lib/typescript/src/components/chat/ChatProductList.d.ts.map +1 -0
  47. package/lib/typescript/src/components/chat/index.d.ts.map +1 -1
  48. package/lib/typescript/src/components/chat/item/ChatAIAnswerMessageItem.d.ts.map +1 -1
  49. package/lib/typescript/src/components/chat/item/ChatTable.d.ts.map +1 -1
  50. package/lib/typescript/src/components/product/Card.d.ts +6 -0
  51. package/lib/typescript/src/components/product/Card.d.ts.map +1 -1
  52. package/lib/typescript/src/components/product/CardHorizontal.d.ts +1 -0
  53. package/lib/typescript/src/components/product/CardHorizontal.d.ts.map +1 -1
  54. package/lib/typescript/src/constants/chatTab.d.ts +11 -0
  55. package/lib/typescript/src/constants/chatTab.d.ts.map +1 -0
  56. package/lib/typescript/src/constants/events.d.ts +2 -0
  57. package/lib/typescript/src/constants/events.d.ts.map +1 -1
  58. package/lib/typescript/src/constants/index.d.ts +1 -0
  59. package/lib/typescript/src/constants/index.d.ts.map +1 -1
  60. package/lib/typescript/src/constants/query.d.ts +1 -0
  61. package/lib/typescript/src/constants/query.d.ts.map +1 -1
  62. package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
  63. package/lib/typescript/src/hooks/message/useMessage.d.ts.map +1 -1
  64. package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
  65. package/lib/typescript/src/hooks/session/useGetExternalSessionInfo.d.ts +6 -0
  66. package/lib/typescript/src/hooks/session/useGetExternalSessionInfo.d.ts.map +1 -0
  67. package/lib/typescript/src/services/endpoints.d.ts +1 -0
  68. package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
  69. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
  70. package/lib/typescript/src/types/chat.d.ts +2 -0
  71. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  72. package/lib/typescript/src/types/dto.d.ts +10 -0
  73. package/lib/typescript/src/types/dto.d.ts.map +1 -1
  74. package/package.json +6 -2
  75. package/src/assets/images/img_empty_data.png +0 -0
  76. package/src/assets/images/index.ts +1 -0
  77. package/src/components/Drawer/SessionList.tsx +4 -2
  78. package/src/components/chat/ChatMessageList.tsx +24 -17
  79. package/src/components/chat/ChatProductList.tsx +92 -0
  80. package/src/components/chat/index.tsx +145 -2
  81. package/src/components/chat/item/ChatAIAnswerMessageItem.tsx +0 -2
  82. package/src/components/chat/item/ChatTable.tsx +17 -29
  83. package/src/components/product/Card.tsx +249 -176
  84. package/src/components/product/CardHorizontal.tsx +31 -18
  85. package/src/constants/chatTab.ts +18 -0
  86. package/src/constants/events.ts +2 -0
  87. package/src/constants/index.ts +1 -0
  88. package/src/constants/query.ts +1 -0
  89. package/src/context/ChatContext.tsx +13 -1
  90. package/src/hooks/message/useMessage.ts +7 -1
  91. package/src/hooks/message/useSendMessage.ts +3 -1
  92. package/src/hooks/session/useGetExternalSessionInfo.ts +23 -0
  93. package/src/ignore.d.ts +1 -0
  94. package/src/services/endpoints.ts +2 -0
  95. package/src/translation/resources/i18n.ts +7 -0
  96. package/src/types/chat.ts +2 -0
  97. package/src/types/dto.ts +12 -0
@@ -19,11 +19,13 @@ import { useChatContext } from '../../context/ChatContext';
19
19
  // import SkeletonPlaceholder from 'react-native-skeleton-placeholder';
20
20
  import { GAEvents } from '../../constants/events';
21
21
  import useSessionStore from '../../store/session';
22
+ import { getRouteKey } from '../../constants';
22
23
 
23
24
  interface IProductHorizontalCardProps {
24
25
  productId?: string;
25
26
  messageId?: string;
26
27
  index?: number;
28
+ showFavorite?: boolean;
27
29
  }
28
30
 
29
31
  const ProductHorizontalCardWrapper = memo(
@@ -45,10 +47,12 @@ const ProductHorizontalCard = memo(
45
47
  item,
46
48
  messageId,
47
49
  index,
50
+ showFavorite = false,
48
51
  }: IProductHorizontalCardProps & { item: IProductItem }) => {
49
52
  const onAddToCart = useChatContext()?.onAddToCart;
50
53
  const onBuyNow = useChatContext()?.onBuyNow;
51
54
  const onNavigateToProduct = useChatContext()?.onNavigateToProduct;
55
+ const tabIndex = useChatContext()?.tabIndex;
52
56
  const logGA = useChatContext()?.logGA;
53
57
 
54
58
  const {
@@ -157,10 +161,13 @@ const ProductHorizontalCard = memo(
157
161
  onNavigateToProduct?.(item);
158
162
  logGA(GAEvents.chatDetailProductCardTap, {
159
163
  conversation_id: useSessionStore.getState().sessionId,
164
+ message_chat_id: messageId,
160
165
  product_id: item.id,
161
166
  position_in_list: index,
167
+ tab_type: getRouteKey(tabIndex),
168
+ type: 'horizontal',
162
169
  });
163
- }, [onNavigateToProduct, logGA, item, index]);
170
+ }, [onNavigateToProduct, logGA, item, index, messageId, tabIndex]);
164
171
 
165
172
  const onPressAddToCart = useCallback(() => {
166
173
  if (!item) return;
@@ -171,8 +178,10 @@ const ProductHorizontalCard = memo(
171
178
  position_in_list: index,
172
179
  pdp_id: item.pdpId,
173
180
  message_chat_id: messageId,
181
+ tab_type: getRouteKey(tabIndex),
182
+ type: 'horizontal',
174
183
  });
175
- }, [onAddToCart, logGA, item, messageId, index]);
184
+ }, [onAddToCart, logGA, item, messageId, index, tabIndex]);
176
185
 
177
186
  const onPressBuyNow = useCallback(() => {
178
187
  if (!item) return;
@@ -183,8 +192,10 @@ const ProductHorizontalCard = memo(
183
192
  position_in_list: -1, //TODO: fix
184
193
  pdp_id: item.pdpId,
185
194
  message_chat_id: messageId,
195
+ tab_type: getRouteKey(tabIndex),
196
+ type: 'horizontal',
186
197
  });
187
- }, [onBuyNow, logGA, item, messageId]);
198
+ }, [onBuyNow, logGA, item, messageId, tabIndex]);
188
199
 
189
200
  return (
190
201
  <KContainer.Touchable style={styles.container} onPress={onPress}>
@@ -195,21 +206,23 @@ const ProductHorizontalCard = memo(
195
206
  br="2x"
196
207
  flashListForceRenderKey={id}
197
208
  />
198
- <KContainer.View style={styles.favoriteContainer}>
199
- <KButton.Base
200
- onPress={() => {}}
201
- size="xs"
202
- icon={{
203
- vectorName: isFavorite ? 'heart-b' : 'heart-o',
204
- size: 14,
205
- tintColor: isFavorite
206
- ? KColors.danger.normal
207
- : KColors.gray.normal,
208
- }}
209
- br="round"
210
- background={KColors.hexToRgba(KColors.white, 0.9)}
211
- />
212
- </KContainer.View>
209
+ <KContainer.VisibleView visible={showFavorite}>
210
+ <KContainer.View style={styles.favoriteContainer}>
211
+ <KButton.Base
212
+ onPress={() => {}}
213
+ size="xs"
214
+ icon={{
215
+ vectorName: isFavorite ? 'heart-b' : 'heart-o',
216
+ size: 14,
217
+ tintColor: isFavorite
218
+ ? KColors.danger.normal
219
+ : KColors.gray.normal,
220
+ }}
221
+ br="round"
222
+ background={KColors.hexToRgba(KColors.white, 0.9)}
223
+ />
224
+ </KContainer.View>
225
+ </KContainer.VisibleView>
213
226
  <KContainer.VisibleView visible={isSuspended}>
214
227
  <KContainer.View style={styles.abs}>
215
228
  <KLabel.Text
@@ -0,0 +1,18 @@
1
+ import { trans } from '../translation';
2
+
3
+ export enum ChatSessionTab {
4
+ answer = 'answer',
5
+ source = 'source',
6
+ product = 'product',
7
+ }
8
+
9
+ export const routes = [
10
+ { key: ChatSessionTab.answer, title: trans('answer') },
11
+ // { key: ChatSessionTab.source, title: trans('source') },
12
+ { key: ChatSessionTab.product, title: trans('product') },
13
+ ];
14
+
15
+ export const getRouteKey = (tabIndex: number) => {
16
+ const routeKey = routes[tabIndex]?.key;
17
+ return routeKey;
18
+ };
@@ -3,6 +3,7 @@ export const events = {
3
3
  updateMultipleMessage: 'update_multiple_message',
4
4
  forceUpdateMessages: 'force_update_messages',
5
5
  updateMessageError: 'update_message_error',
6
+ scrollToMessage: 'scroll_to_message',
6
7
  };
7
8
 
8
9
  export const GAEvents = {
@@ -37,4 +38,5 @@ export const GAEvents = {
37
38
  chatDetailLivechatBtnTap: 'ChatDetail_LivechatBtn_Tap',
38
39
  chatDetailFAQTap: 'ChatDetail_FAQ_Tap',
39
40
  chatDetailGiftDetailBtnTap: 'ChatDetail_GiftDetailBtn_Tap',
41
+ chatDetailJumpToMessageTap: 'ChatDetail_JumpToMessage_Tap',
40
42
  };
@@ -1,5 +1,6 @@
1
1
  import { createRef } from 'react';
2
2
  import { WithBottomSheetProps, WithPopupProps, WithToastProps } from '../types';
3
+ export * from './chatTab';
3
4
 
4
5
  const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER + 100;
5
6
 
@@ -8,4 +8,5 @@ export const QUERY_KEYS = {
8
8
  SHARE_SESSION: 'SHARE_SESSION',
9
9
  DELETE_SESSION: 'DELETE_SESSION',
10
10
  SEND_FEEDBACK: 'SEND_FEEDBACK',
11
+ GET_EXTERNAL_SESSION_INFO: 'GET_EXTERNAL_SESSION_INFO',
11
12
  };
@@ -1,8 +1,9 @@
1
- import { createContext, useContext, useRef } from 'react';
1
+ import { createContext, useContext, useEffect, useRef, useState } from 'react';
2
2
  import type { ChatContextType, ChatProviderProps } from '../types/chat';
3
3
  import ChatBotAI from '../components/chat';
4
4
  import Portal from '../components/portal';
5
5
  import ReanimatedDrawerExample from '../components/Drawer';
6
+ import useSessionStore from '../store/session';
6
7
 
7
8
  export const ChatContext = createContext<ChatContextType>({
8
9
  apiAddress: '',
@@ -18,12 +19,17 @@ export const ChatContext = createContext<ChatContextType>({
18
19
  chatbotUrl: '',
19
20
  logGA: () => {},
20
21
  notifyError: () => {},
22
+ tabIndex: 0,
23
+ setTabIndex: () => {},
21
24
  });
22
25
 
23
26
  export const useChatContext = () => useContext(ChatContext);
24
27
 
25
28
  export const ChatProvider = (props: ChatProviderProps) => {
26
29
  const ref = useRef<any>(null);
30
+ const [tabIndex, setTabIndex] = useState(0);
31
+ const sessionId = useSessionStore((state) => state.sessionId);
32
+
27
33
  const openDrawer = () => {
28
34
  ref.current?.openDrawer();
29
35
  };
@@ -46,6 +52,10 @@ export const ChatProvider = (props: ChatProviderProps) => {
46
52
  notifyError,
47
53
  } = props;
48
54
 
55
+ useEffect(() => {
56
+ setTabIndex(0);
57
+ }, [sessionId]);
58
+
49
59
  return (
50
60
  <ChatContext.Provider
51
61
  value={{
@@ -63,6 +73,8 @@ export const ChatProvider = (props: ChatProviderProps) => {
63
73
  chatbotUrl,
64
74
  logGA,
65
75
  notifyError,
76
+ tabIndex,
77
+ setTabIndex,
66
78
  }}
67
79
  >
68
80
  <ReanimatedDrawerExample ref={ref}>
@@ -5,6 +5,8 @@ import { IMessageItem, SessionDetailResponse } from '../../types/dto';
5
5
  import { DeviceEventEmitter } from 'react-native';
6
6
  import { events } from '../../constants/events';
7
7
  import useStreamMessageStore from '../../store/streamMessage';
8
+ import { useQueryClient } from '@tanstack/react-query';
9
+ import { QUERY_KEYS } from '../../constants/query';
8
10
 
9
11
  const initialState = {
10
12
  id: '',
@@ -18,6 +20,7 @@ const initialState = {
18
20
  messages: [],
19
21
  };
20
22
  export const useMessage = () => {
23
+ const queryClient = useQueryClient();
21
24
  const sessionId = useSessionStore((state) => state.sessionId);
22
25
  const { mutateAsync: getSessionById } = useFetchSessionById();
23
26
  const [loadState, setLoadState] =
@@ -111,6 +114,9 @@ export const useMessage = () => {
111
114
  useStreamMessageStore
112
115
  .getState()
113
116
  .clearStreamMessageRecordById(messages.map((m) => m.id));
117
+ queryClient.refetchQueries({
118
+ queryKey: [QUERY_KEYS.GET_EXTERNAL_SESSION_INFO],
119
+ });
114
120
  }
115
121
  );
116
122
  const subUpdateMessageError = DeviceEventEmitter.addListener(
@@ -152,7 +158,7 @@ export const useMessage = () => {
152
158
  subForceUpdateMessages.remove();
153
159
  subUpdateMessageError.remove();
154
160
  };
155
- }, []);
161
+ }, [queryClient]);
156
162
 
157
163
  return {
158
164
  messageState: loadState,
@@ -23,6 +23,7 @@ export const useSendMessage = () => {
23
23
  const { mutateAsync: createSession } = useCreateSession();
24
24
  const queryClient = useQueryClient();
25
25
  const logGA = useChatContext().logGA;
26
+ const setTabIndex = useChatContext().setTabIndex;
26
27
 
27
28
  const onSendMessage = useCallback(
28
29
  async (
@@ -30,6 +31,7 @@ export const useSendMessage = () => {
30
31
  attachments?: IAttachment[],
31
32
  actionType?: SendActionLogType
32
33
  ) => {
34
+ setTabIndex(0);
33
35
  const messageId = dayjs().valueOf().toString();
34
36
  const messageItem: IMessageItem = {
35
37
  id: messageId,
@@ -112,7 +114,7 @@ export const useSendMessage = () => {
112
114
  messageId
113
115
  );
114
116
  },
115
- [startStream, createSession, queryClient, logGA]
117
+ [startStream, createSession, queryClient, logGA, setTabIndex]
116
118
  );
117
119
 
118
120
  return {
@@ -0,0 +1,23 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { QUERY_KEYS } from '../../constants/query';
3
+ import { apiInstance } from '../../services';
4
+ import { BaseResponse, IChatExternalSessionInfoResponse } from '../../types';
5
+ import { ENDPOINTS } from '../../services/endpoints';
6
+
7
+ interface IUseGetExternalSessionInfoProps {
8
+ sessionId: string;
9
+ }
10
+
11
+ export const useGetExternalSessionInfo = ({
12
+ sessionId,
13
+ }: IUseGetExternalSessionInfoProps) =>
14
+ useQuery({
15
+ queryKey: [QUERY_KEYS.GET_EXTERNAL_SESSION_INFO, sessionId],
16
+ queryFn: async () => {
17
+ const res = await apiInstance?.get<
18
+ BaseResponse<IChatExternalSessionInfoResponse>
19
+ >(ENDPOINTS.assistantService.getExternalSessionInfo(sessionId));
20
+ return res?.data?.data || null;
21
+ },
22
+ enabled: !!sessionId,
23
+ });
package/src/ignore.d.ts CHANGED
@@ -19,5 +19,6 @@ declare module '@droppii/libs' {
19
19
  export const KRating: any;
20
20
  export const KProduct: any;
21
21
  export const KFonts: any;
22
+ export const KBadge: any;
22
23
  }
23
24
  declare module '*';
@@ -17,6 +17,8 @@ export const ENDPOINTS = {
17
17
  `/assistant-service/v1/app/chat/sessions/${sessionId}/feedback`,
18
18
  generateAudio: (sessionId: string, messageId: string) =>
19
19
  `/assistant-service/v1/app/chat/sessions/${sessionId}/messages/${messageId}/speech`,
20
+ getExternalSessionInfo: (sessionId: string) =>
21
+ `/assistant-service/v1/app/chat/sessions/${sessionId}/tab-data`,
20
22
  },
21
23
  uploaderService: {
22
24
  upload: '/uploader-service/v1/uploader/permanently',
@@ -56,6 +56,13 @@ const i18nKey: Record<string, string> = {
56
56
  //product
57
57
  commissions: 'LN: ',
58
58
  points: 'Points: ',
59
+
60
+ //tabs
61
+ answer: 'Trả lời',
62
+ source: 'Nguồn',
63
+ product: 'Sản phẩm',
64
+ view_original_message: 'Xem câu trả lời gốc',
65
+ empty_product: 'Không có sản phẩm nào',
59
66
  };
60
67
 
61
68
  export default {
package/src/types/chat.ts CHANGED
@@ -17,6 +17,8 @@ export interface ChatContextType {
17
17
  chatbotUrl: string;
18
18
  logGA: (event: string, params?: any) => void;
19
19
  notifyError?: ErrorLogger;
20
+ tabIndex: number;
21
+ setTabIndex: (tabIndex: number) => void;
20
22
  }
21
23
 
22
24
  export interface ChatProviderProps {
package/src/types/dto.ts CHANGED
@@ -199,3 +199,15 @@ export interface SendFeedbackResponse {
199
199
  success: boolean;
200
200
  message: string;
201
201
  }
202
+
203
+ export interface ISessionProductItem extends IProductItem {
204
+ message_id?: string;
205
+ }
206
+
207
+ export interface IChatExternalSessionInfoResponse {
208
+ products: {
209
+ items: ISessionProductItem[];
210
+ count: number;
211
+ };
212
+ source: null;
213
+ }