@channelhub/widget 0.1.12 → 0.1.14
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/README.md +168 -0
- package/dist/ChannelHubInbox.d.ts.map +1 -1
- package/dist/ChannelHubSettings.d.ts +3 -0
- package/dist/ChannelHubSettings.d.ts.map +1 -0
- package/dist/api.d.ts +16 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +100 -30
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4900 -2764
- package/dist/types.d.ts +224 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelHubInbox.tsx +168 -14
- package/src/ChannelHubSettings.tsx +1846 -0
- package/src/api.ts +163 -2
- package/src/index.ts +18 -2
- package/src/types.ts +223 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Supported messaging channel providers in ChannelHub.
|
|
4
|
+
*/
|
|
5
|
+
export type Provider = 'facebook' | 'instagram' | 'telegram' | 'zalo' | 'livechat' | 'whatsapp' | string;
|
|
3
6
|
export type Connection = {
|
|
4
7
|
id: string;
|
|
5
8
|
provider: Provider;
|
|
6
9
|
type?: string;
|
|
7
10
|
metadata?: Record<string, unknown>;
|
|
8
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Represents a staff member / support agent in the host application (CRM / POS / ERP).
|
|
14
|
+
* Used for conversation assignment (`assignedAgent`) and message attribution (`senderAgent`).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const currentAgent: ChannelHubAgent = {
|
|
18
|
+
* id: 'emp_101',
|
|
19
|
+
* name: 'Nguyễn Văn A',
|
|
20
|
+
* title: 'Tư vấn viên',
|
|
21
|
+
* avatarUrl: 'https://example.com/avatar.png',
|
|
22
|
+
* };
|
|
23
|
+
*/
|
|
9
24
|
export interface ChannelHubAgent {
|
|
25
|
+
/** Unique staff ID from the host platform/CRM */
|
|
10
26
|
id: string;
|
|
27
|
+
/** Display name shown on conversation badges and message bubbles */
|
|
11
28
|
name: string;
|
|
29
|
+
/** Optional avatar URL */
|
|
12
30
|
avatarUrl?: string;
|
|
31
|
+
/** Optional role/title (e.g., "Sale", "CSKH", "Lễ tân") */
|
|
13
32
|
title?: string;
|
|
33
|
+
/** Optional custom metadata from host platform */
|
|
14
34
|
metadata?: Record<string, unknown>;
|
|
15
35
|
}
|
|
16
36
|
export type Conversation = {
|
|
@@ -68,6 +88,7 @@ export interface ExtensionContact {
|
|
|
68
88
|
name?: string;
|
|
69
89
|
pictureUrl?: string;
|
|
70
90
|
providerUserId: string;
|
|
91
|
+
/** External CRM customer ID linked via `ctx.linkContact(externalId)` */
|
|
71
92
|
externalId?: string;
|
|
72
93
|
}
|
|
73
94
|
export interface ExtensionContext {
|
|
@@ -75,8 +96,11 @@ export interface ExtensionContext {
|
|
|
75
96
|
contact: ExtensionContact;
|
|
76
97
|
provider?: Provider;
|
|
77
98
|
recentMessages?: Message[];
|
|
99
|
+
/** Link or unlink this chat contact with an external CRM customer ID */
|
|
78
100
|
linkContact: (externalId: string | null) => Promise<void>;
|
|
101
|
+
/** Trigger re-fetching of `contactInfoRows` across all registered extensions */
|
|
79
102
|
refreshContactInfo: () => void;
|
|
103
|
+
/** Programmatically send a message into the active conversation */
|
|
80
104
|
sendMessage: (text?: string, attachments?: MessageAttachment[]) => Promise<void>;
|
|
81
105
|
}
|
|
82
106
|
export interface ContactInfoRow {
|
|
@@ -108,12 +132,202 @@ export interface MessageEnrichment {
|
|
|
108
132
|
pattern: RegExp;
|
|
109
133
|
render: (match: RegExpMatchArray, ctx: ExtensionContext, message: Message) => React.ReactNode;
|
|
110
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Extension hook interface allowing host platforms (CRM, POS, Clinic, E-commerce)
|
|
137
|
+
* to inject custom customer data rows, sidebar CTA buttons, composer toolbar actions,
|
|
138
|
+
* and inline message regex enrichments into `<ChannelHubInbox />`.
|
|
139
|
+
*/
|
|
111
140
|
export interface Extension {
|
|
112
141
|
contactInfoRows?: (ctx: ExtensionContext) => Promise<ContactInfoRow[]>;
|
|
113
142
|
sidebarActions?: SidebarAction[];
|
|
114
143
|
toolbarActions?: ToolbarAction[];
|
|
115
144
|
messageEnrichments?: MessageEnrichment[];
|
|
116
145
|
}
|
|
146
|
+
export interface CannedResponse {
|
|
147
|
+
id: string;
|
|
148
|
+
title: string;
|
|
149
|
+
content: string;
|
|
150
|
+
shortcut: string | null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* - `'off'`: AI is disabled.
|
|
154
|
+
* - `'copilot'`: AI suggests replies/drafts to human agents; does not auto-send.
|
|
155
|
+
* - `'autopilot'`: AI automatically replies when conversation is unassigned (`assignedAgent === null`).
|
|
156
|
+
*/
|
|
157
|
+
export type ChannelHubAiMode = 'off' | 'copilot' | 'autopilot';
|
|
158
|
+
export type ChannelHubAiTone = 'friendly' | 'professional' | 'concise';
|
|
159
|
+
export type ChannelHubAiProvider = 'webhook' | 'openai' | 'gemini' | 'anthropic';
|
|
160
|
+
/**
|
|
161
|
+
* Schema definition for a platform-specific business parameter rendered inside `<ChannelHubSettings />`.
|
|
162
|
+
*
|
|
163
|
+
* When a SaaS Platform embeds ChannelHub for its end-merchants (tenants), the Platform can define
|
|
164
|
+
* domain-specific fields (e.g. `allowStockCheck`, `bookingLink`, `shippingPolicy`).
|
|
165
|
+
* User inputs are persisted in `settings.ai.parameters[key]` via `PUT /v1/settings` and can be
|
|
166
|
+
* retrieved by the Platform's AI backend via `GET /v1/settings` or `onSettingsChange`.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const customParameters: ChannelHubCustomParameter[] = [
|
|
170
|
+
* {
|
|
171
|
+
* key: 'allowStockCheck',
|
|
172
|
+
* type: 'toggle',
|
|
173
|
+
* label: 'Cho phép AI tự tra cứu & báo tồn kho',
|
|
174
|
+
* description: 'AI tự động kiểm tra tồn kho thực tế từ POS trước khi trả lời khách',
|
|
175
|
+
* defaultValue: true,
|
|
176
|
+
* },
|
|
177
|
+
* {
|
|
178
|
+
* key: 'shippingPolicy',
|
|
179
|
+
* type: 'textarea',
|
|
180
|
+
* label: 'Chính sách giao hàng & đổi trả của shop',
|
|
181
|
+
* placeholder: 'VD: Freeship đơn từ 300k, đổi trả trong 7 ngày...',
|
|
182
|
+
* },
|
|
183
|
+
* ];
|
|
184
|
+
*/
|
|
185
|
+
export interface ChannelHubCustomParameter {
|
|
186
|
+
/** Unique parameter key saved under `settings.ai.parameters[key]` */
|
|
187
|
+
key: string;
|
|
188
|
+
/** UI control type rendered in `<ChannelHubSettings />` */
|
|
189
|
+
type: 'toggle' | 'text' | 'textarea' | 'select';
|
|
190
|
+
/** Human-readable label shown to the shop owner / admin */
|
|
191
|
+
label: string;
|
|
192
|
+
/** Optional helper text explaining what this parameter controls */
|
|
193
|
+
description?: string;
|
|
194
|
+
/** Placeholder text for `'text'` and `'textarea'` inputs */
|
|
195
|
+
placeholder?: string;
|
|
196
|
+
/** Default value applied if the tenant has not configured this parameter yet */
|
|
197
|
+
defaultValue?: string | boolean;
|
|
198
|
+
/** Dropdown options when `type === 'select'` */
|
|
199
|
+
options?: {
|
|
200
|
+
label: string;
|
|
201
|
+
value: string;
|
|
202
|
+
}[];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Tenant-level configuration stored in `tenants.settings` (JSONB) and returned by `GET /v1/settings`.
|
|
206
|
+
*/
|
|
207
|
+
export interface ChannelHubTenantSettings {
|
|
208
|
+
ai: {
|
|
209
|
+
mode: ChannelHubAiMode;
|
|
210
|
+
tone: ChannelHubAiTone;
|
|
211
|
+
/** Seconds to wait and batch consecutive customer messages before triggering AI (default: 5) */
|
|
212
|
+
debounceSeconds: number;
|
|
213
|
+
/** Automatically stop AI autopilot when a staff member claims/is assigned to the conversation */
|
|
214
|
+
autoPauseOnAgentAssign: boolean;
|
|
215
|
+
/** Automatically stop AI autopilot when a staff member manually sends a message */
|
|
216
|
+
autoPauseOnAgentReply: boolean;
|
|
217
|
+
/** Hand off to human staff when customer leaves a phone number */
|
|
218
|
+
handoffOnPhone: boolean;
|
|
219
|
+
/** Hand off to human staff when customer complains or asks for a human */
|
|
220
|
+
handoffOnComplaint: boolean;
|
|
221
|
+
schedule: 'always' | 'outside_hours';
|
|
222
|
+
businessHours: {
|
|
223
|
+
start: string;
|
|
224
|
+
end: string;
|
|
225
|
+
};
|
|
226
|
+
provider: ChannelHubAiProvider;
|
|
227
|
+
webhookUrl?: string;
|
|
228
|
+
webhookSecret?: string;
|
|
229
|
+
apiKey?: string;
|
|
230
|
+
model?: string;
|
|
231
|
+
systemPrompt?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Key-value map of custom business parameters defined by `customParameters`
|
|
234
|
+
* (e.g. `{ allowStockCheck: true, shippingPolicy: "Freeship > 300k" }`).
|
|
235
|
+
*/
|
|
236
|
+
parameters: Record<string, string | boolean>;
|
|
237
|
+
};
|
|
238
|
+
inbox: {
|
|
239
|
+
/** Automatically assign an unassigned conversation to the first agent who replies */
|
|
240
|
+
autoAssignOnFirstReply: boolean;
|
|
241
|
+
/** Play notification sound on new inbound messages */
|
|
242
|
+
soundNotification: boolean;
|
|
243
|
+
/** Quick reply chips shown above the message composer */
|
|
244
|
+
quickReplies: string[];
|
|
245
|
+
welcomeMessageEnabled: boolean;
|
|
246
|
+
welcomeMessageText: string;
|
|
247
|
+
awayMessageEnabled: boolean;
|
|
248
|
+
awayMessageText: string;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* `true` when the tenant belongs to a parent SaaS Platform (`tenants.platform_id != null`).
|
|
252
|
+
* When `true` (or when `hideTechnicalAiConfig` is passed), technical AI connection settings
|
|
253
|
+
* (API Keys, Model names, Webhook URLs) are hidden from end-user merchants.
|
|
254
|
+
*/
|
|
255
|
+
isPlatformManaged?: boolean;
|
|
256
|
+
}
|
|
257
|
+
export type ChannelHubSettingsTab = 'ai' | 'templates' | 'inbox' | 'channels';
|
|
258
|
+
/**
|
|
259
|
+
* Props for `<ChannelHubSettings />`.
|
|
260
|
+
*
|
|
261
|
+
* Supports two integration modes:
|
|
262
|
+
* 1. **Standalone Shop Mode (Direct Tenant)**: Omit `hideTechnicalAiConfig`. The shop can configure
|
|
263
|
+
* its own OpenAI/Gemini/Claude API Key, System Prompt, or External Webhook URL, plus Canned Responses.
|
|
264
|
+
* 2. **B2B2B Platform Mode (SaaS Host App)**: Set `hideTechnicalAiConfig={true}` and pass `customParameters`
|
|
265
|
+
* and `starterTemplates`. Technical AI fields are hidden, and the shop only sees easy business toggles/inputs.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* // Platform-Managed Mode example:
|
|
269
|
+
* <ChannelHubSettings
|
|
270
|
+
* apiUrl="https://api.channelhub.io.vn"
|
|
271
|
+
* token={tenantToken}
|
|
272
|
+
* hideTechnicalAiConfig={true}
|
|
273
|
+
* customParameters={[
|
|
274
|
+
* { key: 'autoCheckStock', type: 'toggle', label: 'Tự động báo tồn kho', defaultValue: true },
|
|
275
|
+
* { key: 'promoText', type: 'text', label: 'Khuyến mãi đang chạy' },
|
|
276
|
+
* ]}
|
|
277
|
+
* onSettingsChange={(updated) => console.log('Saved parameters:', updated.ai.parameters)}
|
|
278
|
+
* />
|
|
279
|
+
*/
|
|
280
|
+
export interface ChannelHubSettingsProps {
|
|
281
|
+
apiUrl: string;
|
|
282
|
+
token: string;
|
|
283
|
+
theme?: WidgetTheme;
|
|
284
|
+
/** Initial active tab (default: `'ai'`) */
|
|
285
|
+
initialTab?: ChannelHubSettingsTab;
|
|
286
|
+
/** Visible tabs (default: `['ai', 'templates', 'inbox']`; add `'channels'` to embed channel connection manager) */
|
|
287
|
+
tabs?: ChannelHubSettingsTab[];
|
|
288
|
+
/**
|
|
289
|
+
* Hide technical AI connection fields (API Key / Model / Webhook URL).
|
|
290
|
+
* Recommended when a SaaS Platform manages the AI backend centrally for its tenants.
|
|
291
|
+
*/
|
|
292
|
+
hideTechnicalAiConfig?: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Custom business parameters injected by the SaaS Platform into the AI settings tab.
|
|
295
|
+
* Values are persisted in `settings.ai.parameters` (`GET / PUT /v1/settings`).
|
|
296
|
+
*/
|
|
297
|
+
customParameters?: ChannelHubCustomParameter[];
|
|
298
|
+
/**
|
|
299
|
+
* Industry-specific starter canned responses offered when a shop has 0 templates.
|
|
300
|
+
*/
|
|
301
|
+
starterTemplates?: {
|
|
302
|
+
title: string;
|
|
303
|
+
content: string;
|
|
304
|
+
shortcut?: string;
|
|
305
|
+
}[];
|
|
306
|
+
/** Callback fired whenever settings are saved via `PUT /v1/settings` */
|
|
307
|
+
onSettingsChange?: (settings: ChannelHubTenantSettings) => void;
|
|
308
|
+
/** Optional close handler when rendered inside a modal/drawer */
|
|
309
|
+
onClose?: () => void;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Props for `<ChannelHubInbox />` — the main omnichannel messaging inbox widget.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* <ChannelHubInbox
|
|
316
|
+
* apiUrl="https://api.channelhub.io.vn"
|
|
317
|
+
* token={tenantToken}
|
|
318
|
+
* currentAgent={{ id: 'emp_1', name: 'Nguyễn Văn A', title: 'CSKH' }}
|
|
319
|
+
* teamAgents={[
|
|
320
|
+
* { id: 'emp_1', name: 'Nguyễn Văn A', title: 'CSKH' },
|
|
321
|
+
* { id: 'emp_2', name: 'Trần Thị B', title: 'Sale' },
|
|
322
|
+
* ]}
|
|
323
|
+
* settingsConfig={{
|
|
324
|
+
* hideTechnicalAiConfig: true,
|
|
325
|
+
* customParameters: [
|
|
326
|
+
* { key: 'allowStockCheck', type: 'toggle', label: 'Cho phép AI báo tồn kho', defaultValue: true },
|
|
327
|
+
* ],
|
|
328
|
+
* }}
|
|
329
|
+
* />
|
|
330
|
+
*/
|
|
117
331
|
export type WidgetProps = {
|
|
118
332
|
apiUrl: string;
|
|
119
333
|
token: string;
|
|
@@ -123,9 +337,18 @@ export type WidgetProps = {
|
|
|
123
337
|
disableAttachments?: boolean;
|
|
124
338
|
disableNotificationSound?: boolean;
|
|
125
339
|
hideKeyboardHint?: boolean;
|
|
340
|
+
/** Hide the top-left `⚙️` Settings button in the inbox sidebar header */
|
|
341
|
+
hideSettingsButton?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* Configuration forwarded to the built-in `<ChannelHubSettings />` modal
|
|
344
|
+
* when opened from the inbox `⚙️` button or `+ Quản lý mẫu câu` action.
|
|
345
|
+
*/
|
|
346
|
+
settingsConfig?: Pick<ChannelHubSettingsProps, 'tabs' | 'hideTechnicalAiConfig' | 'customParameters' | 'starterTemplates'>;
|
|
126
347
|
locale?: 'vi' | 'en';
|
|
127
348
|
extensions?: Extension[];
|
|
349
|
+
/** Currently logged-in staff member (used for "+ Nhận phụ trách" and outbound message sender attribution) */
|
|
128
350
|
currentAgent?: ChannelHubAgent | null;
|
|
351
|
+
/** List of team members available in the conversation assignment dropdown */
|
|
129
352
|
teamAgents?: ChannelHubAgent[];
|
|
130
353
|
onNewMessage?: (conversationId: string) => void;
|
|
131
354
|
onConversationSelect?: (conversationId: string) => void;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,WAAW,GAA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AG,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,cAAc,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,uBAAuB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC,CAAC;IAC3H,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,6GAA6G;IAC7G,YAAY,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACtC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,oBAAoB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD,CAAC"}
|
package/package.json
CHANGED
package/src/ChannelHubInbox.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Component, FormEvent, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
-
import { AlertCircle, ArrowLeft, Check, CheckCheck, ChevronDown, ChevronRight, Image, Inbox, Info, Loader2, MoreHorizontal, Paperclip, Play, Search, Send, SlidersHorizontal, Smile, UserCheck, UserPlus, X, Zap } from 'lucide-react';
|
|
5
|
-
import { ChannelHubClient } from './api.js';
|
|
6
|
-
import
|
|
4
|
+
import { AlertCircle, ArrowLeft, Bot, Check, CheckCheck, ChevronDown, ChevronRight, Image, Inbox, Info, Loader2, MoreHorizontal, Paperclip, Play, Search, Send, Settings, SlidersHorizontal, Smile, Sparkles, UserCheck, UserPlus, X, Zap } from 'lucide-react';
|
|
5
|
+
import { ChannelHubClient, DEFAULT_TENANT_SETTINGS } from './api.js';
|
|
6
|
+
import { ChannelHubSettings } from './ChannelHubSettings.js';
|
|
7
|
+
import type { ChannelHubAgent, ChannelHubInboxHandle, ChannelHubSettingsTab, ChannelHubTenantSettings, Connection, Conversation, ContactInfoRow, Extension, ExtensionContact, ExtensionContext, Message, MessageAttachment, Page, Provider, WidgetProps } from './types.js';
|
|
7
8
|
|
|
8
9
|
type WidgetTranslations = { today: string; loadOlder: string; loading: string; noMessages: string; searchPlaceholder: string; unreadOnly: string; sendPlaceholder: string; send: string; all: string };
|
|
9
10
|
import { Avatar as UiAvatar, Button, Input, ScrollArea, Textarea } from './components/ui/index.js';
|
|
@@ -131,7 +132,7 @@ function shortAgentName(name: string): string {
|
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(function ChannelHubInbox(
|
|
134
|
-
{ apiUrl, token, theme, height, defaultConversationId, disableAttachments, disableNotificationSound, hideKeyboardHint, locale = 'vi', extensions, currentAgent, teamAgents, onNewMessage, onConversationSelect },
|
|
135
|
+
{ apiUrl, token, theme, height, defaultConversationId, disableAttachments, disableNotificationSound, hideKeyboardHint, hideSettingsButton, settingsConfig, locale = 'vi', extensions, currentAgent, teamAgents, onNewMessage, onConversationSelect },
|
|
135
136
|
ref
|
|
136
137
|
) {
|
|
137
138
|
const client = useRef(new ChannelHubClient(apiUrl, token));
|
|
@@ -140,6 +141,10 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
140
141
|
const [query, setQuery] = useState('');
|
|
141
142
|
const [assignmentScope, setAssignmentScope] = useState<AssignmentScope>('all');
|
|
142
143
|
const [sessionAgent, setSessionAgent] = useState<ChannelHubAgent | null>(null);
|
|
144
|
+
const [tenantSettings, setTenantSettings] = useState<ChannelHubTenantSettings>(DEFAULT_TENANT_SETTINGS);
|
|
145
|
+
const tenantSettingsRef = useRef<ChannelHubTenantSettings>(DEFAULT_TENANT_SETTINGS);
|
|
146
|
+
const [settingsModalTab, setSettingsModalTab] = useState<ChannelHubSettingsTab | null>(null);
|
|
147
|
+
const [templateRefreshKey, setTemplateRefreshKey] = useState(0);
|
|
143
148
|
const [activeFilters, setActiveFilters] = useState<ActiveFilters>({ provider: 'all', unreadOnly: false });
|
|
144
149
|
const [filterOpen, setFilterOpen] = useState(false);
|
|
145
150
|
const filterBtnRef = useRef<HTMLButtonElement>(null);
|
|
@@ -188,6 +193,10 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
188
193
|
|
|
189
194
|
useEffect(() => {
|
|
190
195
|
client.current = new ChannelHubClient(apiUrl, token);
|
|
196
|
+
void client.current.getSettings().then(s => {
|
|
197
|
+
setTenantSettings(s);
|
|
198
|
+
tenantSettingsRef.current = s;
|
|
199
|
+
}).catch(() => undefined);
|
|
191
200
|
if (!currentAgent) {
|
|
192
201
|
void client.current.getSessionMe().then(res => {
|
|
193
202
|
if (res?.agent) setSessionAgent(res.agent);
|
|
@@ -195,6 +204,10 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
195
204
|
}
|
|
196
205
|
}, [apiUrl, token, currentAgent]);
|
|
197
206
|
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
tenantSettingsRef.current = tenantSettings;
|
|
209
|
+
}, [tenantSettings]);
|
|
210
|
+
|
|
198
211
|
const mergedTeamAgents = useMemo(() => {
|
|
199
212
|
const map = new Map<string, ChannelHubAgent>();
|
|
200
213
|
if (effectiveCurrentAgent?.id) map.set(effectiveCurrentAgent.id, effectiveCurrentAgent);
|
|
@@ -268,7 +281,32 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
268
281
|
document.addEventListener('mouseup', onUp);
|
|
269
282
|
}
|
|
270
283
|
const load = useCallback(async (next?: string) => { try { const page: Page<Conversation> = await client.current.listConversations(next); setItems(old => next ? [...old, ...page.items] : page.items); setCursor(page.nextCursor); if (!next && page.items.length) setSelected(old => old ?? (defaultConversationId ? (page.items.find(c => c.id === defaultConversationId) ?? page.items[0]) : page.items[0])); setError(''); } catch (e) { setError(e instanceof Error ? e.message : 'Không tải được hội thoại'); } finally { setLoading(false); } }, [defaultConversationId]);
|
|
271
|
-
useEffect(() => {
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
void client.current.listConnections().then(setConnections).catch(() => undefined);
|
|
286
|
+
void load();
|
|
287
|
+
const stop = client.current.connectSSE((type, data) => {
|
|
288
|
+
if (type === 'message.new' || type === 'conversation.updated') {
|
|
289
|
+
void load();
|
|
290
|
+
if (type === 'message.new') {
|
|
291
|
+
const evtData = typeof data === 'object' && data ? data as Record<string, unknown> : {};
|
|
292
|
+
const evtConvId = evtData['conversationId'] ? String(evtData['conversationId']) : '';
|
|
293
|
+
const evtMsgId = evtData['messageId'] ? String(evtData['messageId']) : '';
|
|
294
|
+
const evtDirection = evtData['direction'] ? String(evtData['direction']) : '';
|
|
295
|
+
if (evtDirection === 'inbound' && !disableNotificationSound && tenantSettingsRef.current.inbox.soundNotification) {
|
|
296
|
+
playNotificationSound();
|
|
297
|
+
}
|
|
298
|
+
if (evtConvId && evtConvId === selectedId.current && evtMsgId && appendMessageRef.current) {
|
|
299
|
+
const appendFn = appendMessageRef.current;
|
|
300
|
+
void client.current.getMessage(evtMsgId).then(msg => { appendFn(msg); }).catch(() => undefined);
|
|
301
|
+
}
|
|
302
|
+
onNewMessage?.(evtConvId || selectedId.current || '');
|
|
303
|
+
}
|
|
304
|
+
} else if (type === 'message.status_updated') {
|
|
305
|
+
setMsgRefreshKey(k => k + 1);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return stop;
|
|
309
|
+
}, [load, onNewMessage, disableNotificationSound]);
|
|
272
310
|
useEffect(() => { selectedId.current = selected?.id; }, [selected]);
|
|
273
311
|
useEffect(() => { if (selected?.unreadCount) void client.current.markRead(selected.id).then(() => load()).catch(() => undefined); }, [selected?.id]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
274
312
|
|
|
@@ -361,7 +399,16 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
361
399
|
<strong>{theme?.branding?.name ?? 'Hộp thư'}</strong>
|
|
362
400
|
{!theme?.branding?.name && <span style={css.eyebrow}>CHANNELHUB</span>}
|
|
363
401
|
</div>
|
|
364
|
-
|
|
402
|
+
{!hideSettingsButton && (
|
|
403
|
+
<Button
|
|
404
|
+
aria-label="Cài đặt"
|
|
405
|
+
title="Cài đặt Hộp thư & Trợ lý AI"
|
|
406
|
+
style={css.iconButton}
|
|
407
|
+
onClick={() => setSettingsModalTab('ai')}
|
|
408
|
+
>
|
|
409
|
+
<Settings size={16} strokeWidth={2} />
|
|
410
|
+
</Button>
|
|
411
|
+
)}
|
|
365
412
|
</div>
|
|
366
413
|
<div style={css.search}><Search size={16} strokeWidth={2} /><Input aria-label={t.searchPlaceholder} value={query} onChange={e => setQuery(e.target.value)} placeholder={t.searchPlaceholder} style={{ fontSize: layoutMode === 'mobile' ? 16 : 12 }} />{query && <button style={css.clear} onClick={() => setQuery('')} aria-label="Xóa tìm kiếm">×</button>}</div>
|
|
367
414
|
|
|
@@ -511,6 +558,9 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
511
558
|
layoutMode={layoutMode}
|
|
512
559
|
onBackToList={() => setMobileView('list')}
|
|
513
560
|
totalUnreadCount={totalUnreadCount}
|
|
561
|
+
tenantSettings={tenantSettings}
|
|
562
|
+
templateRefreshKey={templateRefreshKey}
|
|
563
|
+
onOpenSettings={!hideSettingsButton ? (tab) => setSettingsModalTab(tab) : undefined}
|
|
514
564
|
/>
|
|
515
565
|
) : <EmptyConversation />}
|
|
516
566
|
</main>
|
|
@@ -570,6 +620,59 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
570
620
|
</div>
|
|
571
621
|
)
|
|
572
622
|
)}
|
|
623
|
+
|
|
624
|
+
{settingsModalTab && (
|
|
625
|
+
<div
|
|
626
|
+
onClick={() => {
|
|
627
|
+
setSettingsModalTab(null);
|
|
628
|
+
setTemplateRefreshKey(k => k + 1);
|
|
629
|
+
}}
|
|
630
|
+
style={{
|
|
631
|
+
position: 'absolute',
|
|
632
|
+
inset: 0,
|
|
633
|
+
zIndex: 80,
|
|
634
|
+
background: 'rgba(15, 23, 42, 0.45)',
|
|
635
|
+
display: 'flex',
|
|
636
|
+
alignItems: 'center',
|
|
637
|
+
justifyContent: 'center',
|
|
638
|
+
padding: layoutMode === 'mobile' ? 0 : 18,
|
|
639
|
+
}}
|
|
640
|
+
>
|
|
641
|
+
<div
|
|
642
|
+
onClick={e => e.stopPropagation()}
|
|
643
|
+
style={{
|
|
644
|
+
width: layoutMode === 'mobile' ? '100%' : 'min(840px, 100%)',
|
|
645
|
+
height: layoutMode === 'mobile' ? '100%' : 'min(620px, 100%)',
|
|
646
|
+
boxShadow: '0 24px 60px rgba(15, 23, 42, 0.25)',
|
|
647
|
+
borderRadius: layoutMode === 'mobile' ? 0 : (theme?.borderRadius ?? '16px'),
|
|
648
|
+
overflow: 'hidden',
|
|
649
|
+
display: 'flex',
|
|
650
|
+
}}
|
|
651
|
+
>
|
|
652
|
+
<ChannelHubSettings
|
|
653
|
+
apiUrl={apiUrl}
|
|
654
|
+
token={token}
|
|
655
|
+
theme={{
|
|
656
|
+
...theme,
|
|
657
|
+
borderRadius: layoutMode === 'mobile' ? '0px' : (theme?.borderRadius ?? '16px'),
|
|
658
|
+
}}
|
|
659
|
+
initialTab={settingsModalTab}
|
|
660
|
+
tabs={settingsConfig?.tabs}
|
|
661
|
+
hideTechnicalAiConfig={settingsConfig?.hideTechnicalAiConfig}
|
|
662
|
+
customParameters={settingsConfig?.customParameters}
|
|
663
|
+
starterTemplates={settingsConfig?.starterTemplates}
|
|
664
|
+
onSettingsChange={s => {
|
|
665
|
+
setTenantSettings(s);
|
|
666
|
+
tenantSettingsRef.current = s;
|
|
667
|
+
}}
|
|
668
|
+
onClose={() => {
|
|
669
|
+
setSettingsModalTab(null);
|
|
670
|
+
setTemplateRefreshKey(k => k + 1);
|
|
671
|
+
}}
|
|
672
|
+
/>
|
|
673
|
+
</div>
|
|
674
|
+
</div>
|
|
675
|
+
)}
|
|
573
676
|
</div>
|
|
574
677
|
</TokenCtx.Provider>
|
|
575
678
|
</ApiUrlCtx.Provider>
|
|
@@ -687,7 +790,7 @@ function ConversationRow({ conversation, provider, selected, primary, currentAge
|
|
|
687
790
|
|
|
688
791
|
type PendingAttachment = { file: File; uploading: boolean; url?: string; mimeType?: string; attachmentType?: string; objectUrl?: string };
|
|
689
792
|
|
|
690
|
-
function MessagePanel({ conversation, provider, connection, client, primary, error, onRegisterAppend, refreshKey, infoOpen, onToggleInfo, t, disableAttachments, hideKeyboardHint, extensions, currentAgent, teamAgents, onAssignAgent, onLinkContact, onRefreshContactInfo, layoutMode = 'desktop', onBackToList, totalUnreadCount = 0 }: { conversation: Conversation; provider?: Provider; connection?: Connection; client: ChannelHubClient; primary: string; error: string; onRegisterAppend?: (fn: ((msg: Message) => void) | null) => void; refreshKey?: number; infoOpen: boolean; onToggleInfo: () => void; t: WidgetTranslations; disableAttachments?: boolean; hideKeyboardHint?: boolean; extensions?: Extension[]; currentAgent?: ChannelHubAgent | null; teamAgents?: ChannelHubAgent[]; onAssignAgent: (agent: ChannelHubAgent | null) => Promise<void>; onLinkContact: (externalId: string | null) => Promise<void>; onRefreshContactInfo: () => void; layoutMode?: LayoutMode; onBackToList?: () => void; totalUnreadCount?: number }) {
|
|
793
|
+
function MessagePanel({ conversation, provider, connection, client, primary, error, onRegisterAppend, refreshKey, infoOpen, onToggleInfo, t, disableAttachments, hideKeyboardHint, extensions, currentAgent, teamAgents, onAssignAgent, onLinkContact, onRefreshContactInfo, layoutMode = 'desktop', onBackToList, totalUnreadCount = 0, tenantSettings = DEFAULT_TENANT_SETTINGS, templateRefreshKey = 0, onOpenSettings }: { conversation: Conversation; provider?: Provider; connection?: Connection; client: ChannelHubClient; primary: string; error: string; onRegisterAppend?: (fn: ((msg: Message) => void) | null) => void; refreshKey?: number; infoOpen: boolean; onToggleInfo: () => void; t: WidgetTranslations; disableAttachments?: boolean; hideKeyboardHint?: boolean; extensions?: Extension[]; currentAgent?: ChannelHubAgent | null; teamAgents?: ChannelHubAgent[]; onAssignAgent: (agent: ChannelHubAgent | null) => Promise<void>; onLinkContact: (externalId: string | null) => Promise<void>; onRefreshContactInfo: () => void; layoutMode?: LayoutMode; onBackToList?: () => void; totalUnreadCount?: number; tenantSettings?: ChannelHubTenantSettings; templateRefreshKey?: number; onOpenSettings?: (tab: ChannelHubSettingsTab) => void }) {
|
|
691
794
|
const [messages, setMessages] = useState<Message[]>([]); const [cursor, setCursor] = useState<string>(); const [text, setText] = useState(''); const [loading, setLoading] = useState(true); const [sending, setSending] = useState(false); const [sendError, setSendError] = useState(''); const messageAreaRef = useRef<HTMLDivElement>(null); const name = conversation.contactName ?? conversation.subject ?? conversation.providerConversationKey;
|
|
692
795
|
const fileImageRef = useRef<HTMLInputElement>(null);
|
|
693
796
|
const fileDocRef = useRef<HTMLInputElement>(null);
|
|
@@ -736,7 +839,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
736
839
|
|
|
737
840
|
useEffect(() => {
|
|
738
841
|
void client.listCannedResponses().then(setTemplates).catch(() => undefined);
|
|
739
|
-
}, [client]);
|
|
842
|
+
}, [client, templateRefreshKey]);
|
|
740
843
|
|
|
741
844
|
useEffect(() => {
|
|
742
845
|
if (!templateOpen) return;
|
|
@@ -806,7 +909,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
806
909
|
: [];
|
|
807
910
|
if (!value && !attachments.length || sending) return;
|
|
808
911
|
setSending(true); setSendError('');
|
|
809
|
-
if (!conversation.assignedAgent && currentAgent) {
|
|
912
|
+
if (!conversation.assignedAgent && currentAgent && tenantSettings.inbox.autoAssignOnFirstReply) {
|
|
810
913
|
void onAssignAgent(currentAgent);
|
|
811
914
|
}
|
|
812
915
|
const optimisticId = `optimistic-${Date.now()}`;
|
|
@@ -1230,9 +1333,37 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1230
1333
|
);
|
|
1231
1334
|
})}
|
|
1232
1335
|
</ScrollArea>
|
|
1233
|
-
{/* Quick reply chips */}
|
|
1234
|
-
<div style={{ display: 'flex', gap: 6, flexWrap: 'nowrap', overflowX: 'auto', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', padding: '6px 14px 2px', borderTop: `1px solid ${c.line}` }}>
|
|
1235
|
-
{
|
|
1336
|
+
{/* Quick reply chips & AI Mode Status Badge */}
|
|
1337
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'nowrap', overflowX: 'auto', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', padding: '6px 14px 2px', borderTop: `1px solid ${c.line}` }}>
|
|
1338
|
+
{tenantSettings.ai.mode !== 'off' && (
|
|
1339
|
+
<button
|
|
1340
|
+
type="button"
|
|
1341
|
+
onClick={() => onOpenSettings?.('ai')}
|
|
1342
|
+
title="Cấu hình Trợ lý AI"
|
|
1343
|
+
style={{
|
|
1344
|
+
display: 'inline-flex',
|
|
1345
|
+
alignItems: 'center',
|
|
1346
|
+
gap: 4,
|
|
1347
|
+
fontSize: 10.5,
|
|
1348
|
+
fontWeight: 700,
|
|
1349
|
+
padding: '3px 9px',
|
|
1350
|
+
borderRadius: 999,
|
|
1351
|
+
background: tenantSettings.ai.mode === 'autopilot' ? '#ecfdf5' : '#f5f3ff',
|
|
1352
|
+
color: tenantSettings.ai.mode === 'autopilot' ? '#059669' : '#7c3aed',
|
|
1353
|
+
border: tenantSettings.ai.mode === 'autopilot' ? '1px solid #a7f3d0' : '1px solid #ddd6fe',
|
|
1354
|
+
cursor: onOpenSettings ? 'pointer' : 'default',
|
|
1355
|
+
whiteSpace: 'nowrap' as const,
|
|
1356
|
+
flexShrink: 0,
|
|
1357
|
+
}}
|
|
1358
|
+
>
|
|
1359
|
+
{tenantSettings.ai.mode === 'autopilot' ? <Bot size={11} /> : <Sparkles size={11} />}
|
|
1360
|
+
<span>{tenantSettings.ai.mode === 'autopilot' ? 'AI Autopilot' : 'AI Copilot'}</span>
|
|
1361
|
+
</button>
|
|
1362
|
+
)}
|
|
1363
|
+
{(tenantSettings.inbox.quickReplies?.length
|
|
1364
|
+
? tenantSettings.inbox.quickReplies
|
|
1365
|
+
: ['Cảm ơn bạn đã liên hệ 🙏', 'Mình sẽ kiểm tra ngay', 'Vui lòng chờ 1-2 phút']
|
|
1366
|
+
).map(chip => (
|
|
1236
1367
|
<button
|
|
1237
1368
|
key={chip}
|
|
1238
1369
|
type="button"
|
|
@@ -1327,15 +1458,38 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1327
1458
|
fontFamily: 'inherit',
|
|
1328
1459
|
}}
|
|
1329
1460
|
>
|
|
1330
|
-
<div style={{ padding: '8px 10px', borderBottom: `1px solid ${c.line}
|
|
1461
|
+
<div style={{ padding: '8px 10px', borderBottom: `1px solid ${c.line}`, display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
1331
1462
|
<input
|
|
1332
1463
|
autoFocus
|
|
1333
1464
|
type="text"
|
|
1334
1465
|
placeholder="Tìm template…"
|
|
1335
1466
|
value={templateSearch}
|
|
1336
1467
|
onChange={e => setTemplateSearch(e.target.value)}
|
|
1337
|
-
style={{
|
|
1468
|
+
style={{ flex: 1, minWidth: 0, boxSizing: 'border-box' as const, border: `1px solid ${c.line}`, borderRadius: 7, padding: '5px 8px', fontSize: 12, outline: 'none', fontFamily: 'inherit', color: c.ink }}
|
|
1338
1469
|
/>
|
|
1470
|
+
{onOpenSettings && (
|
|
1471
|
+
<button
|
|
1472
|
+
type="button"
|
|
1473
|
+
onClick={() => {
|
|
1474
|
+
setTemplateOpen(false);
|
|
1475
|
+
onOpenSettings('templates');
|
|
1476
|
+
}}
|
|
1477
|
+
style={{
|
|
1478
|
+
border: `1px solid ${primary}33`,
|
|
1479
|
+
background: `${primary}0f`,
|
|
1480
|
+
color: primary,
|
|
1481
|
+
borderRadius: 7,
|
|
1482
|
+
padding: '5px 8px',
|
|
1483
|
+
fontSize: 11,
|
|
1484
|
+
fontWeight: 600,
|
|
1485
|
+
cursor: 'pointer',
|
|
1486
|
+
whiteSpace: 'nowrap' as const,
|
|
1487
|
+
flexShrink: 0,
|
|
1488
|
+
}}
|
|
1489
|
+
>
|
|
1490
|
+
+ Quản lý mẫu câu
|
|
1491
|
+
</button>
|
|
1492
|
+
)}
|
|
1339
1493
|
</div>
|
|
1340
1494
|
<div style={{ maxHeight: 220, overflowY: 'auto' }}>
|
|
1341
1495
|
{(() => {
|