@scalemule/chat 0.0.5 → 0.0.8
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/chat.embed.global.js +1 -1
- package/dist/chat.umd.global.js +288 -12
- package/dist/{chunk-ZLMMNFZL.js → chunk-5O5YLRJL.js} +386 -16
- package/dist/chunk-GTMAK3IA.js +285 -0
- package/dist/chunk-TRCELAZQ.cjs +287 -0
- package/dist/{chunk-YDLRISR7.cjs → chunk-W2PWFS3E.cjs} +386 -15
- package/dist/element.cjs +542 -51
- package/dist/element.js +541 -50
- package/dist/index.cjs +34 -5
- package/dist/index.js +29 -4
- package/dist/react.cjs +1260 -50
- package/dist/react.js +1212 -13
- package/dist/support-widget.global.js +485 -157
- package/package.json +5 -2
- package/dist/ChatClient-BoZaTtyM.d.cts +0 -88
- package/dist/ChatClient-COmdEJ11.d.ts +0 -88
- package/dist/element.d.cts +0 -2
- package/dist/element.d.ts +0 -2
- package/dist/iframe.d.cts +0 -17
- package/dist/iframe.d.ts +0 -17
- package/dist/index.d.cts +0 -77
- package/dist/index.d.ts +0 -77
- package/dist/react.d.cts +0 -49
- package/dist/react.d.ts +0 -49
- package/dist/types-BmD7f1gV.d.cts +0 -232
- package/dist/types-BmD7f1gV.d.ts +0 -232
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalemule/chat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "ScaleMule standalone chat SDK — real-time messaging, presence, typing indicators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"LICENSE"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "tsup",
|
|
37
|
+
"build": "tsup && npm run build:types && npm run check:budgets",
|
|
38
|
+
"build:types": "tsc --emitDeclarationOnly --project tsconfig.json",
|
|
39
|
+
"check:budgets": "node ./scripts/check-bundle-budgets.mjs",
|
|
38
40
|
"dev": "tsup --watch",
|
|
39
41
|
"typecheck": "tsc --noEmit",
|
|
40
42
|
"lint": "eslint src/",
|
|
@@ -52,6 +54,7 @@
|
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@types/react": "^18.0.0",
|
|
54
56
|
"@types/react-dom": "^18.0.0",
|
|
57
|
+
"jsdom": "^26.0.0",
|
|
55
58
|
"tsup": "^8.0.0",
|
|
56
59
|
"typescript": "^5.4.0",
|
|
57
60
|
"vitest": "^2.0.0"
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { h as ChatEventMap, C as ChatConfig, b as ConnectionStatus, j as CreateConversationOptions, A as ApiResponse, c as Conversation, L as ListConversationsOptions, S as SendMessageOptions, a as ChatMessage, G as GetMessagesOptions, M as MessagesResponse, U as UnreadTotalResponse, n as ReadStatus, f as ChannelSettings, g as ChannelWithSettings, k as CreateEphemeralChannelOptions, l as CreateLargeRoomOptions } from './types-BmD7f1gV.cjs';
|
|
2
|
-
|
|
3
|
-
type Listener<T> = (data: T) => void;
|
|
4
|
-
declare class EventEmitter<EventMap extends Record<string, any>> {
|
|
5
|
-
private listeners;
|
|
6
|
-
on<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): () => void;
|
|
7
|
-
off<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): void;
|
|
8
|
-
once<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): () => void;
|
|
9
|
-
emit<K extends keyof EventMap>(event: K, ...[data]: EventMap[K] extends void ? [] : [EventMap[K]]): void;
|
|
10
|
-
removeAllListeners(event?: keyof EventMap): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare class ChatClient extends EventEmitter<ChatEventMap> {
|
|
14
|
-
private http;
|
|
15
|
-
private ws;
|
|
16
|
-
private cache;
|
|
17
|
-
private offlineQueue;
|
|
18
|
-
private conversationSubs;
|
|
19
|
-
private conversationTypes;
|
|
20
|
-
constructor(config: ChatConfig);
|
|
21
|
-
get status(): ConnectionStatus;
|
|
22
|
-
connect(): void;
|
|
23
|
-
disconnect(): void;
|
|
24
|
-
createConversation(options: CreateConversationOptions): Promise<ApiResponse<Conversation>>;
|
|
25
|
-
listConversations(options?: ListConversationsOptions): Promise<ApiResponse<Conversation[]>>;
|
|
26
|
-
getConversation(id: string): Promise<ApiResponse<Conversation>>;
|
|
27
|
-
private trackConversationType;
|
|
28
|
-
sendMessage(conversationId: string, options: SendMessageOptions): Promise<ApiResponse<ChatMessage>>;
|
|
29
|
-
getMessages(conversationId: string, options?: GetMessagesOptions): Promise<ApiResponse<MessagesResponse>>;
|
|
30
|
-
editMessage(messageId: string, content: string): Promise<ApiResponse<void>>;
|
|
31
|
-
deleteMessage(messageId: string): Promise<ApiResponse<void>>;
|
|
32
|
-
getCachedMessages(conversationId: string): ChatMessage[];
|
|
33
|
-
addReaction(messageId: string, emoji: string): Promise<ApiResponse<void>>;
|
|
34
|
-
removeReaction(messageId: string, emoji: string): Promise<ApiResponse<void>>;
|
|
35
|
-
getUnreadTotal(): Promise<ApiResponse<UnreadTotalResponse>>;
|
|
36
|
-
sendTyping(conversationId: string, isTyping?: boolean): Promise<void>;
|
|
37
|
-
markRead(conversationId: string): Promise<void>;
|
|
38
|
-
getReadStatus(conversationId: string): Promise<ApiResponse<{
|
|
39
|
-
statuses: ReadStatus[];
|
|
40
|
-
}>>;
|
|
41
|
-
addParticipant(conversationId: string, userId: string): Promise<ApiResponse<void>>;
|
|
42
|
-
removeParticipant(conversationId: string, userId: string): Promise<ApiResponse<void>>;
|
|
43
|
-
joinPresence(conversationId: string, userData?: unknown): void;
|
|
44
|
-
leavePresence(conversationId: string): void;
|
|
45
|
-
/** Update presence status (online/away/dnd) without leaving the channel. */
|
|
46
|
-
updatePresence(conversationId: string, status: 'online' | 'away' | 'dnd', userData?: unknown): void;
|
|
47
|
-
getChannelSettings(channelId: string): Promise<ApiResponse<ChannelSettings>>;
|
|
48
|
-
/**
|
|
49
|
-
* Set the conversation type for channel name routing.
|
|
50
|
-
* Large rooms use `conversation:lr:` prefix to skip MySQL in the realtime service.
|
|
51
|
-
*/
|
|
52
|
-
setConversationType(conversationId: string, type: Conversation['conversation_type']): void;
|
|
53
|
-
/**
|
|
54
|
-
* Find an active ephemeral or large_room channel by linked session ID.
|
|
55
|
-
* Returns null (not an error) if no active channel exists.
|
|
56
|
-
*/
|
|
57
|
-
findChannelBySessionId(linkedSessionId: string): Promise<ChannelWithSettings | null>;
|
|
58
|
-
/**
|
|
59
|
-
* Self-join an ephemeral or large_room channel. Idempotent.
|
|
60
|
-
*/
|
|
61
|
-
joinChannel(channelId: string): Promise<ApiResponse<{
|
|
62
|
-
participant_id: string;
|
|
63
|
-
role: string;
|
|
64
|
-
joined_at: string;
|
|
65
|
-
}>>;
|
|
66
|
-
/**
|
|
67
|
-
* Create an ephemeral channel tied to a session (e.g., a video snap).
|
|
68
|
-
*/
|
|
69
|
-
createEphemeralChannel(options: CreateEphemeralChannelOptions): Promise<ApiResponse<ChannelWithSettings>>;
|
|
70
|
-
/**
|
|
71
|
-
* Create a large room channel (high-concurrency, skips MySQL tracking in realtime).
|
|
72
|
-
*/
|
|
73
|
-
createLargeRoom(options: CreateLargeRoomOptions): Promise<ApiResponse<ChannelWithSettings>>;
|
|
74
|
-
/**
|
|
75
|
-
* Get the global concurrent subscriber count for a conversation.
|
|
76
|
-
*/
|
|
77
|
-
getSubscriberCount(conversationId: string): Promise<number>;
|
|
78
|
-
subscribeToConversation(conversationId: string): () => void;
|
|
79
|
-
/** Build channel name with correct prefix based on conversation type. */
|
|
80
|
-
private channelName;
|
|
81
|
-
destroy(): void;
|
|
82
|
-
private handleRealtimeMessage;
|
|
83
|
-
private handlePrivateMessage;
|
|
84
|
-
private handleConversationMessage;
|
|
85
|
-
private flushOfflineQueue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { ChatClient as C };
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { h as ChatEventMap, C as ChatConfig, b as ConnectionStatus, j as CreateConversationOptions, A as ApiResponse, c as Conversation, L as ListConversationsOptions, S as SendMessageOptions, a as ChatMessage, G as GetMessagesOptions, M as MessagesResponse, U as UnreadTotalResponse, n as ReadStatus, f as ChannelSettings, g as ChannelWithSettings, k as CreateEphemeralChannelOptions, l as CreateLargeRoomOptions } from './types-BmD7f1gV.js';
|
|
2
|
-
|
|
3
|
-
type Listener<T> = (data: T) => void;
|
|
4
|
-
declare class EventEmitter<EventMap extends Record<string, any>> {
|
|
5
|
-
private listeners;
|
|
6
|
-
on<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): () => void;
|
|
7
|
-
off<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): void;
|
|
8
|
-
once<K extends keyof EventMap>(event: K, callback: Listener<EventMap[K]>): () => void;
|
|
9
|
-
emit<K extends keyof EventMap>(event: K, ...[data]: EventMap[K] extends void ? [] : [EventMap[K]]): void;
|
|
10
|
-
removeAllListeners(event?: keyof EventMap): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare class ChatClient extends EventEmitter<ChatEventMap> {
|
|
14
|
-
private http;
|
|
15
|
-
private ws;
|
|
16
|
-
private cache;
|
|
17
|
-
private offlineQueue;
|
|
18
|
-
private conversationSubs;
|
|
19
|
-
private conversationTypes;
|
|
20
|
-
constructor(config: ChatConfig);
|
|
21
|
-
get status(): ConnectionStatus;
|
|
22
|
-
connect(): void;
|
|
23
|
-
disconnect(): void;
|
|
24
|
-
createConversation(options: CreateConversationOptions): Promise<ApiResponse<Conversation>>;
|
|
25
|
-
listConversations(options?: ListConversationsOptions): Promise<ApiResponse<Conversation[]>>;
|
|
26
|
-
getConversation(id: string): Promise<ApiResponse<Conversation>>;
|
|
27
|
-
private trackConversationType;
|
|
28
|
-
sendMessage(conversationId: string, options: SendMessageOptions): Promise<ApiResponse<ChatMessage>>;
|
|
29
|
-
getMessages(conversationId: string, options?: GetMessagesOptions): Promise<ApiResponse<MessagesResponse>>;
|
|
30
|
-
editMessage(messageId: string, content: string): Promise<ApiResponse<void>>;
|
|
31
|
-
deleteMessage(messageId: string): Promise<ApiResponse<void>>;
|
|
32
|
-
getCachedMessages(conversationId: string): ChatMessage[];
|
|
33
|
-
addReaction(messageId: string, emoji: string): Promise<ApiResponse<void>>;
|
|
34
|
-
removeReaction(messageId: string, emoji: string): Promise<ApiResponse<void>>;
|
|
35
|
-
getUnreadTotal(): Promise<ApiResponse<UnreadTotalResponse>>;
|
|
36
|
-
sendTyping(conversationId: string, isTyping?: boolean): Promise<void>;
|
|
37
|
-
markRead(conversationId: string): Promise<void>;
|
|
38
|
-
getReadStatus(conversationId: string): Promise<ApiResponse<{
|
|
39
|
-
statuses: ReadStatus[];
|
|
40
|
-
}>>;
|
|
41
|
-
addParticipant(conversationId: string, userId: string): Promise<ApiResponse<void>>;
|
|
42
|
-
removeParticipant(conversationId: string, userId: string): Promise<ApiResponse<void>>;
|
|
43
|
-
joinPresence(conversationId: string, userData?: unknown): void;
|
|
44
|
-
leavePresence(conversationId: string): void;
|
|
45
|
-
/** Update presence status (online/away/dnd) without leaving the channel. */
|
|
46
|
-
updatePresence(conversationId: string, status: 'online' | 'away' | 'dnd', userData?: unknown): void;
|
|
47
|
-
getChannelSettings(channelId: string): Promise<ApiResponse<ChannelSettings>>;
|
|
48
|
-
/**
|
|
49
|
-
* Set the conversation type for channel name routing.
|
|
50
|
-
* Large rooms use `conversation:lr:` prefix to skip MySQL in the realtime service.
|
|
51
|
-
*/
|
|
52
|
-
setConversationType(conversationId: string, type: Conversation['conversation_type']): void;
|
|
53
|
-
/**
|
|
54
|
-
* Find an active ephemeral or large_room channel by linked session ID.
|
|
55
|
-
* Returns null (not an error) if no active channel exists.
|
|
56
|
-
*/
|
|
57
|
-
findChannelBySessionId(linkedSessionId: string): Promise<ChannelWithSettings | null>;
|
|
58
|
-
/**
|
|
59
|
-
* Self-join an ephemeral or large_room channel. Idempotent.
|
|
60
|
-
*/
|
|
61
|
-
joinChannel(channelId: string): Promise<ApiResponse<{
|
|
62
|
-
participant_id: string;
|
|
63
|
-
role: string;
|
|
64
|
-
joined_at: string;
|
|
65
|
-
}>>;
|
|
66
|
-
/**
|
|
67
|
-
* Create an ephemeral channel tied to a session (e.g., a video snap).
|
|
68
|
-
*/
|
|
69
|
-
createEphemeralChannel(options: CreateEphemeralChannelOptions): Promise<ApiResponse<ChannelWithSettings>>;
|
|
70
|
-
/**
|
|
71
|
-
* Create a large room channel (high-concurrency, skips MySQL tracking in realtime).
|
|
72
|
-
*/
|
|
73
|
-
createLargeRoom(options: CreateLargeRoomOptions): Promise<ApiResponse<ChannelWithSettings>>;
|
|
74
|
-
/**
|
|
75
|
-
* Get the global concurrent subscriber count for a conversation.
|
|
76
|
-
*/
|
|
77
|
-
getSubscriberCount(conversationId: string): Promise<number>;
|
|
78
|
-
subscribeToConversation(conversationId: string): () => void;
|
|
79
|
-
/** Build channel name with correct prefix based on conversation type. */
|
|
80
|
-
private channelName;
|
|
81
|
-
destroy(): void;
|
|
82
|
-
private handleRealtimeMessage;
|
|
83
|
-
private handlePrivateMessage;
|
|
84
|
-
private handleConversationMessage;
|
|
85
|
-
private flushOfflineQueue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { ChatClient as C };
|
package/dist/element.d.cts
DELETED
package/dist/element.d.ts
DELETED
package/dist/iframe.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { C as ChatConfig } from './types-BmD7f1gV.cjs';
|
|
2
|
-
|
|
3
|
-
declare class ChatIframeController {
|
|
4
|
-
private iframe;
|
|
5
|
-
private listeners;
|
|
6
|
-
constructor(container: HTMLElement, config: ChatConfig & {
|
|
7
|
-
conversationId?: string;
|
|
8
|
-
iframeSrc?: string;
|
|
9
|
-
});
|
|
10
|
-
on(event: string, callback: (data: unknown) => void): () => void;
|
|
11
|
-
sendMessage(content: string): void;
|
|
12
|
-
destroy(): void;
|
|
13
|
-
private handleMessage;
|
|
14
|
-
private postToIframe;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { ChatIframeController };
|
package/dist/iframe.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { C as ChatConfig } from './types-BmD7f1gV.js';
|
|
2
|
-
|
|
3
|
-
declare class ChatIframeController {
|
|
4
|
-
private iframe;
|
|
5
|
-
private listeners;
|
|
6
|
-
constructor(container: HTMLElement, config: ChatConfig & {
|
|
7
|
-
conversationId?: string;
|
|
8
|
-
iframeSrc?: string;
|
|
9
|
-
});
|
|
10
|
-
on(event: string, callback: (data: unknown) => void): () => void;
|
|
11
|
-
sendMessage(content: string): void;
|
|
12
|
-
destroy(): void;
|
|
13
|
-
private handleMessage;
|
|
14
|
-
private postToIframe;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { ChatIframeController };
|
package/dist/index.d.cts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { C as ChatClient } from './ChatClient-BoZaTtyM.cjs';
|
|
2
|
-
export { d as ApiError, A as ApiResponse, e as Attachment, f as ChannelSettings, g as ChannelWithSettings, C as ChatConfig, h as ChatEventMap, a as ChatMessage, i as ChatReaction, b as ConnectionStatus, c as Conversation, j as CreateConversationOptions, k as CreateEphemeralChannelOptions, l as CreateLargeRoomOptions, G as GetMessagesOptions, L as ListConversationsOptions, M as MessagesResponse, P as Participant, m as PresenceMember, R as ReactionSummary, n as ReadStatus, S as SendMessageOptions, U as UnreadTotalResponse } from './types-BmD7f1gV.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SupportClient — High-level client for the support chat widget.
|
|
6
|
-
*
|
|
7
|
-
* Handles visitor session lifecycle (create/restore/refresh) and exposes
|
|
8
|
-
* the underlying ChatClient for real-time messaging.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* ```ts
|
|
12
|
-
* const support = new SupportClient({ apiKey: 'pb_...', apiBaseUrl: 'https://api.scalemule.com' });
|
|
13
|
-
* await support.initVisitorSession({ name: 'Jane' });
|
|
14
|
-
* const conversation = await support.startConversation('Hi, I need help!', { page_url: location.href });
|
|
15
|
-
* support.chat.on('message', (msg) => console.log(msg));
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
interface SupportConversation {
|
|
20
|
-
id: string;
|
|
21
|
-
conversation_id: string;
|
|
22
|
-
status: string;
|
|
23
|
-
visitor_name?: string;
|
|
24
|
-
visitor_email?: string;
|
|
25
|
-
visitor_page_url?: string;
|
|
26
|
-
assigned_rep_id?: string;
|
|
27
|
-
assigned_rep_name?: string;
|
|
28
|
-
last_message_preview?: string;
|
|
29
|
-
last_message_at?: string;
|
|
30
|
-
created_at: string;
|
|
31
|
-
existing?: boolean;
|
|
32
|
-
}
|
|
33
|
-
interface SupportClientConfig {
|
|
34
|
-
apiKey: string;
|
|
35
|
-
apiBaseUrl?: string;
|
|
36
|
-
}
|
|
37
|
-
declare class SupportClient {
|
|
38
|
-
private chatClient;
|
|
39
|
-
private apiKey;
|
|
40
|
-
private apiBaseUrl;
|
|
41
|
-
private storageKey;
|
|
42
|
-
private anonymousId;
|
|
43
|
-
private refreshToken;
|
|
44
|
-
private accessToken;
|
|
45
|
-
private tokenExpiresAt;
|
|
46
|
-
private userId;
|
|
47
|
-
private visitorName;
|
|
48
|
-
private visitorEmail;
|
|
49
|
-
constructor(config: SupportClientConfig);
|
|
50
|
-
/** Create or restore a visitor session. Call before startConversation(). */
|
|
51
|
-
initVisitorSession(info?: {
|
|
52
|
-
name?: string;
|
|
53
|
-
email?: string;
|
|
54
|
-
}): Promise<void>;
|
|
55
|
-
/** Start a new support conversation with the first message. */
|
|
56
|
-
startConversation(message: string, meta?: {
|
|
57
|
-
page_url?: string;
|
|
58
|
-
}): Promise<SupportConversation>;
|
|
59
|
-
/** Get the visitor's active/waiting support conversation, if any. */
|
|
60
|
-
getActiveConversation(): Promise<SupportConversation | null>;
|
|
61
|
-
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
62
|
-
get chat(): ChatClient;
|
|
63
|
-
/** Whether a visitor session has been initialized. */
|
|
64
|
-
get isInitialized(): boolean;
|
|
65
|
-
/** The visitor's user ID (available after initVisitorSession). */
|
|
66
|
-
get visitorUserId(): string | null;
|
|
67
|
-
/** Clean up all resources. */
|
|
68
|
-
destroy(): void;
|
|
69
|
-
private initChatClient;
|
|
70
|
-
private refreshAccessToken;
|
|
71
|
-
private loadState;
|
|
72
|
-
private saveState;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare const CHAT_VERSION = "0.0.1";
|
|
76
|
-
|
|
77
|
-
export { CHAT_VERSION, ChatClient, SupportClient, type SupportClientConfig, type SupportConversation };
|
package/dist/index.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { C as ChatClient } from './ChatClient-COmdEJ11.js';
|
|
2
|
-
export { d as ApiError, A as ApiResponse, e as Attachment, f as ChannelSettings, g as ChannelWithSettings, C as ChatConfig, h as ChatEventMap, a as ChatMessage, i as ChatReaction, b as ConnectionStatus, c as Conversation, j as CreateConversationOptions, k as CreateEphemeralChannelOptions, l as CreateLargeRoomOptions, G as GetMessagesOptions, L as ListConversationsOptions, M as MessagesResponse, P as Participant, m as PresenceMember, R as ReactionSummary, n as ReadStatus, S as SendMessageOptions, U as UnreadTotalResponse } from './types-BmD7f1gV.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SupportClient — High-level client for the support chat widget.
|
|
6
|
-
*
|
|
7
|
-
* Handles visitor session lifecycle (create/restore/refresh) and exposes
|
|
8
|
-
* the underlying ChatClient for real-time messaging.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* ```ts
|
|
12
|
-
* const support = new SupportClient({ apiKey: 'pb_...', apiBaseUrl: 'https://api.scalemule.com' });
|
|
13
|
-
* await support.initVisitorSession({ name: 'Jane' });
|
|
14
|
-
* const conversation = await support.startConversation('Hi, I need help!', { page_url: location.href });
|
|
15
|
-
* support.chat.on('message', (msg) => console.log(msg));
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
interface SupportConversation {
|
|
20
|
-
id: string;
|
|
21
|
-
conversation_id: string;
|
|
22
|
-
status: string;
|
|
23
|
-
visitor_name?: string;
|
|
24
|
-
visitor_email?: string;
|
|
25
|
-
visitor_page_url?: string;
|
|
26
|
-
assigned_rep_id?: string;
|
|
27
|
-
assigned_rep_name?: string;
|
|
28
|
-
last_message_preview?: string;
|
|
29
|
-
last_message_at?: string;
|
|
30
|
-
created_at: string;
|
|
31
|
-
existing?: boolean;
|
|
32
|
-
}
|
|
33
|
-
interface SupportClientConfig {
|
|
34
|
-
apiKey: string;
|
|
35
|
-
apiBaseUrl?: string;
|
|
36
|
-
}
|
|
37
|
-
declare class SupportClient {
|
|
38
|
-
private chatClient;
|
|
39
|
-
private apiKey;
|
|
40
|
-
private apiBaseUrl;
|
|
41
|
-
private storageKey;
|
|
42
|
-
private anonymousId;
|
|
43
|
-
private refreshToken;
|
|
44
|
-
private accessToken;
|
|
45
|
-
private tokenExpiresAt;
|
|
46
|
-
private userId;
|
|
47
|
-
private visitorName;
|
|
48
|
-
private visitorEmail;
|
|
49
|
-
constructor(config: SupportClientConfig);
|
|
50
|
-
/** Create or restore a visitor session. Call before startConversation(). */
|
|
51
|
-
initVisitorSession(info?: {
|
|
52
|
-
name?: string;
|
|
53
|
-
email?: string;
|
|
54
|
-
}): Promise<void>;
|
|
55
|
-
/** Start a new support conversation with the first message. */
|
|
56
|
-
startConversation(message: string, meta?: {
|
|
57
|
-
page_url?: string;
|
|
58
|
-
}): Promise<SupportConversation>;
|
|
59
|
-
/** Get the visitor's active/waiting support conversation, if any. */
|
|
60
|
-
getActiveConversation(): Promise<SupportConversation | null>;
|
|
61
|
-
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
62
|
-
get chat(): ChatClient;
|
|
63
|
-
/** Whether a visitor session has been initialized. */
|
|
64
|
-
get isInitialized(): boolean;
|
|
65
|
-
/** The visitor's user ID (available after initVisitorSession). */
|
|
66
|
-
get visitorUserId(): string | null;
|
|
67
|
-
/** Clean up all resources. */
|
|
68
|
-
destroy(): void;
|
|
69
|
-
private initChatClient;
|
|
70
|
-
private refreshAccessToken;
|
|
71
|
-
private loadState;
|
|
72
|
-
private saveState;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare const CHAT_VERSION = "0.0.1";
|
|
76
|
-
|
|
77
|
-
export { CHAT_VERSION, ChatClient, SupportClient, type SupportClientConfig, type SupportConversation };
|
package/dist/react.d.cts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { C as ChatClient } from './ChatClient-BoZaTtyM.cjs';
|
|
3
|
-
import { C as ChatConfig, a as ChatMessage, S as SendMessageOptions, A as ApiResponse, b as ConnectionStatus, c as Conversation } from './types-BmD7f1gV.cjs';
|
|
4
|
-
export { G as GetMessagesOptions, L as ListConversationsOptions, M as MessagesResponse, R as ReactionSummary, U as UnreadTotalResponse } from './types-BmD7f1gV.cjs';
|
|
5
|
-
|
|
6
|
-
interface ChatProviderProps {
|
|
7
|
-
config: ChatConfig;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
declare function ChatProvider({ config, children }: ChatProviderProps): React.JSX.Element;
|
|
11
|
-
/** Direct access to the ChatClient instance for custom event subscriptions (e.g., support:new). */
|
|
12
|
-
declare function useChatClient(): ChatClient;
|
|
13
|
-
declare function useConnection(): {
|
|
14
|
-
status: ConnectionStatus;
|
|
15
|
-
connect: () => void;
|
|
16
|
-
disconnect: () => void;
|
|
17
|
-
};
|
|
18
|
-
declare function useChat(conversationId?: string): {
|
|
19
|
-
messages: ChatMessage[];
|
|
20
|
-
isLoading: boolean;
|
|
21
|
-
error: string | null;
|
|
22
|
-
hasMore: boolean;
|
|
23
|
-
sendMessage: (content: string, options?: Partial<SendMessageOptions>) => Promise<ApiResponse<ChatMessage> | undefined>;
|
|
24
|
-
loadMore: () => Promise<void>;
|
|
25
|
-
markRead: () => Promise<void>;
|
|
26
|
-
};
|
|
27
|
-
declare function usePresence(conversationId?: string): {
|
|
28
|
-
members: {
|
|
29
|
-
userId: string;
|
|
30
|
-
status: string;
|
|
31
|
-
userData?: unknown;
|
|
32
|
-
}[];
|
|
33
|
-
};
|
|
34
|
-
declare function useTyping(conversationId?: string): {
|
|
35
|
-
typingUsers: string[];
|
|
36
|
-
sendTyping: (isTyping?: boolean) => void;
|
|
37
|
-
};
|
|
38
|
-
declare function useConversations(options?: {
|
|
39
|
-
conversationType?: string;
|
|
40
|
-
}): {
|
|
41
|
-
conversations: Conversation[];
|
|
42
|
-
isLoading: boolean;
|
|
43
|
-
refresh: () => Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
declare function useUnreadCount(): {
|
|
46
|
-
totalUnread: number;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { ApiResponse, ChatClient, ChatConfig, ChatMessage, ChatProvider, ConnectionStatus, Conversation, SendMessageOptions, useChat, useChatClient, useConnection, useConversations, usePresence, useTyping, useUnreadCount };
|
package/dist/react.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { C as ChatClient } from './ChatClient-COmdEJ11.js';
|
|
3
|
-
import { C as ChatConfig, a as ChatMessage, S as SendMessageOptions, A as ApiResponse, b as ConnectionStatus, c as Conversation } from './types-BmD7f1gV.js';
|
|
4
|
-
export { G as GetMessagesOptions, L as ListConversationsOptions, M as MessagesResponse, R as ReactionSummary, U as UnreadTotalResponse } from './types-BmD7f1gV.js';
|
|
5
|
-
|
|
6
|
-
interface ChatProviderProps {
|
|
7
|
-
config: ChatConfig;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
declare function ChatProvider({ config, children }: ChatProviderProps): React.JSX.Element;
|
|
11
|
-
/** Direct access to the ChatClient instance for custom event subscriptions (e.g., support:new). */
|
|
12
|
-
declare function useChatClient(): ChatClient;
|
|
13
|
-
declare function useConnection(): {
|
|
14
|
-
status: ConnectionStatus;
|
|
15
|
-
connect: () => void;
|
|
16
|
-
disconnect: () => void;
|
|
17
|
-
};
|
|
18
|
-
declare function useChat(conversationId?: string): {
|
|
19
|
-
messages: ChatMessage[];
|
|
20
|
-
isLoading: boolean;
|
|
21
|
-
error: string | null;
|
|
22
|
-
hasMore: boolean;
|
|
23
|
-
sendMessage: (content: string, options?: Partial<SendMessageOptions>) => Promise<ApiResponse<ChatMessage> | undefined>;
|
|
24
|
-
loadMore: () => Promise<void>;
|
|
25
|
-
markRead: () => Promise<void>;
|
|
26
|
-
};
|
|
27
|
-
declare function usePresence(conversationId?: string): {
|
|
28
|
-
members: {
|
|
29
|
-
userId: string;
|
|
30
|
-
status: string;
|
|
31
|
-
userData?: unknown;
|
|
32
|
-
}[];
|
|
33
|
-
};
|
|
34
|
-
declare function useTyping(conversationId?: string): {
|
|
35
|
-
typingUsers: string[];
|
|
36
|
-
sendTyping: (isTyping?: boolean) => void;
|
|
37
|
-
};
|
|
38
|
-
declare function useConversations(options?: {
|
|
39
|
-
conversationType?: string;
|
|
40
|
-
}): {
|
|
41
|
-
conversations: Conversation[];
|
|
42
|
-
isLoading: boolean;
|
|
43
|
-
refresh: () => Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
declare function useUnreadCount(): {
|
|
46
|
-
totalUnread: number;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { ApiResponse, ChatClient, ChatConfig, ChatMessage, ChatProvider, ConnectionStatus, Conversation, SendMessageOptions, useChat, useChatClient, useConnection, useConversations, usePresence, useTyping, useUnreadCount };
|