@channlize/react 0.1.1 → 0.3.0
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/CHANGELOG.md +42 -0
- package/README.md +99 -25
- package/dist/index.d.mts +222 -38
- package/dist/index.d.ts +222 -38
- package/dist/index.js +2095 -593
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2117 -593
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
3
|
import { ChannlizeConfig, ChannlizeClient, CreateContactResponse, ChannlizeError, ContactFormData, ChatMessage, ChatSession, TrackEventOptions } from '@channlize/core';
|
|
4
4
|
export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, EventSeverity, FileAttachment, RateLimitError, SendMessageResponse, TrackEventOptions, ValidationError } from '@channlize/core';
|
|
5
5
|
|
|
@@ -54,6 +54,11 @@ interface UseChatSessionReturn {
|
|
|
54
54
|
sendMessage: (content: string, attachments?: File[]) => Promise<void>;
|
|
55
55
|
startSession: () => Promise<void>;
|
|
56
56
|
endSession: () => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Reopen the real-time stream for the current session after it failed
|
|
59
|
+
* (`error.code === 'SSE_ERROR'`). Routine reconnects are automatic.
|
|
60
|
+
*/
|
|
61
|
+
reconnect: () => void;
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
64
|
* Hook for managing chat sessions with real-time messaging
|
|
@@ -61,7 +66,10 @@ interface UseChatSessionReturn {
|
|
|
61
66
|
declare function useChatSession(options?: UseChatSessionOptions): UseChatSessionReturn;
|
|
62
67
|
|
|
63
68
|
/**
|
|
64
|
-
* Returns a stable `track` function bound to the provider client for
|
|
69
|
+
* Returns a stable `track` function bound to the provider client for log
|
|
70
|
+
* tracking (browser / widget key; shown under Log tracking in the
|
|
71
|
+
* dashboard). To post a Slack message when something happens, use Events
|
|
72
|
+
* (`notify` from `@channlize/core`) on your server instead.
|
|
65
73
|
*/
|
|
66
74
|
declare function useChannlizeAnalytics(): {
|
|
67
75
|
track: (name: string, options?: TrackEventOptions) => Promise<{
|
|
@@ -70,48 +78,186 @@ declare function useChannlizeAnalytics(): {
|
|
|
70
78
|
}>;
|
|
71
79
|
};
|
|
72
80
|
|
|
81
|
+
/** `auto` and `system` both follow `prefers-color-scheme`. */
|
|
82
|
+
type ContactFormTheme = 'auto' | 'system' | 'light' | 'dark';
|
|
83
|
+
/** Whether a built-in field is shown, and whether it must be filled in. */
|
|
84
|
+
type ContactFieldMode = 'required' | 'optional' | 'hidden';
|
|
85
|
+
interface ContactFormTopic {
|
|
86
|
+
/** Identifies the option, e.g. for `defaultValues.topic` from a URL */
|
|
87
|
+
value: string;
|
|
88
|
+
/**
|
|
89
|
+
* Shown in the select, sent as `customFields.topic`, and used as the
|
|
90
|
+
* subject when that is blank. Defaults to `value`.
|
|
91
|
+
*/
|
|
92
|
+
label?: string;
|
|
93
|
+
}
|
|
94
|
+
/** The built-in fields' values (also what `defaultValues` takes). */
|
|
95
|
+
interface ContactFormValues {
|
|
96
|
+
name: string;
|
|
97
|
+
email: string;
|
|
98
|
+
company: string;
|
|
99
|
+
subject: string;
|
|
100
|
+
topic: string;
|
|
101
|
+
message: string;
|
|
102
|
+
}
|
|
103
|
+
interface ContactFormCustomField {
|
|
104
|
+
name: string;
|
|
105
|
+
label: string;
|
|
106
|
+
type: 'text' | 'email' | 'textarea' | 'select';
|
|
107
|
+
required?: boolean;
|
|
108
|
+
options?: string[];
|
|
109
|
+
placeholder?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Every user-facing string in the form, for copy changes or translation. */
|
|
112
|
+
interface ContactFormLabels {
|
|
113
|
+
name: string;
|
|
114
|
+
email: string;
|
|
115
|
+
company: string;
|
|
116
|
+
subject: string;
|
|
117
|
+
topic: string;
|
|
118
|
+
message: string;
|
|
119
|
+
namePlaceholder: string;
|
|
120
|
+
emailPlaceholder: string;
|
|
121
|
+
companyPlaceholder: string;
|
|
122
|
+
subjectPlaceholder: string;
|
|
123
|
+
topicPlaceholder: string;
|
|
124
|
+
messagePlaceholder: string;
|
|
125
|
+
optional: string;
|
|
126
|
+
submit: string;
|
|
127
|
+
submitting: string;
|
|
128
|
+
successTitle: string;
|
|
129
|
+
successMessage: string;
|
|
130
|
+
sendAnother: string;
|
|
131
|
+
/** Shown under a required field left empty */
|
|
132
|
+
errorRequired: string;
|
|
133
|
+
/** Shown under a required select left on the placeholder */
|
|
134
|
+
errorSelect: string;
|
|
135
|
+
errorEmail: string;
|
|
136
|
+
/** `{min}` is replaced with the minimum length */
|
|
137
|
+
errorTooShort: string;
|
|
138
|
+
/** `{max}` is replaced with the maximum length */
|
|
139
|
+
errorTooLong: string;
|
|
140
|
+
/** Announced when a submit is blocked by invalid fields */
|
|
141
|
+
errorSummary: string;
|
|
142
|
+
/** Shown when sending fails */
|
|
143
|
+
errorGeneric: string;
|
|
144
|
+
/** Shown when the API rate limit is hit */
|
|
145
|
+
errorRateLimit: string;
|
|
146
|
+
/** Small print under the submit button; '' hides it */
|
|
147
|
+
footnote: string;
|
|
148
|
+
}
|
|
149
|
+
declare const defaultContactFormLabels: ContactFormLabels;
|
|
73
150
|
interface FormProps {
|
|
74
|
-
/** Custom fields to include in the form */
|
|
75
|
-
customFields?:
|
|
76
|
-
name: string;
|
|
77
|
-
label: string;
|
|
78
|
-
type: 'text' | 'email' | 'textarea' | 'select';
|
|
79
|
-
required?: boolean;
|
|
80
|
-
options?: string[];
|
|
81
|
-
}>;
|
|
151
|
+
/** Custom fields to include in the form (sent as `customFields`) */
|
|
152
|
+
customFields?: ContactFormCustomField[];
|
|
82
153
|
/** Callback when form is successfully submitted */
|
|
83
|
-
onSuccess?: () => void;
|
|
154
|
+
onSuccess?: (response: CreateContactResponse) => void;
|
|
84
155
|
/** Callback when form submission fails */
|
|
85
156
|
onError?: (error: Error) => void;
|
|
86
157
|
/** Custom CSS classes */
|
|
87
158
|
className?: string;
|
|
88
|
-
/** Custom styles for form elements */
|
|
159
|
+
/** Custom styles for form elements (applied inline, so they win over the theme) */
|
|
89
160
|
styles?: {
|
|
90
|
-
form?:
|
|
91
|
-
field?:
|
|
92
|
-
label?:
|
|
93
|
-
input?:
|
|
94
|
-
textarea?:
|
|
95
|
-
button?:
|
|
96
|
-
error?:
|
|
97
|
-
success?:
|
|
161
|
+
form?: CSSProperties;
|
|
162
|
+
field?: CSSProperties;
|
|
163
|
+
label?: CSSProperties;
|
|
164
|
+
input?: CSSProperties;
|
|
165
|
+
textarea?: CSSProperties;
|
|
166
|
+
button?: CSSProperties;
|
|
167
|
+
error?: CSSProperties;
|
|
168
|
+
success?: CSSProperties;
|
|
98
169
|
};
|
|
99
|
-
/** Button text */
|
|
170
|
+
/** Button text (same as `labels.submit`) */
|
|
100
171
|
submitText?: string;
|
|
101
|
-
/** Success message */
|
|
172
|
+
/** Success message (same as `labels.successMessage`) */
|
|
102
173
|
successMessage?: string;
|
|
174
|
+
/** Colour scheme (default `light`). `auto` / `system` follow `prefers-color-scheme`. */
|
|
175
|
+
theme?: ContactFormTheme;
|
|
176
|
+
/** Accent colour (button, focus ring). Hex recommended. */
|
|
177
|
+
primaryColor?: string;
|
|
178
|
+
/** Text colour on the accent colour. Defaults to white or near-black, whichever is readable. */
|
|
179
|
+
primaryTextColor?: string;
|
|
180
|
+
/** `card` (default) draws a themed surface with padding; `plain` inherits the host's. */
|
|
181
|
+
variant?: 'card' | 'plain';
|
|
182
|
+
/** Skip the built-in stylesheet entirely (class names stay for your own CSS) */
|
|
183
|
+
unstyled?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Built-in fields. Email and message are always required.
|
|
186
|
+
* Defaults: name `required`, subject `optional`, company `hidden`,
|
|
187
|
+
* topic `optional` when `topics` is set.
|
|
188
|
+
*/
|
|
189
|
+
fields?: {
|
|
190
|
+
name?: ContactFieldMode;
|
|
191
|
+
company?: ContactFieldMode;
|
|
192
|
+
subject?: ContactFieldMode;
|
|
193
|
+
topic?: ContactFieldMode;
|
|
194
|
+
};
|
|
195
|
+
/** Options of the topic select; it is shown only when this is set */
|
|
196
|
+
topics?: Array<string | ContactFormTopic>;
|
|
197
|
+
/**
|
|
198
|
+
* Initial values, e.g. a topic from the URL (`?topic=sales`). A topic
|
|
199
|
+
* matches an option's value or label, case-insensitively.
|
|
200
|
+
*/
|
|
201
|
+
defaultValues?: Partial<ContactFormValues>;
|
|
202
|
+
/** Override any user-facing string */
|
|
203
|
+
labels?: Partial<ContactFormLabels>;
|
|
204
|
+
/** Minimum message length (default `10`, what the Channlize API accepts) */
|
|
205
|
+
minMessageLength?: number;
|
|
206
|
+
/** Maximum message length (default `5000`) */
|
|
207
|
+
maxMessageLength?: number;
|
|
208
|
+
/** Add a hidden honeypot field; bots that fill it get a fake success (default `true`) */
|
|
209
|
+
honeypot?: boolean;
|
|
210
|
+
/** Show the built-in success state after sending (default `true`) */
|
|
211
|
+
showSuccessState?: boolean;
|
|
212
|
+
/** Prefix of the fields' ids (default `channlize`, e.g. `channlize-email`) */
|
|
213
|
+
idPrefix?: string;
|
|
103
214
|
}
|
|
104
215
|
|
|
105
216
|
/**
|
|
106
|
-
* ContactForm component
|
|
107
|
-
*
|
|
217
|
+
* ContactForm component
|
|
218
|
+
*
|
|
219
|
+
* A themed, accessible contact form that posts to Channlize (and from there
|
|
220
|
+
* to your Slack). Inline validation, loading / success / error states, an
|
|
221
|
+
* optional topic select and company field, and a honeypot spam guard.
|
|
222
|
+
* Must be rendered inside `<ChannlizeProvider>`.
|
|
108
223
|
*/
|
|
109
224
|
declare function ContactForm(props: FormProps): react.JSX.Element;
|
|
225
|
+
type ContactFormProps = FormProps;
|
|
110
226
|
|
|
227
|
+
type ChatTheme = 'auto' | 'light' | 'dark';
|
|
228
|
+
/** Every user-facing string in the chat, for copy changes or translation. */
|
|
229
|
+
interface SupportChatLabels {
|
|
230
|
+
online: string;
|
|
231
|
+
connecting: string;
|
|
232
|
+
reconnecting: string;
|
|
233
|
+
offline: string;
|
|
234
|
+
connectionLost: string;
|
|
235
|
+
startFailed: string;
|
|
236
|
+
retry: string;
|
|
237
|
+
today: string;
|
|
238
|
+
yesterday: string;
|
|
239
|
+
you: string;
|
|
240
|
+
sending: string;
|
|
241
|
+
failed: string;
|
|
242
|
+
remove: string;
|
|
243
|
+
moreOptions: string;
|
|
244
|
+
minimize: string;
|
|
245
|
+
endChat: string;
|
|
246
|
+
endChatTitle: string;
|
|
247
|
+
endChatDescription: string;
|
|
248
|
+
endChatConfirm: string;
|
|
249
|
+
cancel: string;
|
|
250
|
+
attach: string;
|
|
251
|
+
removeAttachment: string;
|
|
252
|
+
messages: string;
|
|
253
|
+
conversationEnded: string;
|
|
254
|
+
charactersLeft: string;
|
|
255
|
+
}
|
|
256
|
+
declare const defaultSupportChatLabels: SupportChatLabels;
|
|
111
257
|
interface SupportChatProps extends UseChatSessionOptions {
|
|
112
258
|
/** Custom CSS classes */
|
|
113
259
|
className?: string;
|
|
114
|
-
/** Custom styles for chat elements */
|
|
260
|
+
/** Custom styles for chat elements (applied inline, so they win over the theme) */
|
|
115
261
|
styles?: {
|
|
116
262
|
container?: React.CSSProperties;
|
|
117
263
|
header?: React.CSSProperties;
|
|
@@ -127,20 +273,48 @@ interface SupportChatProps extends UseChatSessionOptions {
|
|
|
127
273
|
};
|
|
128
274
|
/** Placeholder text for message input */
|
|
129
275
|
placeholder?: string;
|
|
130
|
-
/** Header title */
|
|
276
|
+
/** Header title: your team or brand name */
|
|
131
277
|
title?: string;
|
|
132
|
-
/**
|
|
278
|
+
/** Accessible label (and tooltip) of the send button */
|
|
133
279
|
sendButtonText?: string;
|
|
134
280
|
/** Show timestamps on messages */
|
|
135
281
|
showTimestamps?: boolean;
|
|
136
282
|
/** Allow file attachments */
|
|
137
283
|
allowAttachments?: boolean;
|
|
284
|
+
/** Logo or team avatar URL, shown in the header and on the welcome screen */
|
|
285
|
+
avatarUrl?: string;
|
|
286
|
+
/** Custom avatar element (overrides `avatarUrl`) */
|
|
287
|
+
avatar?: ReactNode;
|
|
288
|
+
/** Text after "Online" in the header, e.g. "Replies in a few minutes". Set to '' to hide. */
|
|
289
|
+
statusText?: string;
|
|
290
|
+
/** Welcome heading shown before the first message */
|
|
291
|
+
greeting?: string;
|
|
292
|
+
/** Welcome text shown under the greeting */
|
|
293
|
+
welcomeMessage?: string;
|
|
294
|
+
/** Quick replies shown on the welcome screen; clicking one sends it */
|
|
295
|
+
suggestions?: string[];
|
|
296
|
+
/** Colour scheme. `auto` follows `prefers-color-scheme`. */
|
|
297
|
+
theme?: ChatTheme;
|
|
298
|
+
/** Accent colour (header, customer bubbles, send button). Hex recommended. */
|
|
299
|
+
primaryColor?: string;
|
|
300
|
+
/** Text colour on the accent colour. Defaults to white or near-black, whichever is readable. */
|
|
301
|
+
primaryTextColor?: string;
|
|
302
|
+
/** Locale for dates and times (defaults to the browser locale) */
|
|
303
|
+
locale?: string;
|
|
304
|
+
/** Maximum message length */
|
|
305
|
+
maxLength?: number;
|
|
306
|
+
/** Show "End conversation" in the header menu */
|
|
307
|
+
allowEndChat?: boolean;
|
|
308
|
+
/** When set, a minimize button is shown in the header and Esc calls it */
|
|
309
|
+
onMinimize?: () => void;
|
|
310
|
+
/** Override any user-facing string */
|
|
311
|
+
labels?: Partial<SupportChatLabels>;
|
|
138
312
|
}
|
|
139
313
|
/**
|
|
140
314
|
* SupportChat component - Real-time chat interface
|
|
141
315
|
* Provides a complete chat UI with message history and real-time updates
|
|
142
316
|
*/
|
|
143
|
-
declare function SupportChat({ autoConnect, metadata, onMessage, onError, sessionId, persistSession, storageKey, className, styles, placeholder, title, sendButtonText, showTimestamps, allowAttachments, }: SupportChatProps): react.JSX.Element;
|
|
317
|
+
declare function SupportChat({ autoConnect, metadata, onMessage, onError, sessionId, persistSession, storageKey, className, styles, placeholder, title, sendButtonText, showTimestamps, allowAttachments, avatarUrl, avatar, statusText, greeting, welcomeMessage, suggestions, theme, primaryColor, primaryTextColor, locale, maxLength, allowEndChat, onMinimize, labels: labelOverrides, }: SupportChatProps): react.JSX.Element;
|
|
144
318
|
|
|
145
319
|
interface ChannlizeChatProps {
|
|
146
320
|
/** Channlize configuration */
|
|
@@ -158,29 +332,36 @@ interface ChannlizeChatProps {
|
|
|
158
332
|
buttonIcon?: ReactNode;
|
|
159
333
|
/** Button size in pixels */
|
|
160
334
|
buttonSize?: number;
|
|
161
|
-
/**
|
|
335
|
+
/** Launcher colours. Default to `primaryColor`. */
|
|
162
336
|
buttonColors?: {
|
|
163
337
|
background?: string;
|
|
164
338
|
hover?: string;
|
|
165
339
|
text?: string;
|
|
166
340
|
};
|
|
167
341
|
/** Chat window props (passed to SupportChat) */
|
|
168
|
-
chatProps?: Omit<SupportChatProps, 'autoConnect'>;
|
|
342
|
+
chatProps?: Omit<SupportChatProps, 'autoConnect' | 'onMinimize'>;
|
|
343
|
+
/** Accent colour for the launcher and chat window (hex recommended) */
|
|
344
|
+
primaryColor?: string;
|
|
345
|
+
/** Colour scheme. `auto` (default) follows `prefers-color-scheme`. */
|
|
346
|
+
theme?: ChatTheme;
|
|
169
347
|
/** Whether to start closed or open */
|
|
170
348
|
defaultOpen?: boolean;
|
|
171
|
-
/**
|
|
349
|
+
/**
|
|
350
|
+
* Show `unreadCount` on the launcher instead of the built-in count. Without
|
|
351
|
+
* it, the launcher counts agent replies received while the chat is closed.
|
|
352
|
+
*/
|
|
172
353
|
showBadge?: boolean;
|
|
173
|
-
/** Unread count (for badge) */
|
|
354
|
+
/** Unread count (for badge, used with `showBadge`) */
|
|
174
355
|
unreadCount?: number;
|
|
175
356
|
/** Custom z-index */
|
|
176
357
|
zIndex?: number;
|
|
177
|
-
/** Whether to show on
|
|
358
|
+
/** Whether to show the launcher on small screens (< 640px) */
|
|
178
359
|
showOnMobile?: boolean;
|
|
179
360
|
/** Callback when chat opens */
|
|
180
361
|
onOpen?: () => void;
|
|
181
362
|
/** Callback when chat closes */
|
|
182
363
|
onClose?: () => void;
|
|
183
|
-
/** Whether to enable animations */
|
|
364
|
+
/** Whether to enable animations (always reduced with `prefers-reduced-motion`) */
|
|
184
365
|
enableAnimations?: boolean;
|
|
185
366
|
/** Custom class for button container */
|
|
186
367
|
buttonClassName?: string;
|
|
@@ -201,13 +382,16 @@ interface ChannlizeChatProps {
|
|
|
201
382
|
* projectId: "your-project-id",
|
|
202
383
|
* }}
|
|
203
384
|
* position="bottom-right"
|
|
385
|
+
* primaryColor="#2563eb"
|
|
204
386
|
* chatProps={{
|
|
205
|
-
* title: "
|
|
206
|
-
*
|
|
387
|
+
* title: "Acme Support",
|
|
388
|
+
* greeting: "Hi there!",
|
|
389
|
+
* welcomeMessage: "Ask us anything.",
|
|
207
390
|
* }}
|
|
208
391
|
* />
|
|
209
392
|
* ```
|
|
210
393
|
*/
|
|
211
|
-
declare function ChannlizeChat({ config, position, offset, buttonElement, buttonIcon, buttonSize, buttonColors, chatProps, defaultOpen, showBadge, unreadCount, zIndex, showOnMobile, onOpen, onClose, enableAnimations, buttonClassName, chatClassName, }: ChannlizeChatProps): react.JSX.Element | null;
|
|
394
|
+
declare function ChannlizeChat({ config, position, offset, buttonElement, buttonIcon, buttonSize, buttonColors, chatProps, primaryColor, theme, defaultOpen, showBadge, unreadCount, zIndex, showOnMobile, onOpen, onClose, enableAnimations, buttonClassName, chatClassName, }: ChannlizeChatProps): react.JSX.Element | null;
|
|
212
395
|
|
|
213
|
-
export { ChannlizeChat, ChannlizeProvider, ContactForm, SupportChat, useChannlize, useChannlizeAnalytics, useChatSession, useContactForm };
|
|
396
|
+
export { ChannlizeChat, ChannlizeProvider, ContactForm, SupportChat, defaultContactFormLabels, defaultSupportChatLabels, useChannlize, useChannlizeAnalytics, useChatSession, useContactForm };
|
|
397
|
+
export type { ChannlizeChatProps, ChatTheme, ContactFieldMode, ContactFormCustomField, ContactFormLabels, ContactFormProps, ContactFormTheme, ContactFormTopic, ContactFormValues, SupportChatLabels, SupportChatProps, UseChatSessionOptions, UseChatSessionReturn };
|