@robylon/react-native-sdk 2.0.21-dev.1 → 2.0.21-staging.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/.npmignore.development +18 -0
- package/.npmignore.production +8 -0
- package/.npmignore.staging +7 -0
- package/babel.config.js +17 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/versions/version.dev.js +1 -1
- package/lib/commonjs/versions/version.staging.js +1 -1
- package/lib/commonjs/versions/version.staging.js.map +1 -1
- package/lib/module/openChatbot.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/versions/version.dev.js +1 -1
- package/lib/module/versions/version.staging.js +1 -1
- package/lib/module/versions/version.staging.js.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/lib/typescript/version.d.ts.map +1 -1
- package/lib/typescript/versions/version.dev.d.ts +1 -1
- package/lib/typescript/versions/version.staging.d.ts +1 -1
- package/lib/typescript/versions/version.staging.d.ts.map +1 -1
- package/package.json +2 -2
- package/scripts/create-branch.js +577 -0
- package/scripts/create-version-tag.js +29 -0
- package/scripts/get-next-version.js +29 -0
- package/scripts/husky-setup.js +32 -0
- package/scripts/prevent-direct-branch.js +37 -0
- package/scripts/publish-version.js +13 -0
- package/scripts/release.js +77 -0
- package/scripts/setup-git-hooks.js +18 -0
- package/scripts/update-version.js +28 -0
- package/scripts/validate-branch-name.sh +65 -0
- package/scripts/validate-publish.js +48 -0
- package/src/ChatbotWebview.tsx +44 -0
- package/src/Chatbotsdk.tsx +775 -0
- package/src/FloatingButton.tsx +88 -0
- package/src/LoadingIndicator.tsx +11 -0
- package/src/Toast.tsx +65 -0
- package/src/components/DebugButton.tsx +46 -0
- package/src/components/ErrorBoundary.tsx +38 -0
- package/src/config.ts +4 -0
- package/src/constants/errorConstants.ts +21 -0
- package/src/constants.ts +4 -0
- package/src/global.d.ts +11 -0
- package/src/hooks/useChatbotEvents.ts +93 -0
- package/src/index.tsx +10 -0
- package/src/openChatbot.ts +11 -0
- package/src/openChatbot.tsx +0 -0
- package/src/services/ErrorTrackingService.ts +217 -0
- package/src/types/events.ts +25 -0
- package/src/types/react-native-flipper-performance-plugin.d.ts +3 -0
- package/src/types/react-native-globals.d.ts +10 -0
- package/src/utils/cookieUtils.ts +7 -0
- package/src/utils/debugConfig.ts +56 -0
- package/src/utils/debugMenu.ts +14 -0
- package/src/utils/errorHandler.ts +58 -0
- package/src/utils/logger.ts +14 -0
- package/src/utils/systemInfo.ts +84 -0
- package/src/utils/webViewStorage.ts +62 -0
- package/src/version.ts +2 -0
- package/src/versions/version.dev.ts +2 -0
- package/src/versions/version.production.ts +2 -0
- package/src/versions/version.staging.ts +2 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.json +26 -0
- package/usage/react-native-ios-docs.md +0 -185
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
ReactNativeWebView: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare let global: {
|
|
10
|
+
XMLHttpRequest: any;
|
|
11
|
+
FormData: any;
|
|
12
|
+
originalXMLHttpRequest: any;
|
|
13
|
+
originalFormData: any;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const enableNetworkDebug = () => {
|
|
17
|
+
if (__DEV__) {
|
|
18
|
+
// Enable network request debugging
|
|
19
|
+
global.XMLHttpRequest =
|
|
20
|
+
global.originalXMLHttpRequest || global.XMLHttpRequest;
|
|
21
|
+
global.FormData = global.originalFormData || global.FormData;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const enableWebViewDebug = (webViewRef: any) => {
|
|
26
|
+
if (__DEV__ && Platform.OS === "ios") {
|
|
27
|
+
// Enable console.log from WebView to show in native debugger
|
|
28
|
+
const script = `
|
|
29
|
+
window.onerror = function(message, sourcefile, lineno, colno, error) {
|
|
30
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
31
|
+
type: 'ERROR',
|
|
32
|
+
data: { message, sourcefile, lineno, colno, error: error?.toString() }
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
console = new Proxy(console, {
|
|
37
|
+
get: function(target, property) {
|
|
38
|
+
const origMethod = target[property];
|
|
39
|
+
return function(...args) {
|
|
40
|
+
const logData = args.map(arg =>
|
|
41
|
+
typeof arg === 'object' ? JSON.stringify(arg) : arg
|
|
42
|
+
).join(' ');
|
|
43
|
+
|
|
44
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
45
|
+
type: 'CONSOLE',
|
|
46
|
+
level: property,
|
|
47
|
+
data: logData
|
|
48
|
+
}));
|
|
49
|
+
origMethod.apply(target, args);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
true;`;
|
|
54
|
+
webViewRef.current?.injectJavaScript(script);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Platform, NativeModules } from "react-native";
|
|
2
|
+
|
|
3
|
+
export const openDebugMenu = () => {
|
|
4
|
+
if (Platform.OS === "ios") {
|
|
5
|
+
NativeModules.DevMenu.show();
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const openDebuggerFromApp = () => {
|
|
10
|
+
if (Platform.OS === "ios") {
|
|
11
|
+
// For iOS
|
|
12
|
+
NativeModules.DevSettings.setIsDebuggingRemotely(true);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
import { ErrorTypes } from "../constants/errorConstants";
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { errorTracker } from "../services/ErrorTrackingService";
|
|
5
|
+
|
|
6
|
+
// Global error handler for uncaught errors and promise rejections
|
|
7
|
+
export const setupGlobalErrorHandlers = () => {
|
|
8
|
+
if (__DEV__) {
|
|
9
|
+
// Handle synchronous errors
|
|
10
|
+
const errorHandler = (error: Error, isFatal?: boolean) => {
|
|
11
|
+
errorTracker.trackError(error, "GlobalErrorHandler", {
|
|
12
|
+
isFatal,
|
|
13
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
14
|
+
platform: Platform.OS,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Handle promise rejections
|
|
19
|
+
const rejectionHandler = (event: any) => {
|
|
20
|
+
errorTracker.trackError(
|
|
21
|
+
event?.reason || new Error("Unknown Promise Error"),
|
|
22
|
+
"UnhandledPromiseRejection",
|
|
23
|
+
{
|
|
24
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
25
|
+
platform: Platform.OS,
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Set up handlers
|
|
31
|
+
if ((global as any).ErrorUtils) {
|
|
32
|
+
const prevHandler = (global as any).ErrorUtils.getGlobalHandler();
|
|
33
|
+
(global as any).ErrorUtils.setGlobalHandler(
|
|
34
|
+
(error: Error, isFatal?: boolean) => {
|
|
35
|
+
errorHandler(error, isFatal);
|
|
36
|
+
prevHandler(error, isFatal);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Handle promise rejections
|
|
42
|
+
const setupPromiseRejectionTracking = () => {
|
|
43
|
+
const tracking = require("promise/setimmediate/rejection-tracking");
|
|
44
|
+
tracking.enable({
|
|
45
|
+
allRejections: true,
|
|
46
|
+
onUnhandled: (id: number, error: Error) => {
|
|
47
|
+
rejectionHandler({ reason: error });
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
setupPromiseRejectionTracking();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
logger.warn("Promise rejection tracking setup failed:", error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const logger = {
|
|
2
|
+
error: (message: string, error?: any) => {
|
|
3
|
+
console.error(message, error);
|
|
4
|
+
},
|
|
5
|
+
info: (message: string, data?: any) => {
|
|
6
|
+
console.info(message, data);
|
|
7
|
+
},
|
|
8
|
+
warn: (message: string, data?: any) => {
|
|
9
|
+
console.warn(message, data);
|
|
10
|
+
},
|
|
11
|
+
debug: (message: string, data?: any) => {
|
|
12
|
+
console.log(message, data);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Platform, Dimensions, PixelRatio } from "react-native";
|
|
2
|
+
import { SDK_VERSION } from "../version";
|
|
3
|
+
|
|
4
|
+
interface ScreenSize {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface SystemInfo {
|
|
10
|
+
platform: string;
|
|
11
|
+
os: string;
|
|
12
|
+
browser: string;
|
|
13
|
+
sdk_version: string;
|
|
14
|
+
device: string;
|
|
15
|
+
screen_size: ScreenSize;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Get device type based on platform and screen dimensions
|
|
19
|
+
const getDeviceType = (): string => {
|
|
20
|
+
const { width, height } = Dimensions.get("window");
|
|
21
|
+
const aspectRatio = height / width;
|
|
22
|
+
|
|
23
|
+
if (Platform.OS === "ios") {
|
|
24
|
+
return Platform.isPad ? "iPad" : "iPhone";
|
|
25
|
+
} else if (Platform.OS === "android") {
|
|
26
|
+
return aspectRatio < 1.6 ? "Android Tablet" : "Android Phone";
|
|
27
|
+
}
|
|
28
|
+
return "Desktop";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Get screen dimensions with pixel ratio
|
|
32
|
+
const getScreenSize = (): ScreenSize => {
|
|
33
|
+
return {
|
|
34
|
+
width: Math.round(Dimensions.get("window").width * PixelRatio.get()),
|
|
35
|
+
height: Math.round(Dimensions.get("window").height * PixelRatio.get()),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Get browser detection script
|
|
40
|
+
export const getBrowserAndOSInfoScript = (): string => {
|
|
41
|
+
return `
|
|
42
|
+
function getOSAndBrowser() {
|
|
43
|
+
const userAgent = navigator.userAgent;
|
|
44
|
+
|
|
45
|
+
// OS Detection
|
|
46
|
+
let os = "unknown";
|
|
47
|
+
if (userAgent.indexOf("Win") !== -1) os = "Windows";
|
|
48
|
+
else if (userAgent.indexOf("Mac") !== -1) os = "MacOS";
|
|
49
|
+
else if (userAgent.indexOf("Linux") !== -1) os = "Linux";
|
|
50
|
+
else if (userAgent.indexOf("Android") !== -1) os = "Android";
|
|
51
|
+
else if (userAgent.indexOf("like Mac") !== -1) os = "iOS";
|
|
52
|
+
|
|
53
|
+
// Browser Detection
|
|
54
|
+
let browser = "unknown";
|
|
55
|
+
if (userAgent.indexOf("Chrome") !== -1) browser = "Chrome";
|
|
56
|
+
else if (userAgent.indexOf("Safari") !== -1) browser = "Safari";
|
|
57
|
+
else if (userAgent.indexOf("Firefox") !== -1) browser = "Firefox";
|
|
58
|
+
else if (userAgent.indexOf("Edge") !== -1) browser = "Edge";
|
|
59
|
+
else if (userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1) browser = "IE";
|
|
60
|
+
|
|
61
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
62
|
+
type: 'SYSTEM_INFO',
|
|
63
|
+
data: { os, browser }
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
getOSAndBrowser();
|
|
67
|
+
true;
|
|
68
|
+
`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Get complete system information
|
|
72
|
+
export const getSystemInfo = (webViewSystemInfo: {
|
|
73
|
+
os: string;
|
|
74
|
+
browser: string;
|
|
75
|
+
}): SystemInfo => {
|
|
76
|
+
return {
|
|
77
|
+
platform: Platform.OS,
|
|
78
|
+
os: webViewSystemInfo.os || Platform.OS,
|
|
79
|
+
browser: webViewSystemInfo.browser || "WebView",
|
|
80
|
+
sdk_version: SDK_VERSION,
|
|
81
|
+
device: getDeviceType(),
|
|
82
|
+
screen_size: getScreenSize(),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
|
|
3
|
+
export enum StorageMessageType {
|
|
4
|
+
GET_STORAGE = "GET_STORAGE",
|
|
5
|
+
SET_STORAGE = "SET_STORAGE",
|
|
6
|
+
STORAGE_READY = "STORAGE_READY",
|
|
7
|
+
STORAGE_ERROR = "STORAGE_ERROR",
|
|
8
|
+
STORAGE_RESPONSE = "STORAGE_RESPONSE",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface StorageMessage {
|
|
12
|
+
type: StorageMessageType;
|
|
13
|
+
key?: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getStorageScript = () => `
|
|
19
|
+
window.handleStorageOperation = function(message) {
|
|
20
|
+
try {
|
|
21
|
+
switch(message.type) {
|
|
22
|
+
case '${StorageMessageType.GET_STORAGE}':
|
|
23
|
+
const value = localStorage.getItem(message.key);
|
|
24
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
25
|
+
type: '${StorageMessageType.STORAGE_RESPONSE}',
|
|
26
|
+
key: message.key,
|
|
27
|
+
value: value
|
|
28
|
+
}));
|
|
29
|
+
break;
|
|
30
|
+
case '${StorageMessageType.SET_STORAGE}':
|
|
31
|
+
localStorage.setItem(message.key, message.value);
|
|
32
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
33
|
+
type: '${StorageMessageType.STORAGE_RESPONSE}',
|
|
34
|
+
key: message.key,
|
|
35
|
+
value: message.value
|
|
36
|
+
}));
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
41
|
+
type: '${StorageMessageType.STORAGE_ERROR}',
|
|
42
|
+
error: error.message
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
48
|
+
type: '${StorageMessageType.STORAGE_READY}'
|
|
49
|
+
}));
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const createStorageMessage = (
|
|
53
|
+
type: StorageMessageType,
|
|
54
|
+
key?: string,
|
|
55
|
+
value?: string
|
|
56
|
+
): string => {
|
|
57
|
+
return `window.handleStorageOperation(${JSON.stringify({
|
|
58
|
+
type,
|
|
59
|
+
key,
|
|
60
|
+
value,
|
|
61
|
+
})});`;
|
|
62
|
+
};
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"outDir": "./lib/typescript"
|
|
6
|
+
},
|
|
7
|
+
"exclude": [
|
|
8
|
+
"**/__tests__",
|
|
9
|
+
"**/__mocks__",
|
|
10
|
+
"**/__fixtures__",
|
|
11
|
+
"node_modules",
|
|
12
|
+
"babel.config.js",
|
|
13
|
+
"metro.config.js",
|
|
14
|
+
"jest.config.js"
|
|
15
|
+
]
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"lib": ["esnext"],
|
|
6
|
+
"jsx": "react-native",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": false,
|
|
16
|
+
"emitDeclarationOnly": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"types": ["react-native", "node"]
|
|
19
|
+
},
|
|
20
|
+
"exclude": [
|
|
21
|
+
"node_modules",
|
|
22
|
+
"babel.config.js",
|
|
23
|
+
"metro.config.js",
|
|
24
|
+
"jest.config.js"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Robylon React Native SDK Documentation
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
First, install the package using npm or yarn:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Using npm
|
|
9
|
-
npm install @robylon/react-native-sdk react-native-webview
|
|
10
|
-
|
|
11
|
-
# Using yarn
|
|
12
|
-
yarn add @robylon/react-native-sdk react-native-webview
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Prerequisites
|
|
16
|
-
|
|
17
|
-
- React Native project set up for iOS
|
|
18
|
-
- `react-native-webview` installed and configured
|
|
19
|
-
- Valid Robylon API key
|
|
20
|
-
|
|
21
|
-
## Basic Implementation
|
|
22
|
-
|
|
23
|
-
### 1. Import the SDK
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { ChatbotSDK } from "@robylon/react-native-sdk";
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 2. Basic Usage
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
import React from "react";
|
|
33
|
-
import { View } from "react-native";
|
|
34
|
-
import { ChatbotSDK } from "@robylon/react-native-sdk";
|
|
35
|
-
|
|
36
|
-
const App = () => {
|
|
37
|
-
return (
|
|
38
|
-
<View style={{ flex: 1 }}>
|
|
39
|
-
<ChatbotSDK
|
|
40
|
-
api_key="YOUR_API_KEY"
|
|
41
|
-
user_id="USER_ID"
|
|
42
|
-
user_token="USER_TOKEN"
|
|
43
|
-
/>
|
|
44
|
-
</View>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default App;
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Props Reference
|
|
52
|
-
|
|
53
|
-
### Required Props
|
|
54
|
-
|
|
55
|
-
| Prop | Type | Description |
|
|
56
|
-
| --------- | ------ | ------------------------------ |
|
|
57
|
-
| `api_key` | string | Your Robylon API key |
|
|
58
|
-
| `user_id` | string | Unique identifier for the user |
|
|
59
|
-
|
|
60
|
-
### Optional Props
|
|
61
|
-
|
|
62
|
-
| Prop | Type | Default | Description |
|
|
63
|
-
| ---------------------- | ---------------------- | --------- | -------------------------------------------- |
|
|
64
|
-
| `user_token` | string | undefined | Authentication token for the user |
|
|
65
|
-
| `additional_params` | Record<string, string> | {} | Additional parameters to pass to the chatbot |
|
|
66
|
-
| `show_floating_button` | boolean | true | Whether to show the floating button |
|
|
67
|
-
| `isFullScreen` | boolean | true | Whether to display in fullscreen mode |
|
|
68
|
-
| `enableAnimation` | boolean | true | Enable/disable animations |
|
|
69
|
-
| `onMessage` | (message: any) => void | undefined | Callback for chatbot messages |
|
|
70
|
-
| `onOpen` | () => void | undefined | Callback when chatbot opens |
|
|
71
|
-
| `onClose` | () => void | undefined | Callback when chatbot closes |
|
|
72
|
-
|
|
73
|
-
## Advanced Implementation
|
|
74
|
-
|
|
75
|
-
### Custom Configuration Example
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import React from "react";
|
|
79
|
-
import { View } from "react-native";
|
|
80
|
-
import { ChatbotSDK } from "@robylon/react-native-sdk";
|
|
81
|
-
|
|
82
|
-
const App = () => {
|
|
83
|
-
const handleMessage = (message) => {
|
|
84
|
-
console.log("Received message:", message);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const handleOpen = () => {
|
|
88
|
-
console.log("Chatbot opened");
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const handleClose = () => {
|
|
92
|
-
console.log("Chatbot closed");
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<View style={{ flex: 1 }}>
|
|
97
|
-
<ChatbotSDK
|
|
98
|
-
api_key="YOUR_API_KEY"
|
|
99
|
-
user_id="USER_ID"
|
|
100
|
-
user_token="USER_TOKEN"
|
|
101
|
-
additional_params={{
|
|
102
|
-
theme: "light",
|
|
103
|
-
language: "en",
|
|
104
|
-
}}
|
|
105
|
-
show_floating_button={true}
|
|
106
|
-
isFullScreen={true}
|
|
107
|
-
enableAnimation={true}
|
|
108
|
-
onMessage={handleMessage}
|
|
109
|
-
onOpen={handleOpen}
|
|
110
|
-
onClose={handleClose}
|
|
111
|
-
/>
|
|
112
|
-
</View>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export default App;
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
<!-- ### Handling Messages
|
|
120
|
-
|
|
121
|
-
The `onMessage` callback receives messages in the following format:
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
interface ChatbotMessage {
|
|
125
|
-
type: string;
|
|
126
|
-
data?: any;
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Example message handler:
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
const handleMessage = (message: ChatbotMessage) => {
|
|
134
|
-
switch (message.type) {
|
|
135
|
-
case 'user_message':
|
|
136
|
-
console.log('User sent:', message.data);
|
|
137
|
-
break;
|
|
138
|
-
case 'bot_response':
|
|
139
|
-
console.log('Bot responded:', message.data);
|
|
140
|
-
break;
|
|
141
|
-
// Handle other message types
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
``` -->
|
|
145
|
-
|
|
146
|
-
## Styling and Customization
|
|
147
|
-
|
|
148
|
-
The SDK automatically fetches and applies your organization's branding configuration, including:
|
|
149
|
-
|
|
150
|
-
- Brand color
|
|
151
|
-
- Launcher logo
|
|
152
|
-
- Welcome message
|
|
153
|
-
|
|
154
|
-
<!-- These are fetched using the provided API key and user credentials. -->
|
|
155
|
-
|
|
156
|
-
## Best Practices
|
|
157
|
-
|
|
158
|
-
1. **Error Handling**: Always implement error handling for network requests and message processing.
|
|
159
|
-
2. **User Authentication**: Ensure user_id and user_token are properly managed and updated.
|
|
160
|
-
3. **Performance**: Consider using `useMemo` or `useCallback` for callback functions to optimize performance.
|
|
161
|
-
4. **Testing**: Test the implementation across different iOS devices and orientations.
|
|
162
|
-
|
|
163
|
-
## Troubleshooting
|
|
164
|
-
|
|
165
|
-
Common issues and solutions:
|
|
166
|
-
|
|
167
|
-
1. **WebView Not Loading**
|
|
168
|
-
|
|
169
|
-
- Verify internet connectivity
|
|
170
|
-
- Check if API key is valid
|
|
171
|
-
- Ensure WebView permissions are properly configured
|
|
172
|
-
|
|
173
|
-
2. **Authentication Issues**
|
|
174
|
-
|
|
175
|
-
- Verify user_token is valid and not expired
|
|
176
|
-
- Check if user_id is correctly formatted
|
|
177
|
-
|
|
178
|
-
3. **UI Issues**
|
|
179
|
-
- Ensure proper layout hierarchy
|
|
180
|
-
- Check for conflicts with other UI elements
|
|
181
|
-
- Verify styling properties
|
|
182
|
-
|
|
183
|
-
## Support
|
|
184
|
-
|
|
185
|
-
For additional support or to report issues, please contact Robylon support or refer to the official documentation.
|