@talqui-oss/talqui-sdk-reactnative 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,150 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { StyleProp, ViewStyle } from 'react-native';
4
+
5
+ /** Who the visitor is, as far as your app knows. Every field is optional. */
6
+ interface TalquiUser {
7
+ /** Your own id for the user. Only used for your bookkeeping; never sent as the identity. */
8
+ userId?: string;
9
+ /**
10
+ * Identifies the user across devices and keeps their history after they
11
+ * log in again. Computed on YOUR backend, never in the app:
12
+ * `HMAC_SHA256(secret, "<tenantId>:<userId>")` as lowercase hex.
13
+ * Anyone holding it can read that user's conversation, so treat it like a
14
+ * session token. 32 to 128 chars of `A-Z a-z 0-9 _ -`.
15
+ */
16
+ userHash?: string;
17
+ name?: string;
18
+ email?: string;
19
+ phone?: string;
20
+ }
21
+ interface TalquiContact {
22
+ name?: string;
23
+ email?: string;
24
+ phone?: string;
25
+ }
26
+ /** Custom data: strings, numbers or booleans (stored as text). `null` removes a key. */
27
+ type TalquiMeta = Record<string, string | number | boolean | null>;
28
+ interface TalquiEventMap {
29
+ ready: {
30
+ protocol: number;
31
+ webchatVersion: string;
32
+ identity: {
33
+ kind: 'anonymous' | 'identified';
34
+ anonymousId?: string;
35
+ };
36
+ };
37
+ sessionStarted: {
38
+ sessionId: string | null;
39
+ };
40
+ messageSent: {
41
+ messageId: string;
42
+ type: string;
43
+ };
44
+ messageReceived: {
45
+ messageId: string;
46
+ type: string;
47
+ preview: string;
48
+ operatorName: string | null;
49
+ };
50
+ unreadChanged: {
51
+ count: number;
52
+ };
53
+ closeRequested: Record<string, never>;
54
+ openUrl: {
55
+ url: string;
56
+ };
57
+ resetDone: Record<string, never>;
58
+ error: {
59
+ code: string;
60
+ message: string;
61
+ commandId?: string;
62
+ };
63
+ }
64
+ type TalquiEventName = keyof TalquiEventMap;
65
+ type TalquiEventListener<E extends TalquiEventName> = (payload: TalquiEventMap[E]) => void;
66
+ interface TalquiApi {
67
+ /** Shows the chat full screen. */
68
+ open(): void;
69
+ /** Hides the full-screen chat. The conversation keeps running in the background. */
70
+ close(): void;
71
+ /** Mounts the chat ahead of time (hidden), so `open()` is instant and unread messages are counted. */
72
+ preload(): void;
73
+ /**
74
+ * Sets who the user is. With a `userHash` the chat reloads as that user
75
+ * (their history follows them across devices); without one, the details
76
+ * are attached to this device's anonymous visitor.
77
+ */
78
+ identify(user: TalquiUser): Promise<void>;
79
+ setContact(contact: TalquiContact): void;
80
+ /** Data about the person, kept on their contact. */
81
+ setContactMeta(meta: TalquiMeta): void;
82
+ /** Data about this conversation (an order, the screen they are on). Can change at any moment. */
83
+ setSessionMeta(meta: TalquiMeta): void;
84
+ /** Puts text in the message box. The user still decides to send it. */
85
+ prefill(text: string): void;
86
+ /** Call it when your user logs out: forgets this user and starts a fresh anonymous visitor. */
87
+ logout(): Promise<void>;
88
+ /** Messages received while the chat was not on screen. */
89
+ unreadCount: number;
90
+ /** Whether the chat is loaded and accepting commands. */
91
+ isReady: boolean;
92
+ isOpen: boolean;
93
+ }
94
+
95
+ interface TalquiProviderProps {
96
+ /** Your workspace id (app.talqui.chat → Plugins → WebChat → Installation). */
97
+ tenantId: string;
98
+ /** The WebChat connection id, on the same screen. */
99
+ connectionId: string;
100
+ /** Called for every link the user taps in the chat. Default: open it with `Linking`. */
101
+ onOpenUrl?: (url: string) => void;
102
+ /** Replaces the spinner shown while the chat loads. */
103
+ renderLoading?: () => ReactNode;
104
+ /** Replaces the screen shown when the chat cannot load. Call `retry` to try again. */
105
+ renderError?: (retry: () => void) => ReactNode;
106
+ /** Logs every message exchanged with the chat page. */
107
+ debug?: boolean;
108
+ /** @internal Points the SDK at another WebChat deployment (development only). */
109
+ __unstableBaseUrl?: string;
110
+ children: ReactNode;
111
+ }
112
+ /**
113
+ * Puts the Talqui chat in your app. Wrap your app once, near the root:
114
+ *
115
+ * <TalquiProvider tenantId="…" connectionId="…">
116
+ * <App />
117
+ * </TalquiProvider>
118
+ *
119
+ * then call `useTalqui().open()` anywhere, or render `<TalquiChat />` in a screen.
120
+ */
121
+ declare function TalquiProvider(props: TalquiProviderProps): react_jsx_runtime.JSX.Element;
122
+ /** The Talqui chat API. Must be used under `<TalquiProvider>`. */
123
+ declare function useTalqui(): TalquiApi;
124
+ /** Runs `listener` for every `name` event from the chat while the component is mounted. */
125
+ declare function useTalquiEvent<E extends TalquiEventName>(name: E, listener: TalquiEventListener<E>): void;
126
+
127
+ interface TalquiChatProps {
128
+ style?: StyleProp<ViewStyle>;
129
+ /**
130
+ * Whether this screen is the one on screen (unread messages are counted
131
+ * while it is not). With React Navigation pass `useIsFocused()`.
132
+ */
133
+ visible?: boolean;
134
+ /** The user tapped close in the chat header. */
135
+ onCloseRequested?: () => void;
136
+ /**
137
+ * Hides the close control in the chat header, which has nothing to close in
138
+ * a tab. Default `false`. Only affects the chat shown here: `open()` full
139
+ * screen always keeps it.
140
+ */
141
+ hideCloseButton?: boolean;
142
+ }
143
+ /**
144
+ * The chat inline, filling its container — for a "Chat" tab or a screen of
145
+ * your own. While it is on screen `open()` does nothing; once the screen is
146
+ * left (a tab navigator keeps it mounted), `open()` shows the chat full screen.
147
+ */
148
+ declare function TalquiChat({ style, visible, onCloseRequested, hideCloseButton }: TalquiChatProps): react_jsx_runtime.JSX.Element;
149
+
150
+ export { type TalquiApi, TalquiChat, type TalquiChatProps, type TalquiContact, type TalquiEventListener, type TalquiEventMap, type TalquiEventName, type TalquiMeta, TalquiProvider, type TalquiProviderProps, type TalquiUser, useTalqui, useTalquiEvent };