@talqui-oss/talqui-sdk-reactnative 0.0.0-stage → 0.1.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.md +21 -0
- package/README.md +274 -2
- package/dist/index.d.mts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +613 -0
- package/dist/index.mjs +581 -0
- package/package.json +82 -4
- package/src/TalquiChat.tsx +40 -0
- package/src/TalquiProvider.tsx +509 -0
- package/src/TalquiWebView.tsx +153 -0
- package/src/identity.ts +40 -0
- package/src/index.ts +13 -0
- package/src/protocol.ts +101 -0
- package/src/types.ts +70 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Talqui
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,275 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center"><strong>Talqui for React Native</strong></div>
|
|
4
|
+
<div align="center">Live chat for your React Native and Expo apps.<br />Your users talk to your team, bots and AI agents without leaving the app.</div>
|
|
5
|
+
<br />
|
|
6
|
+
<div align="center">
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@talqui-oss/talqui-sdk-reactnative)
|
|
9
|
+
[](https://expo.dev/go)
|
|
10
|
+
[](https://reactnative.dev)
|
|
11
|
+
[](https://github.com/talqui-oss/talqui-sdk-reactnative/blob/main/LICENSE.md)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
<div align="center">
|
|
15
|
+
<a href="https://docs.talqui.chat/guides/chat-sdks/react-native">Documentation</a>
|
|
16
|
+
<span> · </span>
|
|
17
|
+
<a href="https://www.npmjs.com/package/@talqui-oss/talqui-sdk-reactnative">npm</a>
|
|
18
|
+
<span> · </span>
|
|
19
|
+
<a href="./example">Example app</a>
|
|
20
|
+
<span> · </span>
|
|
21
|
+
<a href="https://talqui.chat">Talqui</a>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
## Introduction
|
|
25
|
+
|
|
26
|
+
[Talqui](https://talqui.chat) brings WhatsApp, Instagram, Mercado Livre, your website and your app into one inbox. This package adds the Talqui chat to a React Native app: drop in a provider, call `open()` from any button, and the conversation lands in the same inbox your team already uses, with history, attachments, voice messages, bots and AI agents.
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **Works in Expo Go.** No native code of its own, no config plugin, no dev build.
|
|
31
|
+
- **Full screen or inline.** `open()` from any button, or `<TalquiChat />` inside a tab.
|
|
32
|
+
- **Knows who is talking.** Pass the logged-in user and data about the conversation (an order, a plan, the screen they are on), at any moment.
|
|
33
|
+
- **Events and unread badge.** React to new messages, sent messages and the chat being closed.
|
|
34
|
+
- **Safe logout.** One call and the next person on the phone starts from nothing.
|
|
35
|
+
- **Small surface.** One provider, two hooks, one component. Fully typed.
|
|
36
|
+
|
|
37
|
+
## Screenshots
|
|
38
|
+
|
|
39
|
+
What your users see, from the [example app](https://github.com/talqui-oss/talqui-sdk-reactnative/tree/main/example) on iOS.
|
|
40
|
+
|
|
41
|
+
<table align="center">
|
|
42
|
+
<tr>
|
|
43
|
+
<td width="33%">
|
|
44
|
+
<img src="https://raw.githubusercontent.com/talqui-oss/talqui-sdk-reactnative/main/.github/assets/screenshot-1-unread.png" alt="Unread count in the host app" />
|
|
45
|
+
<p align="center"><strong>Unread count</strong><br />Replies that arrive while the chat is closed</p>
|
|
46
|
+
</td>
|
|
47
|
+
<td width="33%">
|
|
48
|
+
<img src="https://raw.githubusercontent.com/talqui-oss/talqui-sdk-reactnative/main/.github/assets/screenshot-2-fullscreen.png" alt="Full screen chat with text, an image and a voice message" />
|
|
49
|
+
<p align="center"><strong>Full screen chat</strong><br />Text, images and voice messages</p>
|
|
50
|
+
</td>
|
|
51
|
+
<td width="33%">
|
|
52
|
+
<img src="https://raw.githubusercontent.com/talqui-oss/talqui-sdk-reactnative/main/.github/assets/screenshot-3-inline-tab.png" alt="The chat inline in a tab" />
|
|
53
|
+
<p align="center"><strong>Inline in a tab</strong><br /><code><TalquiChat hideCloseButton /></code></p>
|
|
54
|
+
</td>
|
|
55
|
+
</tr>
|
|
56
|
+
</table>
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
| | Minimum |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| React Native | 0.73 (Expo SDK 50) |
|
|
63
|
+
| iOS | 15 |
|
|
64
|
+
| Android | 7.0 (API 24) |
|
|
65
|
+
|
|
66
|
+
## Install
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx expo install @talqui-oss/talqui-sdk-reactnative react-native-webview @react-native-async-storage/async-storage
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Bare React Native: install the same three packages with your package manager, then run `cd ios && pod install`.
|
|
73
|
+
|
|
74
|
+
## Get your IDs
|
|
75
|
+
|
|
76
|
+
You need two values from your Talqui workspace, both on **app.talqui.chat → Plugins → WebChat → Installation**:
|
|
77
|
+
|
|
78
|
+
- **Tenant ID**: your workspace.
|
|
79
|
+
- **Connection ID**: the WebChat connection the app's conversations arrive through.
|
|
80
|
+
|
|
81
|
+
[Step by step with screenshots →](https://docs.talqui.chat/guides/chat-sdks/get-your-ids)
|
|
82
|
+
|
|
83
|
+
## Quick start
|
|
84
|
+
|
|
85
|
+
Wrap your app once:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { TalquiProvider } from '@talqui-oss/talqui-sdk-reactnative';
|
|
89
|
+
|
|
90
|
+
export default function App() {
|
|
91
|
+
return (
|
|
92
|
+
<TalquiProvider tenantId="YOUR_TENANT_ID" connectionId="YOUR_CONNECTION_ID">
|
|
93
|
+
<Home />
|
|
94
|
+
</TalquiProvider>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Open the chat from anywhere below it:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { useTalqui } from '@talqui-oss/talqui-sdk-reactnative';
|
|
103
|
+
import { Button } from 'react-native';
|
|
104
|
+
|
|
105
|
+
function Home() {
|
|
106
|
+
const talqui = useTalqui();
|
|
107
|
+
return <Button title="Talk to us" onPress={talqui.open} />;
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
That's it. The chat opens full screen and closes with the header button or the Android back button.
|
|
112
|
+
|
|
113
|
+
### Inline, in a tab
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { TalquiChat } from '@talqui-oss/talqui-sdk-reactnative';
|
|
117
|
+
import { useIsFocused } from '@react-navigation/native';
|
|
118
|
+
|
|
119
|
+
function ChatScreen() {
|
|
120
|
+
return <TalquiChat style={{ flex: 1 }} visible={useIsFocused()} hideCloseButton />;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`visible` tells the SDK whether the tab is on screen, so unread messages are counted while it is not. `hideCloseButton` removes the close button from the chat header, which has nothing to close in a tab. Full screen always keeps it.
|
|
125
|
+
|
|
126
|
+
## Identify users
|
|
127
|
+
|
|
128
|
+
Once your user logs in, tell the chat who they are. The pre-chat form is skipped and your team sees the name, email and phone:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
await talqui.identify({ name: 'Ana Souza', email: 'ana@example.com', phone: '+5511999990000' });
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
To keep a user's history across devices and reinstalls, also pass a `userHash`. Compute it **on your backend**, never in the app:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
userHash = HMAC_SHA256(secret, "<tenantId>:<userId>") // lowercase hex
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Anyone holding a `userHash` can read that user's conversation, so treat it like a session token. [Read more →](https://docs.talqui.chat/guides/chat-sdks/identify-users)
|
|
141
|
+
|
|
142
|
+
## Metadata
|
|
143
|
+
|
|
144
|
+
Send context your team will see next to the conversation:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
talqui.setContactMeta({ plan: 'pro', seats: 12 }); // about the person, kept on their contact
|
|
148
|
+
talqui.setSessionMeta({ order_id: '4821', step: 'checkout' }); // about this conversation, change it any time
|
|
149
|
+
talqui.setSessionMeta({ step: null }); // null removes a key
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Keys use lowercase letters, digits, `_` and `-` (up to 60 chars). Values are strings, numbers or booleans, stored as text up to 255 chars. Calls made before the chat loads are queued and sent once it is ready. [Read more →](https://docs.talqui.chat/guides/chat-sdks/metadata)
|
|
153
|
+
|
|
154
|
+
## Events
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { useTalqui, useTalquiEvent } from '@talqui-oss/talqui-sdk-reactnative';
|
|
158
|
+
|
|
159
|
+
useTalquiEvent('messageReceived', (event) => {
|
|
160
|
+
console.log(`${event.operatorName ?? 'Support'}: ${event.preview}`);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const { unreadCount } = useTalqui(); // for a badge
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Event | When | Payload |
|
|
167
|
+
| --- | --- | --- |
|
|
168
|
+
| `ready` | The chat finished loading | `{ protocol, webchatVersion, identity }` |
|
|
169
|
+
| `sessionStarted` | The user started a conversation | `{ sessionId }` |
|
|
170
|
+
| `messageSent` | The user sent a message | `{ messageId, type }` |
|
|
171
|
+
| `messageReceived` | Your team, a bot or an agent replied | `{ messageId, type, preview, operatorName }` |
|
|
172
|
+
| `unreadChanged` | The unread count changed | `{ count }` |
|
|
173
|
+
| `closeRequested` | The user tapped close in the header | `{}` |
|
|
174
|
+
| `openUrl` | The user tapped a link | `{ url }` |
|
|
175
|
+
| `error` | A command was rejected | `{ code, message }` |
|
|
176
|
+
|
|
177
|
+
[All events →](https://docs.talqui.chat/guides/chat-sdks/events)
|
|
178
|
+
|
|
179
|
+
## Logout
|
|
180
|
+
|
|
181
|
+
Call it when your user logs out. It forgets the user on this device, clears everything you set and starts a fresh anonymous visitor:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
await talqui.logout();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## API
|
|
188
|
+
|
|
189
|
+
### `<TalquiProvider>`
|
|
190
|
+
|
|
191
|
+
| Prop | Type | |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
| `tenantId` | `string` | Required. Your workspace id. |
|
|
194
|
+
| `connectionId` | `string` | Required. The WebChat connection id. |
|
|
195
|
+
| `onOpenUrl` | `(url: string) => void` | Handles links tapped in the chat. Default: `Linking.openURL`. |
|
|
196
|
+
| `renderLoading` | `() => ReactNode` | Replaces the loading spinner. |
|
|
197
|
+
| `renderError` | `(retry: () => void) => ReactNode` | Replaces the screen shown when the chat cannot load. |
|
|
198
|
+
| `debug` | `boolean` | Logs every message exchanged with the chat. |
|
|
199
|
+
|
|
200
|
+
### `useTalqui()`
|
|
201
|
+
|
|
202
|
+
| Member | |
|
|
203
|
+
| --- | --- |
|
|
204
|
+
| `open()` / `close()` | Show or hide the full-screen chat. The conversation keeps running while hidden. |
|
|
205
|
+
| `preload()` | Loads the chat ahead of time so `open()` is instant and unread messages are counted. |
|
|
206
|
+
| `identify(user)` | Sets who the user is (`name`, `email`, `phone`, `userHash`). |
|
|
207
|
+
| `setContact(contact)` | Updates `name`, `email` or `phone`. |
|
|
208
|
+
| `setContactMeta(meta)` / `setSessionMeta(meta)` | Custom data, see [Metadata](#metadata). |
|
|
209
|
+
| `prefill(text)` | Puts text in the message box. The user still decides to send it. |
|
|
210
|
+
| `logout()` | Forgets the user and starts a fresh visitor. |
|
|
211
|
+
| `unreadCount`, `isReady`, `isOpen` | Current state. |
|
|
212
|
+
|
|
213
|
+
### `<TalquiChat>`
|
|
214
|
+
|
|
215
|
+
| Prop | Type | |
|
|
216
|
+
| --- | --- | --- |
|
|
217
|
+
| `style` | `ViewStyle` | Usually `{ flex: 1 }`. |
|
|
218
|
+
| `visible` | `boolean` | Whether this screen is on screen. |
|
|
219
|
+
| `onCloseRequested` | `() => void` | The user tapped close in the header. |
|
|
220
|
+
| `hideCloseButton` | `boolean` | Hides the header's close button here. Default `false`. |
|
|
221
|
+
|
|
222
|
+
## Permissions
|
|
223
|
+
|
|
224
|
+
Attachments, photos and voice messages need these entries. With Expo, in `app.json`:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"expo": {
|
|
229
|
+
"ios": {
|
|
230
|
+
"infoPlist": {
|
|
231
|
+
"NSCameraUsageDescription": "Take photos to send in the support chat.",
|
|
232
|
+
"NSMicrophoneUsageDescription": "Record voice messages for the support chat.",
|
|
233
|
+
"NSPhotoLibraryUsageDescription": "Choose photos to send in the support chat."
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
"android": {
|
|
237
|
+
"softwareKeyboardLayoutMode": "resize",
|
|
238
|
+
"permissions": ["android.permission.CAMERA", "android.permission.RECORD_AUDIO", "android.permission.MODIFY_AUDIO_SETTINGS"]
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Bare React Native: the same keys in `ios/<App>/Info.plist` and `android/app/src/main/AndroidManifest.xml`, plus `android:windowSoftInputMode="adjustResize"` on your main activity.
|
|
245
|
+
|
|
246
|
+
## Example app
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
cd example
|
|
250
|
+
npm install
|
|
251
|
+
npx expo start
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Open it in Expo Go. It has an "Open chat" button that shows the unread count, a "Chat" tab, and buttons for identify, metadata, prefill and logout, connected to the Talqui demo workspace.
|
|
255
|
+
|
|
256
|
+
## Troubleshooting
|
|
257
|
+
|
|
258
|
+
- **The attach or camera button does nothing**: the permissions above are missing.
|
|
259
|
+
- **The keyboard covers the message box on Android**: set `softwareKeyboardLayoutMode: "resize"` (Expo) or `adjustResize` (bare).
|
|
260
|
+
- **"Invalid link" screen**: `tenantId` or `connectionId` is wrong.
|
|
261
|
+
- **`useTalqui must be used inside <TalquiProvider>`**: the provider must wrap every screen that uses the hook.
|
|
262
|
+
|
|
263
|
+
[More →](https://docs.talqui.chat/guides/chat-sdks/troubleshooting)
|
|
264
|
+
|
|
265
|
+
## How it works
|
|
266
|
+
|
|
267
|
+
The SDK hosts the Talqui WebChat in a `react-native-webview` and talks to it through a small, versioned message protocol ([`docs/BRIDGE_PROTOCOL.md`](./docs/BRIDGE_PROTOCOL.md)). The visitor's identity lives in AsyncStorage, owned by the SDK, so logout is complete and the chat page itself keeps nothing between users. Chat features ship from Talqui's side without an app update.
|
|
268
|
+
|
|
269
|
+
## Contributing
|
|
270
|
+
|
|
271
|
+
Issues and pull requests are welcome. Run `pnpm install`, then `pnpm typecheck` and `pnpm test` before opening a PR.
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
[MIT](./LICENSE.md) © [Talqui](https://talqui.chat)
|
package/dist/index.d.mts
ADDED
|
@@ -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 };
|
package/dist/index.d.ts
ADDED
|
@@ -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 };
|