@daeryun/dr_components 0.8.26 → 0.8.28
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/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatButton.jsx +29 -14
- package/dist/components/Daeryuntalk/ChatButton.tsx +17 -14
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +42 -11
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +41 -12
- package/dist/components/Daeryuntalk/ChatItem/RichText.jsx +12 -2
- package/dist/components/Daeryuntalk/ChatItem/RichText.tsx +14 -2
- package/dist/components/Daeryuntalk/ChatMessage.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatMessage.tsx +2 -2
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +2 -1
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +7 -4
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +10 -5
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +1 -11
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +87 -59
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +100 -61
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.d.ts +3 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +7 -4
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +91 -84
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.d.ts +3 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.js +11 -3
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.ts +21 -3
- package/dist/components/Daeryuntalk/_types/message.js +1 -2
- package/dist/components/Daeryuntalk/_types/message.ts +1 -2
- package/dist/styles/globals.css +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -265,13 +265,18 @@ export async function initializeWebSocket(
|
|
|
265
265
|
* @param onError 오류 핸들러
|
|
266
266
|
* @returns 웹소켓 인스턴스
|
|
267
267
|
*/
|
|
268
|
+
let reconnectAttempts = 0;
|
|
269
|
+
const MAX_RECONNECT_ATTEMPTS = 5;
|
|
270
|
+
const RECONNECT_DELAY_MS = 2000;
|
|
271
|
+
|
|
268
272
|
export function connectWebSocket(
|
|
269
273
|
wsUrl: string,
|
|
270
274
|
token: string,
|
|
271
275
|
onMessage?: (event: MessageEvent) => void,
|
|
272
276
|
onOpen?: (event: Event) => void,
|
|
273
277
|
onClose?: (event: CloseEvent) => void,
|
|
274
|
-
onError?: (event: Event) => void
|
|
278
|
+
onError?: (event: Event) => void,
|
|
279
|
+
onReconnectFail?: () => void // 재연결 실패 후 알림
|
|
275
280
|
): WebSocket {
|
|
276
281
|
// URL에 토큰을 파라미터로 추가
|
|
277
282
|
const connectionUrl = `${wsUrl}?token=${token}`;
|
|
@@ -280,37 +285,50 @@ export function connectWebSocket(
|
|
|
280
285
|
try {
|
|
281
286
|
const socket = new WebSocket(connectionUrl);
|
|
282
287
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
const setupSocketHandlers = (socket: WebSocket) => {
|
|
289
|
+
socket.onopen = event => {
|
|
290
|
+
console.log('[웹소켓 연결 성공]');
|
|
291
|
+
reconnectAttempts = 0;
|
|
292
|
+
if (onOpen) onOpen(event);
|
|
293
|
+
};
|
|
287
294
|
|
|
288
|
-
|
|
289
|
-
|
|
295
|
+
socket.onmessage = event => {
|
|
296
|
+
console.log('[웹소켓 메시지 수신]', event.data);
|
|
290
297
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
298
|
+
try {
|
|
299
|
+
const data = JSON.parse(event.data);
|
|
300
|
+
console.log('📩 New Message (parsed):', data);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
console.error('[웹소켓] JSON 파싱 오류:', err);
|
|
303
|
+
}
|
|
297
304
|
|
|
298
|
-
|
|
299
|
-
|
|
305
|
+
if (onMessage) onMessage(event.data);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
socket.onclose = async event => {
|
|
309
|
+
console.warn('[웹소켓 종료]', event);
|
|
300
310
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
311
|
+
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
|
312
|
+
reconnectAttempts++;
|
|
313
|
+
console.log(`[재연결 시도] ${reconnectAttempts}회... ${RECONNECT_DELAY_MS}ms 후`);
|
|
314
|
+
await new Promise(res => setTimeout(res, RECONNECT_DELAY_MS));
|
|
315
|
+
|
|
316
|
+
socket = new WebSocket(connectionUrl);
|
|
317
|
+
setupSocketHandlers(socket); // 재귀 호출
|
|
318
|
+
} else {
|
|
319
|
+
console.error('[웹소켓 재연결 실패] 최대 재시도 초과');
|
|
320
|
+
if (onReconnectFail) onReconnectFail();
|
|
321
|
+
if (onClose) onClose(event);
|
|
322
|
+
}
|
|
305
323
|
};
|
|
306
|
-
}
|
|
307
324
|
|
|
308
|
-
if (onError) {
|
|
309
325
|
socket.onerror = event => {
|
|
310
326
|
console.error('[웹소켓 오류]', event);
|
|
311
|
-
onError(event);
|
|
327
|
+
if (onError) onError(event);
|
|
312
328
|
};
|
|
313
|
-
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
setupSocketHandlers(socket);
|
|
314
332
|
|
|
315
333
|
return socket;
|
|
316
334
|
} catch (error) {
|
|
@@ -477,6 +495,21 @@ export async function getChatInquiryMessageList(
|
|
|
477
495
|
}
|
|
478
496
|
}
|
|
479
497
|
|
|
498
|
+
async function retryable<T>(fn: () => Promise<T>, maxAttempts = 3, delayMs = 1000, label = ''): Promise<T> {
|
|
499
|
+
let attempt = 0;
|
|
500
|
+
while (attempt < maxAttempts) {
|
|
501
|
+
try {
|
|
502
|
+
return await fn();
|
|
503
|
+
} catch (error) {
|
|
504
|
+
attempt++;
|
|
505
|
+
console.warn(`[재시도] ${label} ${attempt}회 실패`, error);
|
|
506
|
+
if (attempt >= maxAttempts) throw new Error(`${label} 최대 재시도 초과`);
|
|
507
|
+
await new Promise(res => setTimeout(res, delayMs));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
throw new Error(`${label} 실패`);
|
|
511
|
+
}
|
|
512
|
+
|
|
480
513
|
/**
|
|
481
514
|
* Daeryuntalk 초기화 완료 흐름
|
|
482
515
|
* 이 함수는 인증부터 웹소켓 연결까지 완전한 흐름을 처리
|
|
@@ -500,57 +533,63 @@ export async function initializeDaeryuntalk(
|
|
|
500
533
|
version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`
|
|
501
534
|
);
|
|
502
535
|
try {
|
|
536
|
+
console.log('[Daeryuntalk 초기화] 전체 흐름 시작');
|
|
537
|
+
|
|
503
538
|
// 1단계: 사용자 인증
|
|
504
|
-
|
|
505
|
-
const authResponse = await authenticateUser(TEST_CENTER_CODE, version);
|
|
506
|
-
console.log('[Daeryuntalk 초기화] 1단계: 사용자 인증 완료');
|
|
539
|
+
const authResponse = await retryable(() => authenticateUser(TEST_CENTER_CODE, version), 3, 1000, '사용자 인증');
|
|
507
540
|
|
|
508
541
|
// 2단계: 웹소켓 초기화
|
|
509
|
-
|
|
510
|
-
const wsInitData = await initializeWebSocket(version);
|
|
511
|
-
console.log('[Daeryuntalk 초기화] 2단계: 웹소켓 초기화 완료', {
|
|
512
|
-
cnnc_url: wsInitData.data.connection_url,
|
|
513
|
-
token_일부: wsInitData.data.connection_token
|
|
514
|
-
? `${wsInitData.data.connection_token.substring(0, 10)}...`
|
|
515
|
-
: '없음'
|
|
516
|
-
});
|
|
542
|
+
const wsInitData = await retryable(() => initializeWebSocket(version), 3, 1000, '웹소켓 초기화');
|
|
517
543
|
|
|
518
544
|
// 3단계: 웹소켓 연결
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
545
|
+
const socket = await retryable(
|
|
546
|
+
() =>
|
|
547
|
+
new Promise<WebSocket>((resolve, reject) => {
|
|
548
|
+
try {
|
|
549
|
+
const ws = connectWebSocket(
|
|
550
|
+
wsInitData.data.connection_url,
|
|
551
|
+
wsInitData.data.connection_token,
|
|
552
|
+
onWebSocketMessage,
|
|
553
|
+
() => {
|
|
554
|
+
console.log('[웹소켓 연결 성공]');
|
|
555
|
+
onWebSocketConnected?.(ws);
|
|
556
|
+
resolve(ws);
|
|
557
|
+
},
|
|
558
|
+
() => {},
|
|
559
|
+
event => {
|
|
560
|
+
console.error('[웹소켓 연결 실패]', event);
|
|
561
|
+
reject(new Error('웹소켓 연결 실패'));
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
} catch (err) {
|
|
565
|
+
reject(err);
|
|
566
|
+
}
|
|
567
|
+
}),
|
|
568
|
+
3,
|
|
569
|
+
2000,
|
|
570
|
+
'웹소켓 연결'
|
|
532
571
|
);
|
|
533
|
-
// console.log('socket', socket);
|
|
534
|
-
console.log('[Daeryuntalk 초기화] 3단계: 웹소켓 연결 객체 생성됨');
|
|
535
572
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
let hashAuth;
|
|
573
|
+
// 4단계: 해시 인증
|
|
574
|
+
let hashAuth = null;
|
|
539
575
|
if (hashValue) {
|
|
540
|
-
hashAuth = await followupAttend({ token: hashValue });
|
|
576
|
+
hashAuth = await retryable(() => followupAttend({ token: hashValue }), 2, 1000, '해시 인증');
|
|
541
577
|
}
|
|
542
578
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
579
|
+
// 5단계: 문의 조회
|
|
580
|
+
const chatInquiryData = await retryable(
|
|
581
|
+
() => getChatInquiryMain(authResponse.data.channel_number, version),
|
|
582
|
+
2,
|
|
583
|
+
1000,
|
|
584
|
+
'채팅 문의 메인 조회'
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
console.log('[Daeryuntalk 초기화 완료]');
|
|
548
588
|
return {
|
|
549
589
|
inquiryData: chatInquiryData,
|
|
550
|
-
socket
|
|
551
|
-
hashAuth
|
|
590
|
+
socket,
|
|
591
|
+
hashAuth
|
|
552
592
|
};
|
|
553
|
-
console.log('[Daeryuntalk 초기화 완료] 모든 단계 성공');
|
|
554
593
|
} catch (error) {
|
|
555
594
|
console.error('[Daeryuntalk 초기화 실패] 오류 발생:', error);
|
|
556
595
|
throw error;
|
|
@@ -16,7 +16,9 @@ interface props {
|
|
|
16
16
|
}
|
|
17
17
|
export declare const useChatHandler: ({ setIsLoading, inquiryMainData, setChatInquiryNumber, setMessages, setInquiryStatus, setMessageObject, chatInquiryNumber, setIsNextPage, setWorkFlowStack, setInquiryMainData }: props) => {
|
|
18
18
|
attendRoomByHistory: (chatInquiryNumber: string) => Promise<import("../../_api/daeryuntalk/type/response").IDaeryunTalkResponseWrapper<import("../../_api/daeryuntalk/type/response").HistoryListResponse>>;
|
|
19
|
-
startChat: () => Promise<string
|
|
19
|
+
startChat: (inquiryNumber?: string) => Promise<string | {
|
|
20
|
+
error: unknown;
|
|
21
|
+
}>;
|
|
20
22
|
sendMessage: (htmlContent: string, jsonData: any, retry?: boolean) => Promise<void>;
|
|
21
23
|
createNewChat: (version?: string) => Promise<void>;
|
|
22
24
|
startWorkFlow: (data: {
|
|
@@ -16,7 +16,7 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
16
16
|
const toast = useDaeryunTalkToast();
|
|
17
17
|
const fullUrl = useFullURL();
|
|
18
18
|
// 채팅 시작 (문의하기 버튼 클릭 시)
|
|
19
|
-
const startChat = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const startChat = useCallback((inquiryNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
try {
|
|
22
22
|
setIsLoading(true);
|
|
@@ -25,9 +25,11 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
25
25
|
// 기존 문의가 있는지 확인
|
|
26
26
|
const hasExistingInquiry = (inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.progress_inquiry_number) && (inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.progress_inquiry_number.trim()) !== '';
|
|
27
27
|
let currentChatInquiryNumber = '';
|
|
28
|
-
if (hasExistingInquiry) {
|
|
28
|
+
if (hasExistingInquiry || inquiryNumber) {
|
|
29
29
|
// 기존 문의가 있는 경우, 해당 문의번호 사용
|
|
30
|
-
currentChatInquiryNumber =
|
|
30
|
+
currentChatInquiryNumber = inquiryNumber
|
|
31
|
+
? inquiryNumber
|
|
32
|
+
: (inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.progress_inquiry_number) || '';
|
|
31
33
|
console.log('[DaeryuntalkContext] 기존 문의 사용:', currentChatInquiryNumber);
|
|
32
34
|
}
|
|
33
35
|
else {
|
|
@@ -101,7 +103,8 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
101
103
|
catch (error) {
|
|
102
104
|
toast.error('문의 시작에 실패했습니다.');
|
|
103
105
|
console.error('[DaeryuntalkContext] 채팅 시작 오류:', error);
|
|
104
|
-
|
|
106
|
+
return { error }; // 에러를 던지지 않고 그대로 반환
|
|
107
|
+
// throw error;
|
|
105
108
|
}
|
|
106
109
|
finally {
|
|
107
110
|
setIsLoading(false);
|
|
@@ -46,106 +46,113 @@ export const useChatHandler = ({
|
|
|
46
46
|
const toast = useDaeryunTalkToast();
|
|
47
47
|
const fullUrl = useFullURL();
|
|
48
48
|
// 채팅 시작 (문의하기 버튼 클릭 시)
|
|
49
|
-
const startChat = useCallback(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const startChat = useCallback(
|
|
50
|
+
async (inquiryNumber?: string) => {
|
|
51
|
+
try {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
console.log('[DaeryuntalkContext] 채팅 시작 요청');
|
|
54
|
+
console.log('inquiryMainData', inquiryMainData);
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// 기존 문의가 있는지 확인
|
|
57
|
+
const hasExistingInquiry =
|
|
58
|
+
inquiryMainData?.progress_inquiry_number && inquiryMainData?.progress_inquiry_number.trim() !== '';
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
let currentChatInquiryNumber = '';
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
console.log('[DaeryuntalkContext] 새 문의 생성 시작');
|
|
68
|
-
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '', fullUrl);
|
|
69
|
-
|
|
70
|
-
if (createResponse && createResponse.data && createResponse.data.chat_inquiry_number) {
|
|
71
|
-
currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
72
|
-
console.log('[DaeryuntalkContext] 새 문의 생성 완료:', currentChatInquiryNumber);
|
|
62
|
+
if (hasExistingInquiry || inquiryNumber) {
|
|
63
|
+
// 기존 문의가 있는 경우, 해당 문의번호 사용
|
|
64
|
+
currentChatInquiryNumber = inquiryNumber
|
|
65
|
+
? inquiryNumber
|
|
66
|
+
: inquiryMainData?.progress_inquiry_number || '';
|
|
67
|
+
console.log('[DaeryuntalkContext] 기존 문의 사용:', currentChatInquiryNumber);
|
|
73
68
|
} else {
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
// 새 문의 생성
|
|
70
|
+
console.log('[DaeryuntalkContext] 새 문의 생성 시작');
|
|
71
|
+
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '', fullUrl);
|
|
72
|
+
|
|
73
|
+
if (createResponse && createResponse.data && createResponse.data.chat_inquiry_number) {
|
|
74
|
+
currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
75
|
+
console.log('[DaeryuntalkContext] 새 문의 생성 완료:', currentChatInquiryNumber);
|
|
76
|
+
} else {
|
|
77
|
+
console.error('[DaeryuntalkContext] 문의 생성 실패: 문의번호 없음');
|
|
78
|
+
throw new Error('문의 생성 실패');
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
|
-
}
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
// 문의 상세 조회
|
|
83
|
+
console.log('[DaeryuntalkContext] 문의 상세 조회 시작:', currentChatInquiryNumber);
|
|
84
|
+
const detailResponse = await getChatInquiryDetailNew(currentChatInquiryNumber);
|
|
85
|
+
console.log('[DaeryuntalkContext] 문의 상세 조회 완료:', detailResponse);
|
|
83
86
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
console.log('[DaeryuntalkContext] 문의 채팅 리스트 조회 시작:', currentChatInquiryNumber);
|
|
88
|
+
const chatList = await getChatInquiryMessageList(currentChatInquiryNumber);
|
|
89
|
+
console.log('[DaeryuntalkContext] 문의 채팅 리스트 조회 완료:', chatList);
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
// 문의 정보 저장
|
|
92
|
+
setChatInquiryNumber(currentChatInquiryNumber);
|
|
90
93
|
|
|
91
|
-
|
|
94
|
+
console.log('detailResponse.data.message_list', chatList?.data?.message_list);
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
// 메시지 처리
|
|
97
|
+
if (detailResponse.data && chatList.data) {
|
|
98
|
+
// 메세지 리스트 후처리
|
|
99
|
+
if (chatList.data?.message_list && chatList.data.message_list.length > 0) {
|
|
100
|
+
const uiMessages = chatList.data.message_list
|
|
101
|
+
.sort((a, b) => a.timestamp - b.timestamp) // timestamp 오름차순 (최신이 마지막에)
|
|
102
|
+
.map(convertApiMessageToUiMessage);
|
|
103
|
+
// const uiMessages = chatList.data.message_list
|
|
104
|
+
// .sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
|
|
105
|
+
// .map(convertApiMessageToUiMessage);
|
|
106
|
+
setMessages(uiMessages);
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
// const uiMessages = chatList.data.message_list.map(convertApiMessageToUiMessage);
|
|
109
|
+
setMessages(uiMessages);
|
|
107
110
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
console.log('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
112
|
+
}
|
|
113
|
+
if (chatList.data?.next_page_yn !== null) {
|
|
114
|
+
setIsNextPage(chatList.data.next_page_yn);
|
|
115
|
+
}
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
// 해당 문의 상태
|
|
118
|
+
if (detailResponse.data?.chat_inquiry_state_code) {
|
|
119
|
+
setInquiryStatus(detailResponse.data.chat_inquiry_state_code);
|
|
120
|
+
}
|
|
121
|
+
// 해당 문의 오브젝트
|
|
122
|
+
if (detailResponse.data?.object_expose_info) {
|
|
123
|
+
const uiObject = convertApiMessageObjectToUiMessageObject(detailResponse.data);
|
|
124
|
+
setMessageObject(uiObject);
|
|
125
|
+
}
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
// 해당 문의 상태
|
|
128
|
+
if (detailResponse.data?.chat_inquiry_state_code) {
|
|
129
|
+
setInquiryStatus(detailResponse.data.chat_inquiry_state_code);
|
|
130
|
+
}
|
|
131
|
+
// 워크플로우 스택 업데이트
|
|
132
|
+
if (detailResponse.data?.work_flow_progress_stack) {
|
|
133
|
+
setWorkFlowStack(detailResponse.data?.work_flow_progress_stack ?? []);
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
setMessages([]);
|
|
137
|
+
setInquiryStatus('');
|
|
138
|
+
setMessageObject(null);
|
|
139
|
+
setIsNextPage(null);
|
|
140
|
+
console.log('[DaeryuntalkContext] 메시지 없음');
|
|
131
141
|
}
|
|
132
|
-
} else {
|
|
133
|
-
setMessages([]);
|
|
134
|
-
setInquiryStatus('');
|
|
135
|
-
setMessageObject(null);
|
|
136
|
-
setIsNextPage(null);
|
|
137
|
-
console.log('[DaeryuntalkContext] 메시지 없음');
|
|
138
|
-
}
|
|
139
142
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
return currentChatInquiryNumber;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
toast.error('문의 시작에 실패했습니다.');
|
|
146
|
+
console.error('[DaeryuntalkContext] 채팅 시작 오류:', error);
|
|
147
|
+
return { error }; // 에러를 던지지 않고 그대로 반환
|
|
148
|
+
|
|
149
|
+
// throw error;
|
|
150
|
+
} finally {
|
|
151
|
+
setIsLoading(false);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[inquiryMainData, fullUrl]
|
|
155
|
+
);
|
|
149
156
|
|
|
150
157
|
// 선택된 히스토리의 채팅창 시작
|
|
151
158
|
const startSelectedChat = useCallback(
|
|
@@ -13,8 +13,9 @@ interface props {
|
|
|
13
13
|
setInquiryStatus: Dispatch<SetStateAction<string>>;
|
|
14
14
|
setHistoryList: Dispatch<SetStateAction<History[]>>;
|
|
15
15
|
historyList: History[];
|
|
16
|
+
inquiryMainData: IChatInquiryMainDataResponse | null;
|
|
16
17
|
}
|
|
17
|
-
export declare const useSocketEventHandler: ({ setIsConnected, setIsLoading, setMessages, setInquiryMainData, socketRef, setWorkFlowStack, setMessageObject, setInquiryStatus, setHistoryList, historyList }: props) => {
|
|
18
|
+
export declare const useSocketEventHandler: ({ setIsConnected, setIsLoading, setMessages, setInquiryMainData, socketRef, setWorkFlowStack, setMessageObject, setInquiryStatus, setHistoryList, historyList, inquiryMainData }: props) => {
|
|
18
19
|
initializeDaeryuntalk: (hashValue: string | null, version?: string) => Promise<void>;
|
|
19
20
|
sendHeartbeat: () => void;
|
|
20
21
|
sendInquiryJoined: (chatInquiryNumber: string) => void;
|
|
@@ -22,5 +23,6 @@ export declare const useSocketEventHandler: ({ setIsConnected, setIsLoading, set
|
|
|
22
23
|
sendHistoryEntered: (chatInquiryNumbers: string[]) => void;
|
|
23
24
|
sendHistoryLeft: (chatInquiryNumbers: string[]) => void;
|
|
24
25
|
sendInquiryWatching: (chatInquiryNumber: string) => void;
|
|
26
|
+
retryInquiryMain: (channelNumber: string) => Promise<import("../../_api/daeryuntalk/type/response").IDaeryunTalkResponseWrapper<IChatInquiryMainDataResponse>>;
|
|
25
27
|
};
|
|
26
28
|
export {};
|
|
@@ -8,12 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useCallback } from 'react';
|
|
11
|
-
import { initializeDaeryuntalk as apiInitializeDaeryuntalk } from '../../_api/daeryuntalk';
|
|
11
|
+
import { getChatInquiryMain, initializeDaeryuntalk as apiInitializeDaeryuntalk } from '../../_api/daeryuntalk';
|
|
12
12
|
import { convertApiMessageToUiMessage, convertSocketObjectToUiMessage } from '../../_lib';
|
|
13
13
|
import { MessageSocketType } from '../../_enums/socket_type';
|
|
14
14
|
import { InquiryStatus } from '../../_enums/ask-status';
|
|
15
15
|
import { useDaeryunTalkToast } from '../../Toast/DaeryuntalkToastProvider';
|
|
16
|
-
export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessages, setInquiryMainData, socketRef, setWorkFlowStack, setMessageObject, setInquiryStatus, setHistoryList, historyList }) => {
|
|
16
|
+
export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessages, setInquiryMainData, socketRef, setWorkFlowStack, setMessageObject, setInquiryStatus, setHistoryList, historyList, inquiryMainData }) => {
|
|
17
17
|
const toast = useDaeryunTalkToast();
|
|
18
18
|
/**
|
|
19
19
|
* 1. heartbeat
|
|
@@ -240,6 +240,13 @@ export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessage
|
|
|
240
240
|
setIsLoading(false);
|
|
241
241
|
}
|
|
242
242
|
}), [historyList]);
|
|
243
|
+
// C2121045680881362573
|
|
244
|
+
const retryInquiryMain = useCallback((channelNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
const result = yield getChatInquiryMain(channelNumber || '');
|
|
246
|
+
console.log('리트ㅏ링 데이터', result.data);
|
|
247
|
+
setInquiryMainData(result.data);
|
|
248
|
+
return result;
|
|
249
|
+
}), [inquiryMainData]);
|
|
243
250
|
return {
|
|
244
251
|
initializeDaeryuntalk,
|
|
245
252
|
sendHeartbeat,
|
|
@@ -247,6 +254,7 @@ export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessage
|
|
|
247
254
|
sendInquiryLeft,
|
|
248
255
|
sendHistoryEntered,
|
|
249
256
|
sendHistoryLeft,
|
|
250
|
-
sendInquiryWatching
|
|
257
|
+
sendInquiryWatching,
|
|
258
|
+
retryInquiryMain
|
|
251
259
|
};
|
|
252
260
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Dispatch, MutableRefObject, SetStateAction, useCallback, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
followupAttend,
|
|
5
|
+
getChatInquiryMain,
|
|
6
|
+
initializeDaeryuntalk as apiInitializeDaeryuntalk
|
|
7
|
+
} from '../../_api/daeryuntalk';
|
|
4
8
|
import { Message } from '../../_types/message';
|
|
5
9
|
import { History, IChatInquiryMainDataResponse } from '../../_api/daeryuntalk/type/response';
|
|
6
10
|
import { convertApiMessageToUiMessage, convertSocketObjectToUiMessage } from '../../_lib';
|
|
@@ -21,6 +25,7 @@ interface props {
|
|
|
21
25
|
setInquiryStatus: Dispatch<SetStateAction<string>>;
|
|
22
26
|
setHistoryList: Dispatch<SetStateAction<History[]>>;
|
|
23
27
|
historyList: History[];
|
|
28
|
+
inquiryMainData: IChatInquiryMainDataResponse | null;
|
|
24
29
|
}
|
|
25
30
|
export const useSocketEventHandler = ({
|
|
26
31
|
setIsConnected,
|
|
@@ -32,7 +37,8 @@ export const useSocketEventHandler = ({
|
|
|
32
37
|
setMessageObject,
|
|
33
38
|
setInquiryStatus,
|
|
34
39
|
setHistoryList,
|
|
35
|
-
historyList
|
|
40
|
+
historyList,
|
|
41
|
+
inquiryMainData
|
|
36
42
|
}: props) => {
|
|
37
43
|
const toast = useDaeryunTalkToast();
|
|
38
44
|
/**
|
|
@@ -305,6 +311,17 @@ export const useSocketEventHandler = ({
|
|
|
305
311
|
[historyList]
|
|
306
312
|
);
|
|
307
313
|
|
|
314
|
+
// C2121045680881362573
|
|
315
|
+
const retryInquiryMain = useCallback(
|
|
316
|
+
async (channelNumber: string) => {
|
|
317
|
+
const result = await getChatInquiryMain(channelNumber || '');
|
|
318
|
+
console.log('리트ㅏ링 데이터', result.data);
|
|
319
|
+
setInquiryMainData(result.data as IChatInquiryMainDataResponse);
|
|
320
|
+
return result;
|
|
321
|
+
},
|
|
322
|
+
[inquiryMainData]
|
|
323
|
+
);
|
|
324
|
+
|
|
308
325
|
return {
|
|
309
326
|
initializeDaeryuntalk,
|
|
310
327
|
sendHeartbeat,
|
|
@@ -312,6 +329,7 @@ export const useSocketEventHandler = ({
|
|
|
312
329
|
sendInquiryLeft,
|
|
313
330
|
sendHistoryEntered,
|
|
314
331
|
sendHistoryLeft,
|
|
315
|
-
sendInquiryWatching
|
|
332
|
+
sendInquiryWatching,
|
|
333
|
+
retryInquiryMain
|
|
316
334
|
};
|
|
317
335
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// todo 올바른 타입 정의 필요
|
|
2
2
|
import { InquiryMessageTemplateType } from '../_enums/template';
|
|
3
|
-
import { isEmptyHtml } from '../_lib/utils';
|
|
4
3
|
// 메시지에 특정 컨텐츠가 있는지 확인하는 헬퍼 함수들
|
|
5
4
|
export const hasBlocks = (message) => !!message.blocks && message.blocks.length > 0;
|
|
6
5
|
//
|
|
7
|
-
export const hasRichForm = (message) =>
|
|
6
|
+
export const hasRichForm = (message) => !!(message.richText && message.richText.structuredData);
|
|
8
7
|
// 사용자가 워크플로우 대답 클릭한거
|
|
9
8
|
export const hasCustomerWorkFlowClickData = (message) => message.templateType === InquiryMessageTemplateType.WORK_FLOW_TEMPLATE_3;
|
|
10
9
|
export const hasButtons = (message) => !!message.buttons && message.buttons.length > 0;
|
|
@@ -125,8 +125,7 @@ export interface Message {
|
|
|
125
125
|
export const hasBlocks = (message: Message): boolean => !!message.blocks && message.blocks.length > 0;
|
|
126
126
|
|
|
127
127
|
//
|
|
128
|
-
export const hasRichForm = (message: Message): boolean =>
|
|
129
|
-
!!(message.richText && message.richText.structuredData && isEmptyHtml(message?.richText?.htmlContent));
|
|
128
|
+
export const hasRichForm = (message: Message): boolean => !!(message.richText && message.richText.structuredData);
|
|
130
129
|
|
|
131
130
|
// 사용자가 워크플로우 대답 클릭한거
|
|
132
131
|
export const hasCustomerWorkFlowClickData = (message: Message): boolean =>
|
package/dist/styles/globals.css
CHANGED