@nafzo/react-native-sdk 0.0.0-stage → 1.0.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 +651 -2
- package/package.json +25 -4
- package/src/NafzoAssistant.js +46 -0
- package/src/NafzoProvider.js +92 -0
- package/src/components/ChatHeader.js +97 -0
- package/src/components/ChatInput.js +133 -0
- package/src/components/FloatingChat.js +157 -0
- package/src/components/FullscreenChat.js +83 -0
- package/src/components/MessageBubble.js +71 -0
- package/src/components/MessageList.js +119 -0
- package/src/components/TypingIndicator.js +107 -0
- package/src/hooks/useNafzoChat.js +223 -0
- package/src/index.js +23 -0
- package/src/services/api.js +112 -0
- package/src/services/history.js +19 -0
- package/src/services/session.js +95 -0
- package/src/utils/helpers.js +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IntechSol
|
|
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,652 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Nafzo React Native SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official React Native SDK for integrating Nafzo AI assistants into Android and iOS mobile applications.
|
|
4
|
+
|
|
5
|
+
Nafzo lets developers add an AI-powered assistant to their mobile app with a floating chat bubble or fullscreen chat interface, persistent conversation history, user-specific sessions, and customizable appearance.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- AI-powered assistant chat
|
|
12
|
+
- Floating chat bubble
|
|
13
|
+
- Fullscreen chat interface
|
|
14
|
+
- Emoji and text floating icons
|
|
15
|
+
- Custom React and vector icons
|
|
16
|
+
- Custom floating bubble color
|
|
17
|
+
- Custom chat theme
|
|
18
|
+
- User and assistant message colors
|
|
19
|
+
- Custom assistant name and avatar
|
|
20
|
+
- Custom welcome message
|
|
21
|
+
- Custom input placeholder
|
|
22
|
+
- Floating bubble positioning
|
|
23
|
+
- Persistent conversation history
|
|
24
|
+
- Separate chat sessions per user
|
|
25
|
+
- Automatic session restoration
|
|
26
|
+
- Android and iOS support
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Requirements
|
|
31
|
+
|
|
32
|
+
- React 18 or newer
|
|
33
|
+
- React Native 0.70 or newer
|
|
34
|
+
- Android or iOS React Native project
|
|
35
|
+
- Node.js and npm
|
|
36
|
+
- `@react-native-async-storage/async-storage`
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
Install Nafzo SDK:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @nafzo/react-native-sdk
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Install AsyncStorage, required for persistent sessions and chat history:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @react-native-async-storage/async-storage
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### iOS Setup
|
|
55
|
+
|
|
56
|
+
Install CocoaPods dependencies:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd ios
|
|
60
|
+
pod install
|
|
61
|
+
cd ..
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Android Setup
|
|
65
|
+
|
|
66
|
+
No additional manual native installation is normally required beyond installing the package dependencies and rebuilding your Android application.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Getting Your Assistant ID
|
|
71
|
+
|
|
72
|
+
Each Nafzo assistant has a unique Assistant ID.
|
|
73
|
+
|
|
74
|
+
To find your Assistant ID:
|
|
75
|
+
|
|
76
|
+
1. Log in to your Nafzo dashboard.
|
|
77
|
+
2. Open the **Assistants** section.
|
|
78
|
+
3. Select the assistant you want to integrate.
|
|
79
|
+
4. Open its details or integration/install section.
|
|
80
|
+
5. Copy the Assistant ID.
|
|
81
|
+
|
|
82
|
+
Use the copied ID in your mobile application's SDK configuration.
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
assistantId: "YOUR_ASSISTANT_ID"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Make sure you use the ID of the correct assistant.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Registering Your Mobile App in Nafzo
|
|
93
|
+
|
|
94
|
+
Before integrating the Nafzo React Native SDK, you must register your mobile application in the Nafzo dashboard for the assistant you want to use.
|
|
95
|
+
|
|
96
|
+
### Android Registration
|
|
97
|
+
|
|
98
|
+
1. Log in to your Nafzo dashboard.
|
|
99
|
+
2. Open **Assistants** and select your assistant.
|
|
100
|
+
3. Go to its **Install / Mobile Integration** section.
|
|
101
|
+
4. Select Android.
|
|
102
|
+
5. Enter your Android application package name (for example, `com.example.myapp`).
|
|
103
|
+
6. Register your application.
|
|
104
|
+
|
|
105
|
+
### iOS Registration
|
|
106
|
+
|
|
107
|
+
1. Open the same assistant's Mobile Integration section.
|
|
108
|
+
2. Select iOS.
|
|
109
|
+
3. Enter your iOS Bundle Identifier (for example, `com.example.myapp`).
|
|
110
|
+
4. Register your application.
|
|
111
|
+
|
|
112
|
+
### Important App Identifier Requirement
|
|
113
|
+
|
|
114
|
+
The `appIdentifier` and `platform` values in your SDK configuration must exactly match the application registered in your Nafzo dashboard for that assistant.
|
|
115
|
+
|
|
116
|
+
- Android: Use the registered Android package name.
|
|
117
|
+
- iOS: Use the registered iOS Bundle Identifier.
|
|
118
|
+
- Each app must be registered for the assistant it intends to use.
|
|
119
|
+
- An unregistered app or mismatched identifier will not be allowed to access the assistant.
|
|
120
|
+
|
|
121
|
+
For example, if you registered `com.example.myapp` for Android, use the following configuration:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
platform: "android",
|
|
125
|
+
appIdentifier: "com.example.myapp"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
If the app identifier does not match the registered integration, Nafzo will reject the request and the assistant will not be accessible from that app.
|
|
129
|
+
|
|
130
|
+
**Register your application before testing or releasing your mobile integration.**
|
|
131
|
+
|
|
132
|
+
## Backend URL
|
|
133
|
+
|
|
134
|
+
### Official Nafzo API
|
|
135
|
+
|
|
136
|
+
Use the official Nafzo API base URL:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
https://nafzo.wabothub.com/api
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Configure it in your SDK:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
baseUrl: "https://nafzo.wabothub.com/api"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
If you are using a self-hosted Nafzo backend, replace this URL with your own backend API base URL.
|
|
149
|
+
|
|
150
|
+
> Use your production backend URL when publishing or releasing your mobile application. Do not use localhost or a development machine IP in a production build.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Basic Integration
|
|
155
|
+
|
|
156
|
+
### 1. Import SDK components
|
|
157
|
+
|
|
158
|
+
```jsx
|
|
159
|
+
import {
|
|
160
|
+
NafzoProvider,
|
|
161
|
+
NafzoAssistant,
|
|
162
|
+
} from "@nafzo/react-native-sdk";
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 2. Wrap your application with NafzoProvider
|
|
166
|
+
|
|
167
|
+
```jsx
|
|
168
|
+
import React from "react";
|
|
169
|
+
|
|
170
|
+
import {
|
|
171
|
+
NafzoProvider,
|
|
172
|
+
NafzoAssistant,
|
|
173
|
+
} from "@nafzo/react-native-sdk";
|
|
174
|
+
|
|
175
|
+
export default function App() {
|
|
176
|
+
return (
|
|
177
|
+
<NafzoProvider
|
|
178
|
+
config={{
|
|
179
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
180
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
181
|
+
platform: "android",
|
|
182
|
+
appIdentifier: "com.example.app",
|
|
183
|
+
userId: "user_123",
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<NafzoAssistant mode="floating" />
|
|
187
|
+
</NafzoProvider>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Replace:
|
|
193
|
+
|
|
194
|
+
- `YOUR_ASSISTANT_ID` with your Nafzo assistant ID.
|
|
195
|
+
- `com.example.app` with your application's Android package name or iOS bundle identifier.
|
|
196
|
+
- `user_123` with the currently logged-in user's unique ID.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Configuration Options
|
|
201
|
+
|
|
202
|
+
| Property | Description |
|
|
203
|
+
|---|---|
|
|
204
|
+
| `assistantId` | Unique ID of the Nafzo assistant |
|
|
205
|
+
| `baseUrl` | Nafzo API base URL |
|
|
206
|
+
| `platform` | Application platform: `android` or `ios` |
|
|
207
|
+
| `appIdentifier` | Android package name or iOS bundle identifier |
|
|
208
|
+
| `userId` | Unique ID of the currently logged-in user |
|
|
209
|
+
| `storage` | Optional custom storage adapter |
|
|
210
|
+
|
|
211
|
+
### Example Configuration
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
config={{
|
|
215
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
216
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
217
|
+
platform: "android",
|
|
218
|
+
appIdentifier: "com.example.app",
|
|
219
|
+
userId: "user_123",
|
|
220
|
+
}}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Floating Chat
|
|
226
|
+
|
|
227
|
+
Display Nafzo as a floating chat bubble inside your application.
|
|
228
|
+
|
|
229
|
+
```jsx
|
|
230
|
+
<NafzoAssistant mode="floating" />
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The floating interface provides an accessible chat bubble that users can tap to open the assistant.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Fullscreen Chat
|
|
238
|
+
|
|
239
|
+
Display the assistant as a fullscreen chat interface.
|
|
240
|
+
|
|
241
|
+
```jsx
|
|
242
|
+
<NafzoAssistant mode="fullscreen" />
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Choose the presentation mode that best fits your application's design.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Floating Bubble Customization
|
|
250
|
+
|
|
251
|
+
You can customize the floating bubble's color, position, and icon.
|
|
252
|
+
|
|
253
|
+
### Custom Bubble Color
|
|
254
|
+
|
|
255
|
+
Use your application's brand color:
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
theme: {
|
|
259
|
+
primaryColor: "#6D28D9",
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Example colors:
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
primaryColor: "#2563EB" // Blue
|
|
267
|
+
primaryColor: "#16A34A" // Green
|
|
268
|
+
primaryColor: "#E11D48" // Rose
|
|
269
|
+
primaryColor: "#6D28D9" // Purple
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Replace the color code with your own brand color.
|
|
273
|
+
|
|
274
|
+
### Floating Bubble Position
|
|
275
|
+
|
|
276
|
+
Set the position of the floating bubble:
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
position: "bottom-right"
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Or:
|
|
283
|
+
|
|
284
|
+
```js
|
|
285
|
+
position: "bottom-left"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Complete Example
|
|
289
|
+
|
|
290
|
+
```jsx
|
|
291
|
+
<NafzoProvider
|
|
292
|
+
config={{
|
|
293
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
294
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
295
|
+
platform: "android",
|
|
296
|
+
appIdentifier: "com.example.app",
|
|
297
|
+
userId: "user_123",
|
|
298
|
+
|
|
299
|
+
position: "bottom-right",
|
|
300
|
+
|
|
301
|
+
theme: {
|
|
302
|
+
primaryColor: "#6D28D9",
|
|
303
|
+
},
|
|
304
|
+
}}
|
|
305
|
+
>
|
|
306
|
+
<NafzoAssistant mode="floating" />
|
|
307
|
+
</NafzoProvider>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Floating Bubble Icon Customization
|
|
313
|
+
|
|
314
|
+
Nafzo supports string icons, emojis, and custom React elements.
|
|
315
|
+
|
|
316
|
+
### 1. Emoji Icons
|
|
317
|
+
|
|
318
|
+
No additional icon library is required.
|
|
319
|
+
|
|
320
|
+
```js
|
|
321
|
+
floatingIcon: "🤖"
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Other examples:
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
floatingIcon: "💬"
|
|
328
|
+
floatingIcon: "✦"
|
|
329
|
+
floatingIcon: "🛍️"
|
|
330
|
+
floatingIcon: "🚗"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 2. Text Icons
|
|
334
|
+
|
|
335
|
+
You can use Unicode or text characters:
|
|
336
|
+
|
|
337
|
+
```js
|
|
338
|
+
floatingIcon: "✦"
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
floatingIcon: "+"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### 3. Vector Icons
|
|
346
|
+
|
|
347
|
+
You can use any React icon component from an icon library installed in your own application.
|
|
348
|
+
|
|
349
|
+
Nafzo does not require a specific vector icon library.
|
|
350
|
+
|
|
351
|
+
#### Example using lucide-react-native
|
|
352
|
+
|
|
353
|
+
Install the icon library:
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
npm install lucide-react-native
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Import an icon:
|
|
360
|
+
|
|
361
|
+
```jsx
|
|
362
|
+
import { MessageCircle } from "lucide-react-native";
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Pass it to Nafzo:
|
|
366
|
+
|
|
367
|
+
```jsx
|
|
368
|
+
<NafzoProvider
|
|
369
|
+
config={{
|
|
370
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
371
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
372
|
+
platform: "android",
|
|
373
|
+
appIdentifier: "com.example.app",
|
|
374
|
+
|
|
375
|
+
floatingIcon: (
|
|
376
|
+
<MessageCircle
|
|
377
|
+
size={28}
|
|
378
|
+
color="#FFFFFF"
|
|
379
|
+
/>
|
|
380
|
+
),
|
|
381
|
+
}}
|
|
382
|
+
>
|
|
383
|
+
<NafzoAssistant mode="floating" />
|
|
384
|
+
</NafzoProvider>
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
#### Example using Ionicons
|
|
388
|
+
|
|
389
|
+
If Ionicons is already installed in your React Native application:
|
|
390
|
+
|
|
391
|
+
```jsx
|
|
392
|
+
import Ionicons from "react-native-vector-icons/Ionicons";
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Configure your icon:
|
|
396
|
+
|
|
397
|
+
```jsx
|
|
398
|
+
floatingIcon: (
|
|
399
|
+
<Ionicons
|
|
400
|
+
name="chatbubble-ellipses"
|
|
401
|
+
size={28}
|
|
402
|
+
color="#FFFFFF"
|
|
403
|
+
/>
|
|
404
|
+
)
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### Example using a custom component
|
|
408
|
+
|
|
409
|
+
```jsx
|
|
410
|
+
import React from "react";
|
|
411
|
+
import { Text } from "react-native";
|
|
412
|
+
|
|
413
|
+
const MyChatIcon = () => (
|
|
414
|
+
<Text style={{ fontSize: 26, color: "#FFFFFF" }}>
|
|
415
|
+
💬
|
|
416
|
+
</Text>
|
|
417
|
+
);
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Use it in configuration:
|
|
421
|
+
|
|
422
|
+
```jsx
|
|
423
|
+
floatingIcon: <MyChatIcon />
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Icon Customization Notes
|
|
427
|
+
|
|
428
|
+
- String values such as emoji and text are supported.
|
|
429
|
+
- React icon elements can be passed directly.
|
|
430
|
+
- Vector icon libraries must be installed in your own app.
|
|
431
|
+
- Nafzo does not install or bundle your chosen icon library.
|
|
432
|
+
- Make sure the icon color contrasts with the bubble background.
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
## Chat Theme Customization
|
|
437
|
+
|
|
438
|
+
Customize the chat interface using the theme configuration.
|
|
439
|
+
|
|
440
|
+
```js
|
|
441
|
+
theme: {
|
|
442
|
+
primaryColor: "#6D28D9",
|
|
443
|
+
userBubbleColor: "#6D28D9",
|
|
444
|
+
assistantBubbleColor: "#F3F4F6",
|
|
445
|
+
userTextColor: "#FFFFFF",
|
|
446
|
+
assistantTextColor: "#111827",
|
|
447
|
+
typingColor: "#6B7280",
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Theme Properties
|
|
452
|
+
|
|
453
|
+
| Property | Description |
|
|
454
|
+
|---|---|
|
|
455
|
+
| `primaryColor` | Primary brand color, including floating bubble and primary interface elements |
|
|
456
|
+
| `userBubbleColor` | Background color of user messages |
|
|
457
|
+
| `assistantBubbleColor` | Background color of assistant messages |
|
|
458
|
+
| `userTextColor` | Text color of user messages |
|
|
459
|
+
| `assistantTextColor` | Text color of assistant messages |
|
|
460
|
+
| `typingColor` | Typing indicator color |
|
|
461
|
+
|
|
462
|
+
### Example Theme
|
|
463
|
+
|
|
464
|
+
```jsx
|
|
465
|
+
theme={{
|
|
466
|
+
primaryColor: "#2563EB",
|
|
467
|
+
userBubbleColor: "#2563EB",
|
|
468
|
+
assistantBubbleColor: "#E5E7EB",
|
|
469
|
+
userTextColor: "#FFFFFF",
|
|
470
|
+
assistantTextColor: "#111827",
|
|
471
|
+
typingColor: "#2563EB",
|
|
472
|
+
}}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
---
|
|
476
|
+
|
|
477
|
+
## Assistant UI Customization
|
|
478
|
+
|
|
479
|
+
Customize the assistant's display name, avatar, welcome message, and input placeholder.
|
|
480
|
+
|
|
481
|
+
```js
|
|
482
|
+
config={{
|
|
483
|
+
assistantName: "Support Assistant",
|
|
484
|
+
avatarUrl: "https://example.com/avatar.png",
|
|
485
|
+
welcomeMessage: "Hello! How can I help you today?",
|
|
486
|
+
inputPlaceholder: "Type your message...",
|
|
487
|
+
}}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Properties
|
|
491
|
+
|
|
492
|
+
| Property | Description |
|
|
493
|
+
|---|---|
|
|
494
|
+
| `assistantName` | Name shown in the chat interface |
|
|
495
|
+
| `avatarUrl` | URL of the assistant's avatar |
|
|
496
|
+
| `welcomeMessage` | Welcome message shown when starting a new conversation |
|
|
497
|
+
| `inputPlaceholder` | Placeholder shown in the message input |
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## User-Specific Chat History
|
|
502
|
+
|
|
503
|
+
Nafzo supports separate persistent chat sessions for different users.
|
|
504
|
+
|
|
505
|
+
Pass your application's unique user ID:
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
userId: user.id
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
Example:
|
|
512
|
+
|
|
513
|
+
```jsx
|
|
514
|
+
<NafzoProvider
|
|
515
|
+
config={{
|
|
516
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
517
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
518
|
+
platform: "android",
|
|
519
|
+
appIdentifier: "com.example.app",
|
|
520
|
+
userId: loggedInUser.id,
|
|
521
|
+
}}
|
|
522
|
+
>
|
|
523
|
+
<NafzoAssistant mode="floating" />
|
|
524
|
+
</NafzoProvider>
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
### How User Sessions Work
|
|
528
|
+
|
|
529
|
+
- Each user receives their own persistent chat session.
|
|
530
|
+
- Chat history is restored when the same user returns.
|
|
531
|
+
- Different users do not share the SDK's saved session key.
|
|
532
|
+
- When a different user logs in, pass that user's unique ID.
|
|
533
|
+
- Guest users can use the assistant without a `userId`.
|
|
534
|
+
|
|
535
|
+
### Important
|
|
536
|
+
|
|
537
|
+
Use a stable unique ID from your application's authentication system.
|
|
538
|
+
|
|
539
|
+
Recommended:
|
|
540
|
+
|
|
541
|
+
```js
|
|
542
|
+
userId: "user_12345"
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
Avoid using names or email addresses as user IDs. User IDs should be stable and unique.
|
|
546
|
+
|
|
547
|
+
When a user logs out, update your app's authentication state and configure Nafzo for the next user. Do not share one user's session with another user.
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## Complete Example
|
|
552
|
+
|
|
553
|
+
```jsx
|
|
554
|
+
import React from "react";
|
|
555
|
+
|
|
556
|
+
import {
|
|
557
|
+
NafzoProvider,
|
|
558
|
+
NafzoAssistant,
|
|
559
|
+
} from "@nafzo/react-native-sdk";
|
|
560
|
+
|
|
561
|
+
import { MessageCircle } from "lucide-react-native";
|
|
562
|
+
|
|
563
|
+
export default function App() {
|
|
564
|
+
return (
|
|
565
|
+
<NafzoProvider
|
|
566
|
+
config={{
|
|
567
|
+
assistantId: "YOUR_ASSISTANT_ID",
|
|
568
|
+
baseUrl: "https://nafzo.wabothub.com/api",
|
|
569
|
+
|
|
570
|
+
platform: "android",
|
|
571
|
+
appIdentifier: "com.example.app",
|
|
572
|
+
|
|
573
|
+
userId: "user_123",
|
|
574
|
+
|
|
575
|
+
assistantName: "My AI Assistant",
|
|
576
|
+
avatarUrl: "https://example.com/avatar.png",
|
|
577
|
+
welcomeMessage: "Hello! How can I help you?",
|
|
578
|
+
inputPlaceholder: "Ask me anything...",
|
|
579
|
+
|
|
580
|
+
position: "bottom-right",
|
|
581
|
+
|
|
582
|
+
floatingIcon: (
|
|
583
|
+
<MessageCircle
|
|
584
|
+
size={28}
|
|
585
|
+
color="#FFFFFF"
|
|
586
|
+
/>
|
|
587
|
+
),
|
|
588
|
+
|
|
589
|
+
theme: {
|
|
590
|
+
primaryColor: "#6D28D9",
|
|
591
|
+
userBubbleColor: "#6D28D9",
|
|
592
|
+
assistantBubbleColor: "#F3F4F6",
|
|
593
|
+
userTextColor: "#FFFFFF",
|
|
594
|
+
assistantTextColor: "#111827",
|
|
595
|
+
typingColor: "#6B7280",
|
|
596
|
+
},
|
|
597
|
+
}}
|
|
598
|
+
>
|
|
599
|
+
<NafzoAssistant mode="floating" />
|
|
600
|
+
</NafzoProvider>
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
---
|
|
606
|
+
|
|
607
|
+
## Troubleshooting
|
|
608
|
+
|
|
609
|
+
### Assistant is not loading
|
|
610
|
+
|
|
611
|
+
Check:
|
|
612
|
+
|
|
613
|
+
- Your `assistantId` is correct.
|
|
614
|
+
- Your backend `baseUrl` is correct.
|
|
615
|
+
- Your mobile device has internet access.
|
|
616
|
+
- Your assistant and app integration are configured correctly.
|
|
617
|
+
|
|
618
|
+
### Chat history is not restoring
|
|
619
|
+
|
|
620
|
+
Check:
|
|
621
|
+
|
|
622
|
+
- AsyncStorage is installed.
|
|
623
|
+
- The same `userId` is being passed when the user returns.
|
|
624
|
+
- The assistant ID has not changed.
|
|
625
|
+
- The application has not cleared its storage.
|
|
626
|
+
|
|
627
|
+
### Floating icon is not showing correctly
|
|
628
|
+
|
|
629
|
+
Check:
|
|
630
|
+
|
|
631
|
+
- The icon component is imported correctly.
|
|
632
|
+
- Your icon library is installed.
|
|
633
|
+
- The icon component is a valid React element.
|
|
634
|
+
- The icon color contrasts with the floating bubble background.
|
|
635
|
+
|
|
636
|
+
### Android connection issues during development
|
|
637
|
+
|
|
638
|
+
Make sure your Android device can access the configured backend URL. Avoid using `localhost` on your physical Android device to access a backend running on your computer.
|
|
639
|
+
|
|
640
|
+
---
|
|
641
|
+
|
|
642
|
+
## Support
|
|
643
|
+
|
|
644
|
+
Nafzo AI Assistant Platform
|
|
645
|
+
|
|
646
|
+
Website: https://nafzo.wabothub.com
|
|
647
|
+
|
|
648
|
+
---
|
|
649
|
+
|
|
650
|
+
## License
|
|
651
|
+
|
|
652
|
+
MIT License
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nafzo/react-native-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Nafzo AI assistant SDK for React Native applications",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"react-native": "src/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@react-native-async-storage/async-storage": ">=2.0.0",
|
|
14
|
+
"react": ">=18.0.0",
|
|
15
|
+
"react-native": ">=0.70.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"nafzo",
|
|
19
|
+
"react-native",
|
|
20
|
+
"ai",
|
|
21
|
+
"chatbot",
|
|
22
|
+
"ai-assistant",
|
|
23
|
+
"chat-sdk",
|
|
24
|
+
"mobile-chat"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|