@worktual/react-native-ai-bot 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +92 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -21,7 +21,53 @@ For iOS:
21
21
  cd ios && pod install
22
22
  ```
23
23
 
24
- ## Quick Start
24
+ ## Quick Start (Recommended - Instant Open)
25
+
26
+ For the best user experience, mount the bot **hidden at your app root** so it pre-loads in the background. When the user taps your button, the bot opens **instantly** with zero loading time.
27
+
28
+ ```tsx
29
+ import React, { useState } from "react";
30
+ import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
31
+ import { WorktualAIBot } from "@worktual/react-native-ai-bot";
32
+
33
+ const App = () => {
34
+ const [showBot, setShowBot] = useState(false);
35
+
36
+ return (
37
+ <View style={{ flex: 1 }}>
38
+ {/* Your app content */}
39
+ <TouchableOpacity onPress={() => setShowBot(true)}>
40
+ <Text>Open AI Chat</Text>
41
+ </TouchableOpacity>
42
+
43
+ {/* Bot is always mounted but hidden — pre-loads in background */}
44
+ <View
45
+ style={[
46
+ StyleSheet.absoluteFill,
47
+ {
48
+ zIndex: showBot ? 999 : -1,
49
+ opacity: showBot ? 1 : 0,
50
+ },
51
+ ]}
52
+ pointerEvents={showBot ? "auto" : "none"}
53
+ >
54
+ <WorktualAIBot
55
+ webchatId="YOUR_WEBCHAT_ID"
56
+ onClose={() => setShowBot(false)}
57
+ />
58
+ </View>
59
+ </View>
60
+ );
61
+ };
62
+
63
+ export default App;
64
+ ```
65
+
66
+ **Why this works:** The WebView starts loading the bot HTML/JS/CSS as soon as your app renders. By the time the user taps the button, everything is already loaded. Toggling visibility is instant — no loading screen, no delay.
67
+
68
+ ## Alternative: Navigation-Based (Shows Loading Screen)
69
+
70
+ If you prefer a separate screen approach, the bot will show a brief loading screen while the WebView downloads:
25
71
 
26
72
  ```tsx
27
73
  import React from "react";
@@ -45,7 +91,7 @@ Register it as a screen in your navigator:
45
91
  <Stack.Screen name="ChatBot" component={ChatBotScreen} />
46
92
  ```
47
93
 
48
- Then navigate to it from anywhere (e.g. a floating button):
94
+ Then navigate to it:
49
95
 
50
96
  ```tsx
51
97
  <TouchableOpacity onPress={() => navigation.navigate("ChatBot")}>
@@ -53,8 +99,32 @@ Then navigate to it from anywhere (e.g. a floating button):
53
99
  </TouchableOpacity>
54
100
  ```
55
101
 
102
+ > **Note:** This approach mounts a fresh WebView each time, so users will see a loading screen for 2-5 seconds while the bot downloads. Use the [recommended approach](#quick-start-recommended---instant-open) above for instant loading.
103
+
104
+ ## Preloader (For Navigation-Based Setup)
105
+
106
+ If you use the navigation approach but still want faster loading, mount the `WorktualAIBotPreloader` early in your app tree. It pre-fetches and caches the bot resources in the background:
107
+
108
+ ```tsx
109
+ import { WorktualAIBotPreloader } from "@worktual/react-native-ai-bot";
110
+
111
+ // In your App.tsx or root layout
112
+ const App = () => {
113
+ return (
114
+ <SafeAreaProvider>
115
+ <WorktualAIBotPreloader webchatId="YOUR_WEBCHAT_ID" />
116
+ <NavigationContainer>
117
+ {/* ... your screens */}
118
+ </NavigationContainer>
119
+ </SafeAreaProvider>
120
+ );
121
+ };
122
+ ```
123
+
56
124
  ## Props
57
125
 
126
+ ### WorktualAIBot
127
+
58
128
  | Prop | Type | Required | Default | Description |
59
129
  |------|------|----------|---------|-------------|
60
130
  | `webchatId` | `string` | Yes | — | Your unique webchat ID provided by Worktual |
@@ -71,6 +141,13 @@ Then navigate to it from anywhere (e.g. a floating button):
71
141
  | `onReady` | `() => void` | No | — | Called when chat content is fully loaded |
72
142
  | `onMessage` | `(data) => void` | No | — | Called on every message from the chat |
73
143
 
144
+ ### WorktualAIBotPreloader
145
+
146
+ | Prop | Type | Required | Default | Description |
147
+ |------|------|----------|---------|-------------|
148
+ | `webchatId` | `string` | Yes | — | Your unique webchat ID provided by Worktual |
149
+ | `baseUrl` | `string` | No | Worktual production URL | Custom bot URL if self-hosted |
150
+
74
151
  ## Customisation Examples
75
152
 
76
153
  ### Custom logo on loading screen
@@ -80,7 +157,7 @@ Use a local image:
80
157
  ```tsx
81
158
  <WorktualAIBot
82
159
  webchatId="YOUR_WEBCHAT_ID"
83
- onClose={() => navigation.goBack()}
160
+ onClose={() => setShowBot(false)}
84
161
  loadingLogo={require("./assets/my-logo.png")}
85
162
  loadingLogoWidth={120}
86
163
  loadingLogoHeight={120}
@@ -92,7 +169,7 @@ Or a remote URL:
92
169
  ```tsx
93
170
  <WorktualAIBot
94
171
  webchatId="YOUR_WEBCHAT_ID"
95
- onClose={() => navigation.goBack()}
172
+ onClose={() => setShowBot(false)}
96
173
  loadingLogo={{ uri: "https://example.com/logo.png" }}
97
174
  loadingLogoWidth={100}
98
175
  loadingLogoHeight={100}
@@ -106,7 +183,7 @@ Or a remote URL:
106
183
  ```tsx
107
184
  <WorktualAIBot
108
185
  webchatId="YOUR_WEBCHAT_ID"
109
- onClose={() => navigation.goBack()}
186
+ onClose={() => setShowBot(false)}
110
187
  loadingLogo={require("./assets/logo.png")}
111
188
  loadingTitle="Support Chat"
112
189
  loadingSubtitle="Connecting to an agent..."
@@ -142,7 +219,7 @@ const App = () => {
142
219
  ```tsx
143
220
  <WorktualAIBot
144
221
  webchatId="YOUR_WEBCHAT_ID"
145
- onClose={() => navigation.goBack()}
222
+ onClose={() => setShowBot(false)}
146
223
  onReady={() => console.log("Bot is ready!")}
147
224
  onMessage={(data) => console.log("Bot event:", data)}
148
225
  />
@@ -150,11 +227,18 @@ const App = () => {
150
227
 
151
228
  ## How It Works
152
229
 
153
- 1. Client taps a button → navigates to the bot screen
230
+ ### Recommended (Instant Open)
231
+ 1. Bot WebView is mounted hidden when your app loads
232
+ 2. HTML/JS/CSS downloads in the background automatically
233
+ 3. User taps button → bot becomes visible instantly (no loading screen)
234
+ 4. User closes chat → bot hides (stays mounted, ready for next open)
235
+
236
+ ### Navigation-Based (With Loading Screen)
237
+ 1. User taps button → navigates to bot screen
154
238
  2. A branded loading screen appears (with animated progress bar)
155
239
  3. The chat loads behind the loading screen
156
240
  4. Once chat content is rendered, the loader fades out smoothly
157
- 5. When the user closes the chat (via the bot's close button), `onClose` is called
241
+ 5. User closes chat `onClose` is called, navigates back
158
242
 
159
243
  ## Requirements
160
244
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worktual/react-native-ai-bot",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Worktual AI Bot - Embeddable AI chatbot for React Native apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",