@daeryun/dr_components 0.6.34 → 0.6.35
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/Daeryuntalk/ChatButton.d.ts +7 -0
- package/dist/Daeryuntalk/ChatButton.jsx +37 -0
- package/dist/Daeryuntalk/ChatButton.tsx +63 -0
- package/dist/Daeryuntalk/ChatConversation.d.ts +6 -0
- package/dist/Daeryuntalk/ChatConversation.jsx +74 -0
- package/dist/Daeryuntalk/ChatConversation.tsx +109 -0
- package/dist/Daeryuntalk/ChatHomeView.d.ts +3 -0
- package/dist/Daeryuntalk/ChatHomeView.jsx +93 -0
- package/dist/Daeryuntalk/ChatHomeView.tsx +158 -0
- package/dist/Daeryuntalk/ChatInput.d.ts +3 -0
- package/dist/Daeryuntalk/ChatInput.jsx +23 -0
- package/dist/Daeryuntalk/ChatInput.tsx +42 -0
- package/dist/Daeryuntalk/ChatMessage.d.ts +7 -0
- package/dist/Daeryuntalk/ChatMessage.jsx +88 -0
- package/dist/Daeryuntalk/ChatMessage.tsx +153 -0
- package/dist/Daeryuntalk/ChatWidget.d.ts +6 -0
- package/dist/Daeryuntalk/ChatWidget.jsx +12 -0
- package/dist/Daeryuntalk/ChatWidget.tsx +22 -0
- package/dist/Daeryuntalk/DaeryuntalkContext.d.ts +20 -0
- package/dist/Daeryuntalk/DaeryuntalkContext.jsx +455 -0
- package/dist/Daeryuntalk/DaeryuntalkContext.tsx +530 -0
- package/dist/Daeryuntalk/DateSeparator.d.ts +6 -0
- package/dist/Daeryuntalk/DateSeparator.jsx +13 -0
- package/dist/Daeryuntalk/DateSeparator.tsx +23 -0
- package/dist/Daeryuntalk/HistoryView.d.ts +8 -0
- package/dist/Daeryuntalk/HistoryView.jsx +68 -0
- package/dist/Daeryuntalk/HistoryView.tsx +98 -0
- package/dist/Daeryuntalk/NavigationFooter.d.ts +8 -0
- package/dist/Daeryuntalk/NavigationFooter.jsx +23 -0
- package/dist/Daeryuntalk/NavigationFooter.tsx +55 -0
- package/dist/Daeryuntalk/NoticeMessage.d.ts +6 -0
- package/dist/Daeryuntalk/NoticeMessage.jsx +23 -0
- package/dist/Daeryuntalk/NoticeMessage.tsx +45 -0
- package/dist/Daeryuntalk/index.jsx +25 -0
- package/dist/Daeryuntalk/index.tsx +33 -0
- package/dist/Daeryuntalk/message-components/FileContent.d.ts +8 -0
- package/dist/Daeryuntalk/message-components/FileContent.jsx +32 -0
- package/dist/Daeryuntalk/message-components/FileContent.tsx +43 -0
- package/dist/Daeryuntalk/message-components/FormContent.d.ts +8 -0
- package/dist/Daeryuntalk/message-components/FormContent.jsx +104 -0
- package/dist/Daeryuntalk/message-components/FormContent.tsx +184 -0
- package/dist/Daeryuntalk/socketManager.d.ts +22 -0
- package/dist/Daeryuntalk/socketManager.js +96 -0
- package/dist/Daeryuntalk/socketManager.ts +123 -0
- package/dist/Daeryuntalk/types.d.ts +75 -0
- package/dist/Daeryuntalk/types.js +80 -0
- package/dist/Daeryuntalk/types.ts +174 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/styles/globals.css +639 -255
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Form, FormInput } from '../types';
|
|
3
|
+
import { useDaeryuntalk } from '../DaeryuntalkContext';
|
|
4
|
+
|
|
5
|
+
interface FormContentProps {
|
|
6
|
+
form: Form;
|
|
7
|
+
messageId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const FormContent: React.FC<FormContentProps> = ({ form, messageId }) => {
|
|
11
|
+
const { submitForm } = useDaeryuntalk();
|
|
12
|
+
const [formData, setFormData] = useState<Record<string, string>>({});
|
|
13
|
+
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
14
|
+
|
|
15
|
+
const handleInputChange = (input: FormInput, value: string) => {
|
|
16
|
+
setFormData(prev => ({
|
|
17
|
+
...prev,
|
|
18
|
+
[input.bindingKey || input.label]: value
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
// 사용자가 입력할 때 해당 필드의 오류 제거
|
|
22
|
+
if (errors[input.bindingKey || input.label]) {
|
|
23
|
+
setErrors(prev => {
|
|
24
|
+
const newErrors = { ...prev };
|
|
25
|
+
delete newErrors[input.bindingKey || input.label];
|
|
26
|
+
return newErrors;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const validateForm = (): boolean => {
|
|
32
|
+
const newErrors: Record<string, string> = {};
|
|
33
|
+
let isValid = true;
|
|
34
|
+
|
|
35
|
+
form.inputs.forEach(input => {
|
|
36
|
+
const key = input.bindingKey || input.label;
|
|
37
|
+
|
|
38
|
+
if (input.required && !formData[key]) {
|
|
39
|
+
newErrors[key] = `${input.label}은(는) 필수 입력 항목입니다.`;
|
|
40
|
+
isValid = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 전화번호 유효성 검사
|
|
44
|
+
if (input.type === 'phone' && formData[key]) {
|
|
45
|
+
const phoneRegex = /^[0-9]{10,11}$/;
|
|
46
|
+
if (!phoneRegex.test(formData[key].replace(/-/g, ''))) {
|
|
47
|
+
newErrors[key] = '유효한 전화번호를 입력해주세요.';
|
|
48
|
+
isValid = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 이메일 유효성 검사
|
|
53
|
+
if (input.type === 'email' && formData[key]) {
|
|
54
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
55
|
+
if (!emailRegex.test(formData[key])) {
|
|
56
|
+
newErrors[key] = '유효한 이메일 주소를 입력해주세요.';
|
|
57
|
+
isValid = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
setErrors(newErrors);
|
|
63
|
+
return isValid;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const handleSubmit = (e: React.FormEvent) => {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
|
|
69
|
+
if (validateForm()) {
|
|
70
|
+
submitForm(messageId, formData);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const renderFormInput = (input: FormInput) => {
|
|
75
|
+
const key = input.bindingKey || input.label;
|
|
76
|
+
|
|
77
|
+
switch (input.type) {
|
|
78
|
+
case 'select':
|
|
79
|
+
return (
|
|
80
|
+
<select
|
|
81
|
+
value={formData[key] || ''}
|
|
82
|
+
onChange={e => handleInputChange(input, e.target.value)}
|
|
83
|
+
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
84
|
+
disabled={input.readOnly}
|
|
85
|
+
>
|
|
86
|
+
<option value="">선택하세요</option>
|
|
87
|
+
{input.options?.map(option => (
|
|
88
|
+
<option key={option.value} value={option.value}>
|
|
89
|
+
{option.label}
|
|
90
|
+
</option>
|
|
91
|
+
))}
|
|
92
|
+
</select>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
case 'textarea':
|
|
96
|
+
return (
|
|
97
|
+
<textarea
|
|
98
|
+
value={formData[key] || ''}
|
|
99
|
+
onChange={e => handleInputChange(input, e.target.value)}
|
|
100
|
+
placeholder={input.placeholder}
|
|
101
|
+
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
102
|
+
rows={4}
|
|
103
|
+
disabled={input.readOnly}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
case 'date':
|
|
108
|
+
return (
|
|
109
|
+
<input
|
|
110
|
+
type="date"
|
|
111
|
+
value={formData[key] || ''}
|
|
112
|
+
onChange={e => handleInputChange(input, e.target.value)}
|
|
113
|
+
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
114
|
+
disabled={input.readOnly}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
case 'checkbox':
|
|
119
|
+
return (
|
|
120
|
+
<div className="flex items-center">
|
|
121
|
+
<input
|
|
122
|
+
type="checkbox"
|
|
123
|
+
checked={formData[key] === 'true'}
|
|
124
|
+
onChange={e => handleInputChange(input, e.target.checked ? 'true' : 'false')}
|
|
125
|
+
className="mr-2 h-4 w-4 text-[#AA1D36]"
|
|
126
|
+
disabled={input.readOnly}
|
|
127
|
+
/>
|
|
128
|
+
<span className="text-sm">{input.label}</span>
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
default:
|
|
133
|
+
return (
|
|
134
|
+
<input
|
|
135
|
+
type={input.type === 'email' ? 'email' : input.type === 'phone' ? 'tel' : 'text'}
|
|
136
|
+
value={formData[key] || ''}
|
|
137
|
+
onChange={e => handleInputChange(input, e.target.value)}
|
|
138
|
+
placeholder={input.placeholder}
|
|
139
|
+
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
140
|
+
disabled={input.readOnly}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div className="mt-2 w-full">
|
|
148
|
+
<div className="rounded-[10px] border border-[#EDEDED] bg-white p-3">
|
|
149
|
+
<form onSubmit={handleSubmit}>
|
|
150
|
+
<div className="space-y-4">
|
|
151
|
+
{form.inputs.map((input, index) => {
|
|
152
|
+
const key = input.bindingKey || input.label;
|
|
153
|
+
const isCheckbox = input.type === 'checkbox';
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div key={index} className="flex flex-col">
|
|
157
|
+
{!isCheckbox && (
|
|
158
|
+
<label className="mb-1 text-sm font-medium">
|
|
159
|
+
{input.label}
|
|
160
|
+
{input.required && <span className="ml-1 text-[#AA1D36]">*</span>}
|
|
161
|
+
</label>
|
|
162
|
+
)}
|
|
163
|
+
|
|
164
|
+
{renderFormInput(input)}
|
|
165
|
+
|
|
166
|
+
{errors[key] && <p className="mt-1 text-xs text-[#AA1D36]">{errors[key]}</p>}
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
169
|
+
})}
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
<button
|
|
173
|
+
type="submit"
|
|
174
|
+
className="mt-4 rounded-md bg-[#2E385B] px-4 py-2 text-sm font-medium text-white hover:bg-opacity-90"
|
|
175
|
+
>
|
|
176
|
+
{form.submitButton || '저장'}
|
|
177
|
+
</button>
|
|
178
|
+
</form>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export default FormContent;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type SocketEventHandlers = {
|
|
2
|
+
onConnect?: () => void;
|
|
3
|
+
onDisconnect?: () => void;
|
|
4
|
+
onMessage?: (data: any) => void;
|
|
5
|
+
onError?: (error: Event) => void;
|
|
6
|
+
};
|
|
7
|
+
declare class SocketManager {
|
|
8
|
+
private socket;
|
|
9
|
+
private url;
|
|
10
|
+
private handlers;
|
|
11
|
+
private reconnectAttempts;
|
|
12
|
+
private maxReconnectAttempts;
|
|
13
|
+
private reconnectTimeout;
|
|
14
|
+
constructor(url: string, handlers?: SocketEventHandlers);
|
|
15
|
+
connect(): void;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
send(data: any): boolean;
|
|
18
|
+
private attemptReconnect;
|
|
19
|
+
isConnected(): boolean;
|
|
20
|
+
updateHandlers(handlers: SocketEventHandlers): void;
|
|
21
|
+
}
|
|
22
|
+
export default SocketManager;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// todo: trophy198 소켓 연결 관리 클래스 적용
|
|
2
|
+
class SocketManager {
|
|
3
|
+
constructor(url, handlers = {}) {
|
|
4
|
+
this.socket = null;
|
|
5
|
+
this.reconnectAttempts = 0;
|
|
6
|
+
this.maxReconnectAttempts = 5;
|
|
7
|
+
this.reconnectTimeout = null;
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.handlers = handlers;
|
|
10
|
+
}
|
|
11
|
+
connect() {
|
|
12
|
+
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
this.socket = new WebSocket(this.url);
|
|
17
|
+
this.socket.onopen = () => {
|
|
18
|
+
this.reconnectAttempts = 0;
|
|
19
|
+
if (this.handlers.onConnect) {
|
|
20
|
+
this.handlers.onConnect();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
this.socket.onmessage = event => {
|
|
24
|
+
if (this.handlers.onMessage) {
|
|
25
|
+
let data;
|
|
26
|
+
try {
|
|
27
|
+
data = JSON.parse(event.data);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
data = event.data;
|
|
31
|
+
}
|
|
32
|
+
this.handlers.onMessage(data);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.socket.onclose = () => {
|
|
36
|
+
if (this.handlers.onDisconnect) {
|
|
37
|
+
this.handlers.onDisconnect();
|
|
38
|
+
}
|
|
39
|
+
this.attemptReconnect();
|
|
40
|
+
};
|
|
41
|
+
this.socket.onerror = error => {
|
|
42
|
+
if (this.handlers.onError) {
|
|
43
|
+
this.handlers.onError(error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error('소켓 연결 오류:', e);
|
|
49
|
+
this.attemptReconnect();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
disconnect() {
|
|
53
|
+
if (this.reconnectTimeout) {
|
|
54
|
+
clearTimeout(this.reconnectTimeout);
|
|
55
|
+
this.reconnectTimeout = null;
|
|
56
|
+
}
|
|
57
|
+
if (this.socket) {
|
|
58
|
+
this.socket.close();
|
|
59
|
+
this.socket = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
send(data) {
|
|
63
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
68
|
+
this.socket.send(message);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error('메시지 전송 오류:', e);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
attemptReconnect() {
|
|
77
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
78
|
+
console.error('최대 재연결 시도 횟수 도달');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
this.reconnectAttempts++;
|
|
82
|
+
// 지수 백오프 적용
|
|
83
|
+
const timeout = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
|
|
84
|
+
this.reconnectTimeout = setTimeout(() => {
|
|
85
|
+
console.log(`재연결 시도 중... 시도 ${this.reconnectAttempts}`);
|
|
86
|
+
this.connect();
|
|
87
|
+
}, timeout);
|
|
88
|
+
}
|
|
89
|
+
isConnected() {
|
|
90
|
+
return this.socket !== null && this.socket.readyState === WebSocket.OPEN;
|
|
91
|
+
}
|
|
92
|
+
updateHandlers(handlers) {
|
|
93
|
+
this.handlers = Object.assign(Object.assign({}, this.handlers), handlers);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export default SocketManager;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// 소켓 연결 관리 타입
|
|
2
|
+
type SocketEventHandlers = {
|
|
3
|
+
onConnect?: () => void;
|
|
4
|
+
onDisconnect?: () => void;
|
|
5
|
+
onMessage?: (data: any) => void;
|
|
6
|
+
onError?: (error: Event) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// todo: trophy198 소켓 연결 관리 클래스 적용
|
|
10
|
+
class SocketManager {
|
|
11
|
+
private socket: WebSocket | null = null;
|
|
12
|
+
private url: string;
|
|
13
|
+
private handlers: SocketEventHandlers;
|
|
14
|
+
private reconnectAttempts: number = 0;
|
|
15
|
+
private maxReconnectAttempts: number = 5;
|
|
16
|
+
private reconnectTimeout: NodeJS.Timeout | null = null;
|
|
17
|
+
|
|
18
|
+
constructor(url: string, handlers: SocketEventHandlers = {}) {
|
|
19
|
+
this.url = url;
|
|
20
|
+
this.handlers = handlers;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connect(): void {
|
|
24
|
+
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
this.socket = new WebSocket(this.url);
|
|
30
|
+
|
|
31
|
+
this.socket.onopen = () => {
|
|
32
|
+
this.reconnectAttempts = 0;
|
|
33
|
+
|
|
34
|
+
if (this.handlers.onConnect) {
|
|
35
|
+
this.handlers.onConnect();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.socket.onmessage = event => {
|
|
40
|
+
if (this.handlers.onMessage) {
|
|
41
|
+
let data;
|
|
42
|
+
try {
|
|
43
|
+
data = JSON.parse(event.data);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
data = event.data;
|
|
46
|
+
}
|
|
47
|
+
this.handlers.onMessage(data);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.socket.onclose = () => {
|
|
52
|
+
if (this.handlers.onDisconnect) {
|
|
53
|
+
this.handlers.onDisconnect();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.attemptReconnect();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
this.socket.onerror = error => {
|
|
60
|
+
if (this.handlers.onError) {
|
|
61
|
+
this.handlers.onError(error);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error('소켓 연결 오류:', e);
|
|
66
|
+
this.attemptReconnect();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
disconnect(): void {
|
|
71
|
+
if (this.reconnectTimeout) {
|
|
72
|
+
clearTimeout(this.reconnectTimeout);
|
|
73
|
+
this.reconnectTimeout = null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (this.socket) {
|
|
77
|
+
this.socket.close();
|
|
78
|
+
this.socket = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
send(data: any): boolean {
|
|
83
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
89
|
+
this.socket.send(message);
|
|
90
|
+
return true;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error('메시지 전송 오류:', e);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private attemptReconnect(): void {
|
|
98
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
99
|
+
console.error('최대 재연결 시도 횟수 도달');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.reconnectAttempts++;
|
|
104
|
+
|
|
105
|
+
// 지수 백오프 적용
|
|
106
|
+
const timeout = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
|
|
107
|
+
|
|
108
|
+
this.reconnectTimeout = setTimeout(() => {
|
|
109
|
+
console.log(`재연결 시도 중... 시도 ${this.reconnectAttempts}`);
|
|
110
|
+
this.connect();
|
|
111
|
+
}, timeout);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
isConnected(): boolean {
|
|
115
|
+
return this.socket !== null && this.socket.readyState === WebSocket.OPEN;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
updateHandlers(handlers: SocketEventHandlers): void {
|
|
119
|
+
this.handlers = { ...this.handlers, ...handlers };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default SocketManager;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type MessageSender = 'user' | 'system';
|
|
2
|
+
export interface TextBlock {
|
|
3
|
+
type: 'text';
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Button {
|
|
7
|
+
id: string;
|
|
8
|
+
text: string;
|
|
9
|
+
action: 'send' | 'url' | 'form';
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
export type FormInputType = 'text' | 'phone' | 'email' | 'select' | 'textarea' | 'date' | 'checkbox';
|
|
13
|
+
export interface FormInput {
|
|
14
|
+
type: FormInputType;
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
readOnly?: boolean;
|
|
20
|
+
bindingKey?: string;
|
|
21
|
+
options?: Array<{
|
|
22
|
+
value: string;
|
|
23
|
+
label: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export interface Form {
|
|
27
|
+
type: string;
|
|
28
|
+
inputs: FormInput[];
|
|
29
|
+
submittedAt?: Date;
|
|
30
|
+
submitButton?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface FileInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
url: string;
|
|
35
|
+
fileType?: string;
|
|
36
|
+
size?: number;
|
|
37
|
+
thumbnailUrl?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ImageInfo {
|
|
40
|
+
url: string;
|
|
41
|
+
alt?: string;
|
|
42
|
+
caption?: string;
|
|
43
|
+
width?: number;
|
|
44
|
+
height?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface Message {
|
|
47
|
+
msgNo: string;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt?: Date;
|
|
50
|
+
userNo?: string;
|
|
51
|
+
centerCd?: string;
|
|
52
|
+
msgIconUrl?: string;
|
|
53
|
+
userType?: string;
|
|
54
|
+
inquiryNo?: string;
|
|
55
|
+
msgStatus?: string;
|
|
56
|
+
msgType?: string;
|
|
57
|
+
isBot?: boolean;
|
|
58
|
+
language?: string;
|
|
59
|
+
plainText: string;
|
|
60
|
+
sender: MessageSender;
|
|
61
|
+
blocks?: TextBlock[];
|
|
62
|
+
buttons?: Button[];
|
|
63
|
+
form?: Form;
|
|
64
|
+
files?: FileInfo[];
|
|
65
|
+
images?: ImageInfo[];
|
|
66
|
+
webPage?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare const hasBlocks: (message: Message) => boolean;
|
|
69
|
+
export declare const hasButtons: (message: Message) => boolean;
|
|
70
|
+
export declare const hasForm: (message: Message) => boolean;
|
|
71
|
+
export declare const hasFiles: (message: Message) => boolean;
|
|
72
|
+
export declare const hasImages: (message: Message) => boolean;
|
|
73
|
+
export declare const hasWebPage: (message: Message) => boolean;
|
|
74
|
+
export type LegacyMessageType = 'text' | 'form' | 'quick_replies' | 'image' | 'file';
|
|
75
|
+
export declare const convertLegacyMessage: (legacyMessage: any) => Message;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// todo : trophy198 올바른 타입 정의 필요
|
|
2
|
+
// 메시지에 특정 컨텐츠가 있는지 확인하는 헬퍼 함수들
|
|
3
|
+
export const hasBlocks = (message) => !!message.blocks && message.blocks.length > 0;
|
|
4
|
+
export const hasButtons = (message) => !!message.buttons && message.buttons.length > 0;
|
|
5
|
+
export const hasForm = (message) => !!message.form;
|
|
6
|
+
export const hasFiles = (message) => !!message.files && message.files.length > 0;
|
|
7
|
+
export const hasImages = (message) => !!message.images && message.images.length > 0;
|
|
8
|
+
export const hasWebPage = (message) => !!message.webPage;
|
|
9
|
+
// 레거시 메시지를 새 형식으로 변환하는 함수
|
|
10
|
+
export const convertLegacyMessage = (legacyMessage) => {
|
|
11
|
+
const newMessage = {
|
|
12
|
+
msgNo: legacyMessage.id,
|
|
13
|
+
createdAt: legacyMessage.timestamp,
|
|
14
|
+
plainText: '',
|
|
15
|
+
sender: legacyMessage.sender,
|
|
16
|
+
blocks: []
|
|
17
|
+
};
|
|
18
|
+
if (legacyMessage.type === 'text' && legacyMessage.text) {
|
|
19
|
+
newMessage.plainText = legacyMessage.text;
|
|
20
|
+
newMessage.blocks = [
|
|
21
|
+
{
|
|
22
|
+
type: 'text',
|
|
23
|
+
value: legacyMessage.text
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
if (legacyMessage.type === 'image' && legacyMessage.url) {
|
|
28
|
+
newMessage.plainText = legacyMessage.caption || '이미지';
|
|
29
|
+
newMessage.images = [
|
|
30
|
+
{
|
|
31
|
+
url: legacyMessage.url,
|
|
32
|
+
alt: legacyMessage.alt,
|
|
33
|
+
caption: legacyMessage.caption
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
if (legacyMessage.type === 'file' && legacyMessage.url) {
|
|
38
|
+
newMessage.plainText = '파일';
|
|
39
|
+
newMessage.files = [
|
|
40
|
+
{
|
|
41
|
+
name: legacyMessage.name,
|
|
42
|
+
url: legacyMessage.url,
|
|
43
|
+
fileType: legacyMessage.fileType,
|
|
44
|
+
size: legacyMessage.size
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
if (legacyMessage.type === 'form' && legacyMessage.fields) {
|
|
49
|
+
newMessage.plainText = legacyMessage.description || '폼';
|
|
50
|
+
newMessage.form = {
|
|
51
|
+
type: 'basic',
|
|
52
|
+
inputs: legacyMessage.fields.map((field) => ({
|
|
53
|
+
type: field.type,
|
|
54
|
+
label: field.label,
|
|
55
|
+
value: '',
|
|
56
|
+
placeholder: field.placeholder,
|
|
57
|
+
required: field.required,
|
|
58
|
+
options: field.options
|
|
59
|
+
})),
|
|
60
|
+
submitButton: legacyMessage.submitButton
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (legacyMessage.type === 'quick_replies' && legacyMessage.text) {
|
|
64
|
+
newMessage.plainText = legacyMessage.text;
|
|
65
|
+
newMessage.blocks = [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
value: legacyMessage.text
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
// 빠른 답변을 버튼으로 변환
|
|
72
|
+
newMessage.buttons = legacyMessage.replies.map((reply) => ({
|
|
73
|
+
id: reply.id,
|
|
74
|
+
text: reply.text,
|
|
75
|
+
action: reply.action,
|
|
76
|
+
value: reply.value
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
return newMessage;
|
|
80
|
+
};
|