@giovchat/react-native 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +333 -2
- package/dist/GiovChat.d.ts +100 -0
- package/dist/GiovChat.d.ts.map +1 -0
- package/dist/GiovChat.js +257 -0
- package/dist/GiovChat.js.map +1 -0
- package/dist/attachments.d.ts +121 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +185 -0
- package/dist/attachments.js.map +1 -0
- package/dist/brand-assets.d.ts +6 -0
- package/dist/brand-assets.d.ts.map +1 -0
- package/dist/brand-assets.js +9 -0
- package/dist/brand-assets.js.map +1 -0
- package/dist/client.d.ts +190 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +801 -0
- package/dist/client.js.map +1 -0
- package/dist/color.d.ts +25 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +78 -0
- package/dist/color.js.map +1 -0
- package/dist/components/Attachments.d.ts +13 -0
- package/dist/components/Attachments.d.ts.map +1 -0
- package/dist/components/Attachments.js +42 -0
- package/dist/components/Attachments.js.map +1 -0
- package/dist/components/Branding.d.ts +6 -0
- package/dist/components/Branding.d.ts.map +1 -0
- package/dist/components/Branding.js +28 -0
- package/dist/components/Branding.js.map +1 -0
- package/dist/components/ChatMarkdown.d.ts +15 -0
- package/dist/components/ChatMarkdown.d.ts.map +1 -0
- package/dist/components/ChatMarkdown.js +72 -0
- package/dist/components/ChatMarkdown.js.map +1 -0
- package/dist/components/GiovBotMark.d.ts +6 -0
- package/dist/components/GiovBotMark.d.ts.map +1 -0
- package/dist/components/GiovBotMark.js +11 -0
- package/dist/components/GiovBotMark.js.map +1 -0
- package/dist/components/GreetingBubble.d.ts +7 -0
- package/dist/components/GreetingBubble.d.ts.map +1 -0
- package/dist/components/GreetingBubble.js +12 -0
- package/dist/components/GreetingBubble.js.map +1 -0
- package/dist/components/Header.d.ts +18 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +67 -0
- package/dist/components/Header.js.map +1 -0
- package/dist/components/MessageBubble.d.ts +16 -0
- package/dist/components/MessageBubble.d.ts.map +1 -0
- package/dist/components/MessageBubble.js +49 -0
- package/dist/components/MessageBubble.js.map +1 -0
- package/dist/components/PreChatForm.d.ts +11 -0
- package/dist/components/PreChatForm.d.ts.map +1 -0
- package/dist/components/PreChatForm.js +72 -0
- package/dist/components/PreChatForm.js.map +1 -0
- package/dist/components/TypingIndicator.d.ts +9 -0
- package/dist/components/TypingIndicator.d.ts.map +1 -0
- package/dist/components/TypingIndicator.js +18 -0
- package/dist/components/TypingIndicator.js.map +1 -0
- package/dist/components/WidgetStyles.d.ts +3 -0
- package/dist/components/WidgetStyles.d.ts.map +1 -0
- package/dist/components/WidgetStyles.js +9 -0
- package/dist/components/WidgetStyles.js.map +1 -0
- package/dist/components/bubbleStyles.d.ts +47 -0
- package/dist/components/bubbleStyles.d.ts.map +1 -0
- package/dist/components/bubbleStyles.js +19 -0
- package/dist/components/bubbleStyles.js.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +14 -0
- package/dist/components/index.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/i18n.d.ts +73 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +292 -0
- package/dist/i18n.js.map +1 -0
- package/dist/identity.d.ts +41 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +41 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +56 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +219 -0
- package/dist/markdown.js.map +1 -0
- package/dist/outbox.d.ts +68 -0
- package/dist/outbox.d.ts.map +1 -0
- package/dist/outbox.js +168 -0
- package/dist/outbox.js.map +1 -0
- package/dist/protocol.d.ts +9 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +34 -0
- package/dist/protocol.js.map +1 -0
- package/dist/styleOverrides.d.ts +37 -0
- package/dist/styleOverrides.d.ts.map +1 -0
- package/dist/styleOverrides.js +54 -0
- package/dist/styleOverrides.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/unread.d.ts +9 -0
- package/dist/unread.d.ts.map +1 -0
- package/dist/unread.js +49 -0
- package/dist/unread.js.map +1 -0
- package/dist/useChatSession.d.ts +78 -0
- package/dist/useChatSession.d.ts.map +1 -0
- package/dist/useChatSession.js +796 -0
- package/dist/useChatSession.js.map +1 -0
- package/package.json +59 -4
- package/src/GiovChat.tsx +530 -0
- package/src/attachments.ts +218 -0
- package/src/brand-assets.ts +5 -0
- package/src/client.ts +758 -0
- package/src/color.ts +74 -0
- package/src/components/Attachments.tsx +75 -0
- package/src/components/Branding.tsx +35 -0
- package/src/components/ChatMarkdown.tsx +111 -0
- package/src/components/GiovBotMark.tsx +19 -0
- package/src/components/GreetingBubble.tsx +20 -0
- package/src/components/Header.tsx +131 -0
- package/src/components/MessageBubble.tsx +121 -0
- package/src/components/PreChatForm.tsx +183 -0
- package/src/components/TypingIndicator.tsx +34 -0
- package/src/components/WidgetStyles.tsx +5 -0
- package/src/components/bubbleStyles.ts +16 -0
- package/src/components/index.ts +14 -0
- package/src/errors.ts +30 -0
- package/src/i18n.ts +351 -0
- package/src/identity.ts +54 -0
- package/src/index.ts +68 -0
- package/src/markdown.ts +227 -0
- package/src/outbox.ts +175 -0
- package/src/protocol.ts +31 -0
- package/src/styleOverrides.ts +85 -0
- package/src/types.ts +119 -0
- package/src/unread.ts +39 -0
- package/src/useChatSession.ts +695 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { GiovAttachment, GiovAttachmentPolicy } from "./attachments";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fields the agent has configured as required in the pre-chat form.
|
|
5
|
+
* Mirrors the dashboard "Pre-chat form" settings.
|
|
6
|
+
*/
|
|
7
|
+
export interface RequestUserInfo {
|
|
8
|
+
email?: boolean;
|
|
9
|
+
phone?: boolean;
|
|
10
|
+
firstName?: boolean;
|
|
11
|
+
lastName?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Contact information for the current user.
|
|
16
|
+
*
|
|
17
|
+
* Pass this to `GiovChat` via the `contact` prop to automatically identify
|
|
18
|
+
* the visitor and skip (or pre-fill) any required pre-chat fields.
|
|
19
|
+
*/
|
|
20
|
+
export interface GiovChatContact {
|
|
21
|
+
/**
|
|
22
|
+
* Your stable user id. On its own it is only a claim: the API stores it for
|
|
23
|
+
* agents but does not link the chat to an existing contact. Pass `userHash`
|
|
24
|
+
* as well to have it verified.
|
|
25
|
+
*/
|
|
26
|
+
userId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* HMAC-SHA256 of `userId` (hex) using the workspace's visitor identity
|
|
29
|
+
* secret from Settings → Chat widget → Visitor details. Compute it on YOUR backend;
|
|
30
|
+
* never ship the secret in the app.
|
|
31
|
+
*/
|
|
32
|
+
userHash?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
phone?: string;
|
|
35
|
+
firstName?: string;
|
|
36
|
+
lastName?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Private visitor credential. Never log it or share it across users. */
|
|
40
|
+
export interface GiovChatSession {
|
|
41
|
+
conversationId: string;
|
|
42
|
+
sessionToken: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Optional host-owned secure persistence. The scope separates API, tenant, identity and reset key. */
|
|
46
|
+
export interface GiovChatSessionStorage {
|
|
47
|
+
load(scope: string): Promise<GiovChatSession | null>;
|
|
48
|
+
save(scope: string, session: GiovChatSession): Promise<void>;
|
|
49
|
+
remove(scope: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type GiovChatConnectionStatus = "connecting" | "connected" | "disconnected";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Widget configuration returned by `GET /widget/config`.
|
|
56
|
+
* All values are set by the agent in their dashboard.
|
|
57
|
+
*/
|
|
58
|
+
export interface GiovWidgetConfig {
|
|
59
|
+
/** Primary brand color (hex or CSS color). */
|
|
60
|
+
primaryColor: string;
|
|
61
|
+
/** Display name shown in the chat header. */
|
|
62
|
+
title: string;
|
|
63
|
+
/** Greeting message shown at the top of the conversation. */
|
|
64
|
+
greetingText: string;
|
|
65
|
+
/** Placeholder text for the message composer. */
|
|
66
|
+
textArea?: string;
|
|
67
|
+
/** Display name for the AI bot, when the GiovBot add-on is enabled. */
|
|
68
|
+
botName?: string;
|
|
69
|
+
/** True when GiovBot is turned on and included in the tenant's plan. */
|
|
70
|
+
botEnabled?: boolean;
|
|
71
|
+
/** The published GiovBot agent's avatar; the header shows the bot while it answers. */
|
|
72
|
+
botAvatarUrl?: string;
|
|
73
|
+
/** What visitors may attach, from the published agent's settings. Absent: images only. */
|
|
74
|
+
attachments?: GiovAttachmentPolicy;
|
|
75
|
+
/** URL of the agent/team avatar image. */
|
|
76
|
+
avatarUrl?: string;
|
|
77
|
+
/** Color theme. `"auto"` follows the device system setting. */
|
|
78
|
+
theme: "light" | "dark" | "auto";
|
|
79
|
+
/** Server-resolved plan policy. Only an explicit false removes GiovChat branding. */
|
|
80
|
+
showBranding?: boolean;
|
|
81
|
+
/** The workspace's privacy policy (https only); the header menu links to it, else to Giov's. */
|
|
82
|
+
privacyPolicyUrl?: string;
|
|
83
|
+
/** Which contact fields the agent requires before starting a chat. */
|
|
84
|
+
requestUserInfo?: RequestUserInfo;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A single message in a conversation. */
|
|
88
|
+
export interface GiovMessage {
|
|
89
|
+
/** Unique message identifier. */
|
|
90
|
+
id: string;
|
|
91
|
+
/** Who sent the message. */
|
|
92
|
+
role: "visitor" | "agent";
|
|
93
|
+
/** Message body: Chat Markdown, as the web widget renders it. */
|
|
94
|
+
content: string;
|
|
95
|
+
/** Unix timestamp in milliseconds. */
|
|
96
|
+
createdAt: number;
|
|
97
|
+
/** `true` when this message was sent by the AI bot. */
|
|
98
|
+
isBot?: boolean;
|
|
99
|
+
/** System-generated delivery. AI replies may set both this flag and `isBot`. */
|
|
100
|
+
isAutomated?: boolean;
|
|
101
|
+
/** Display name of the human agent, when available. */
|
|
102
|
+
senderName?: string | null;
|
|
103
|
+
/** Photo of the human agent (http(s) only), when available. */
|
|
104
|
+
senderAvatar?: string | null;
|
|
105
|
+
/** Files sent with the message. */
|
|
106
|
+
attachments?: GiovAttachment[];
|
|
107
|
+
/** Local only: "sending" until the server confirms it, "failed" when it could not be delivered. */
|
|
108
|
+
status?: "sending" | "failed";
|
|
109
|
+
/** Local only: the id it was shown under before the server confirmed it (keeps list keys stable). */
|
|
110
|
+
clientMessageId?: string;
|
|
111
|
+
/** Local only: a GiovBot reply still being written. */
|
|
112
|
+
isStreaming?: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Callback invoked for every incoming message. */
|
|
116
|
+
export type MessageHandler = (message: GiovMessage) => void;
|
|
117
|
+
|
|
118
|
+
/** Callback invoked when the WebSocket connection status changes. */
|
|
119
|
+
export type StatusHandler = (connected: boolean) => void;
|
package/src/unread.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unread agent replies per mounted chat, so any screen can show a badge without a provider. Each
|
|
5
|
+
* `GiovChat` publishes its own count under its tenant key; the hook sums them (normally one).
|
|
6
|
+
*/
|
|
7
|
+
const counts = new Map<symbol, { tenantKey: string; count: number }>();
|
|
8
|
+
const listeners = new Set<() => void>();
|
|
9
|
+
const notify = () => { for (const listener of listeners) { try { listener(); } catch { /* Isolated. */ } } };
|
|
10
|
+
|
|
11
|
+
export function publishUnreadCount(owner: symbol, tenantKey: string, count: number): void {
|
|
12
|
+
const current = counts.get(owner);
|
|
13
|
+
if (current && current.tenantKey === tenantKey && current.count === count) return;
|
|
14
|
+
counts.set(owner, { tenantKey, count });
|
|
15
|
+
notify();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function forgetUnreadCount(owner: symbol): void {
|
|
19
|
+
if (counts.delete(owner)) notify();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function readUnreadCount(tenantKey?: string): number {
|
|
23
|
+
let total = 0;
|
|
24
|
+
for (const entry of counts.values()) if (!tenantKey || entry.tenantKey === tenantKey) total += entry.count;
|
|
25
|
+
return total;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function subscribe(listener: () => void): () => void {
|
|
29
|
+
listeners.add(listener);
|
|
30
|
+
return () => { listeners.delete(listener); };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Agent replies the visitor has not seen because the chat was closed. Counts only while a mounted
|
|
35
|
+
* `GiovChat` stays connected when hidden (`keepConnected`); opening the chat clears it.
|
|
36
|
+
*/
|
|
37
|
+
export function useGiovChatUnreadCount(tenantKey?: string): number {
|
|
38
|
+
return useSyncExternalStore(subscribe, () => readUnreadCount(tenantKey), () => 0);
|
|
39
|
+
}
|