@robylon/react-native-sdk 1.10.1-staging.11 → 1.10.1-staging.3
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.production +0 -1
- package/.npmignore.staging +0 -1
- package/README.md +0 -185
- package/babel.config.js +3 -16
- package/lib/commonjs/ChatbotWebview.js +44 -1
- package/lib/commonjs/ChatbotWebview.js.map +1 -1
- package/lib/commonjs/Chatbotsdk.js +309 -1
- package/lib/commonjs/Chatbotsdk.js.map +1 -1
- package/lib/commonjs/FloatingButton.js +60 -1
- package/lib/commonjs/FloatingButton.js.map +1 -1
- package/lib/commonjs/LoadingIndicator.js +20 -1
- package/lib/commonjs/LoadingIndicator.js.map +1 -1
- package/lib/commonjs/config.js +10 -1
- package/lib/commonjs/config.js.map +1 -1
- package/lib/commonjs/constants.js +9 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/global.d.js +7 -1
- package/lib/commonjs/global.d.js.map +1 -1
- package/lib/commonjs/index.js +20 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/openChatbot.js +16 -1
- package/lib/commonjs/openChatbot.js.map +1 -1
- package/lib/module/ChatbotWebview.js +33 -1
- package/lib/module/ChatbotWebview.js.map +1 -1
- package/lib/module/Chatbotsdk.js +300 -1
- package/lib/module/Chatbotsdk.js.map +1 -1
- package/lib/module/FloatingButton.js +53 -1
- package/lib/module/FloatingButton.js.map +1 -1
- package/lib/module/LoadingIndicator.js +13 -1
- package/lib/module/LoadingIndicator.js.map +1 -1
- package/lib/module/config.js +4 -1
- package/lib/module/config.js.map +1 -1
- package/lib/module/constants.js +3 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/global.d.js +6 -1
- package/lib/module/global.d.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/openChatbot.js +9 -1
- package/package.json +13 -20
- package/src/FloatingButton.tsx +6 -6
package/.npmignore.production
CHANGED
package/.npmignore.staging
CHANGED
package/README.md
CHANGED
|
@@ -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.
|
package/babel.config.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
module.exports =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
presets: ["module:metro-react-native-babel-preset"],
|
|
5
|
-
plugins: [
|
|
6
|
-
[
|
|
7
|
-
"inline-dotenv",
|
|
8
|
-
{
|
|
9
|
-
path:
|
|
10
|
-
process.env.NODE_ENV === "production"
|
|
11
|
-
? ".env.production"
|
|
12
|
-
: ".env.staging",
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
],
|
|
16
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
presets: ["module:metro-react-native-babel-preset"],
|
|
3
|
+
plugins: ["transform-inline-environment-variables"],
|
|
17
4
|
};
|
|
@@ -1,2 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ChatbotWebview = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeWebview = require("react-native-webview");
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
var _LoadingIndicator = _interopRequireDefault(require("./LoadingIndicator"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
// File: src/ChatbotWebview.tsx
|
|
16
|
+
|
|
17
|
+
const constructUrl = (chatbotId, additionalParams = {}) => {
|
|
18
|
+
const params = new URLSearchParams({
|
|
19
|
+
id: chatbotId,
|
|
20
|
+
...additionalParams
|
|
21
|
+
});
|
|
22
|
+
return `${_constants.BASE_CHATBOT_URL}?${params.toString()}`;
|
|
23
|
+
};
|
|
24
|
+
const ChatbotWebview = ({
|
|
25
|
+
chatbotId,
|
|
26
|
+
additionalParams
|
|
27
|
+
}) => {
|
|
28
|
+
const [url, setUrl] = (0, _react.useState)("");
|
|
29
|
+
(0, _react.useEffect)(() => {
|
|
30
|
+
setUrl(constructUrl(chatbotId, additionalParams));
|
|
31
|
+
}, [chatbotId, additionalParams]);
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
33
|
+
style: {
|
|
34
|
+
flex: 1
|
|
35
|
+
}
|
|
36
|
+
}, url ? /*#__PURE__*/_react.default.createElement(_reactNativeWebview.WebView, {
|
|
37
|
+
source: {
|
|
38
|
+
uri: url
|
|
39
|
+
},
|
|
40
|
+
startInLoadingState: true,
|
|
41
|
+
renderLoading: () => /*#__PURE__*/_react.default.createElement(_LoadingIndicator.default, null)
|
|
42
|
+
}) : /*#__PURE__*/_react.default.createElement(_LoadingIndicator.default, null));
|
|
43
|
+
};
|
|
44
|
+
exports.ChatbotWebview = ChatbotWebview;
|
|
2
45
|
//# sourceMappingURL=ChatbotWebview.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeWebview","_constants","_LoadingIndicator","_interopRequireDefault","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeWebview","_constants","_LoadingIndicator","_interopRequireDefault","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","constructUrl","chatbotId","additionalParams","params","URLSearchParams","id","BASE_CHATBOT_URL","toString","ChatbotWebview","url","setUrl","useState","useEffect","createElement","View","style","flex","WebView","source","uri","startInLoadingState","renderLoading","exports"],"sourceRoot":"../../src","sources":["ChatbotWebview.tsx"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,2 +1,310 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeWebview = require("react-native-webview");
|
|
10
|
+
var _FloatingButton = _interopRequireDefault(require("./FloatingButton"));
|
|
11
|
+
var _constants = require("./constants");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
const ChatbotSDK = ({
|
|
16
|
+
api_key,
|
|
17
|
+
user_id,
|
|
18
|
+
user_token,
|
|
19
|
+
additional_params = {},
|
|
20
|
+
show_floating_button = true,
|
|
21
|
+
onMessage,
|
|
22
|
+
isFullScreen = true,
|
|
23
|
+
enableAnimation = true,
|
|
24
|
+
onOpen,
|
|
25
|
+
onClose
|
|
26
|
+
}) => {
|
|
27
|
+
const [isWebViewVisible, setIsWebViewVisible] = (0, _react.useState)(false);
|
|
28
|
+
const [chatbotConfig, setChatbotConfig] = (0, _react.useState)(null);
|
|
29
|
+
const [loading, setLoading] = (0, _react.useState)(true);
|
|
30
|
+
const webViewRef = (0, _react.useRef)(null);
|
|
31
|
+
const fadeAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
|
|
32
|
+
const isFirstLoadRef = (0, _react.useRef)(true);
|
|
33
|
+
const webViewUrl = (0, _react.useMemo)(() => constructUrl(), [api_key, user_id, additional_params]);
|
|
34
|
+
const stableAdditionalParams = (0, _react.useMemo)(() => additional_params, [JSON.stringify(additional_params)]);
|
|
35
|
+
const triggerAppInit = () => {
|
|
36
|
+
if (webViewRef.current) {
|
|
37
|
+
webViewRef.current.injectJavaScript(`
|
|
38
|
+
// Trigger APP_READY equivalent
|
|
39
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'APP_READY' }));
|
|
40
|
+
true;
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
(0, _react.useEffect)(() => {
|
|
45
|
+
const fetchChatbotConfig = async () => {
|
|
46
|
+
try {
|
|
47
|
+
var _data$user;
|
|
48
|
+
const endpointUrl = `https://stage-api.robylon.ai/users/auth/copilot/`;
|
|
49
|
+
const payload = {
|
|
50
|
+
client_user_id: user_id,
|
|
51
|
+
org_id: api_key,
|
|
52
|
+
token: user_token,
|
|
53
|
+
extra_info: stableAdditionalParams
|
|
54
|
+
};
|
|
55
|
+
const response = await fetch(endpointUrl, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json"
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify(payload)
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new Error("Failed to fetch chatbot configuration");
|
|
64
|
+
}
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
const orgInfo = data === null || data === void 0 || (_data$user = data.user) === null || _data$user === void 0 ? void 0 : _data$user.org_info;
|
|
67
|
+
if (orgInfo) {
|
|
68
|
+
var _orgInfo$config, _orgInfo$brand_config, _orgInfo$config2;
|
|
69
|
+
setChatbotConfig({
|
|
70
|
+
brand_color: (orgInfo === null || orgInfo === void 0 || (_orgInfo$config = orgInfo.config) === null || _orgInfo$config === void 0 ? void 0 : _orgInfo$config.brand_colour) || "#007AFF",
|
|
71
|
+
image_url: (orgInfo === null || orgInfo === void 0 || (_orgInfo$brand_config = orgInfo.brand_config) === null || _orgInfo$brand_config === void 0 ? void 0 : _orgInfo$brand_config.launcher_logo_url) || "",
|
|
72
|
+
welcome_message: (orgInfo === null || orgInfo === void 0 || (_orgInfo$config2 = orgInfo.config) === null || _orgInfo$config2 === void 0 ? void 0 : _orgInfo$config2.welcome_message) || ""
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("Error fetching chatbot configuration:", error);
|
|
77
|
+
} finally {
|
|
78
|
+
setLoading(false);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
if (api_key && user_id) {
|
|
82
|
+
fetchChatbotConfig();
|
|
83
|
+
}
|
|
84
|
+
}, [api_key, user_id, user_token, stableAdditionalParams]);
|
|
85
|
+
function constructUrl() {
|
|
86
|
+
if (!user_id) return "";
|
|
87
|
+
const params = new URLSearchParams({
|
|
88
|
+
id: api_key,
|
|
89
|
+
user_id,
|
|
90
|
+
...additional_params
|
|
91
|
+
});
|
|
92
|
+
return `${_constants.BASE_CHATBOT_URL}?${params.toString()}`;
|
|
93
|
+
}
|
|
94
|
+
const openWebView = () => {
|
|
95
|
+
setIsWebViewVisible(true);
|
|
96
|
+
if (enableAnimation) {
|
|
97
|
+
_reactNative.Animated.timing(fadeAnim, {
|
|
98
|
+
toValue: 1,
|
|
99
|
+
duration: 250,
|
|
100
|
+
useNativeDriver: true
|
|
101
|
+
}).start(() => {
|
|
102
|
+
onOpen === null || onOpen === void 0 || onOpen();
|
|
103
|
+
if (!isFirstLoadRef.current) {
|
|
104
|
+
// If not first load, manually trigger initialization
|
|
105
|
+
setTimeout(triggerAppInit, 100);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
fadeAnim.setValue(1);
|
|
110
|
+
requestAnimationFrame(() => {
|
|
111
|
+
onOpen === null || onOpen === void 0 || onOpen();
|
|
112
|
+
if (!isFirstLoadRef.current) {
|
|
113
|
+
setTimeout(triggerAppInit, 100);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const closeWebView = () => {
|
|
119
|
+
if (webViewRef.current) {
|
|
120
|
+
console.log("closeWebView");
|
|
121
|
+
webViewRef.current.postMessage(JSON.stringify({
|
|
122
|
+
name: "closeFrame",
|
|
123
|
+
domain: "app-domain.com"
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
const complete = () => {
|
|
127
|
+
setIsWebViewVisible(false);
|
|
128
|
+
onClose === null || onClose === void 0 || onClose();
|
|
129
|
+
};
|
|
130
|
+
if (enableAnimation) {
|
|
131
|
+
_reactNative.Animated.timing(fadeAnim, {
|
|
132
|
+
toValue: 0,
|
|
133
|
+
duration: 200,
|
|
134
|
+
useNativeDriver: true
|
|
135
|
+
}).start(complete);
|
|
136
|
+
} else {
|
|
137
|
+
fadeAnim.setValue(0);
|
|
138
|
+
requestAnimationFrame(complete);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const handleMessage = event => {
|
|
142
|
+
const {
|
|
143
|
+
data
|
|
144
|
+
} = event.nativeEvent;
|
|
145
|
+
try {
|
|
146
|
+
const parsedData = JSON.parse(data);
|
|
147
|
+
if (parsedData.type === "APP_READY") {
|
|
148
|
+
console.log("APP_READY", webViewRef.current && isWebViewVisible);
|
|
149
|
+
if (webViewRef.current && isWebViewVisible) {
|
|
150
|
+
webViewRef.current.injectJavaScript(`
|
|
151
|
+
window.postMessage(${JSON.stringify({
|
|
152
|
+
name: "openFrame",
|
|
153
|
+
domain: "app-domain.com"
|
|
154
|
+
})}, '*');
|
|
155
|
+
window.postMessage(${JSON.stringify({
|
|
156
|
+
name: "registerUserId",
|
|
157
|
+
action: "registerUserId",
|
|
158
|
+
domain: "app-domain.com",
|
|
159
|
+
data: {
|
|
160
|
+
userId: `${user_id}`,
|
|
161
|
+
token: `${user_token}`
|
|
162
|
+
}
|
|
163
|
+
})}, '*');
|
|
164
|
+
`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (typeof parsedData !== "object" || !parsedData.type) {
|
|
168
|
+
console.warn("Invalid message structure");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
switch (parsedData.type) {
|
|
172
|
+
case "close_chatbot":
|
|
173
|
+
closeWebView();
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
if (onMessage) onMessage(parsedData);
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error("Failed to parse or process WebView message:", error);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const getScreenDimensions = () => {
|
|
183
|
+
const windowHeight = _reactNative.Dimensions.get("window").height;
|
|
184
|
+
const windowWidth = _reactNative.Dimensions.get("window").width;
|
|
185
|
+
const statusBarHeight = _reactNative.Platform.OS === "ios" ? 0 : _reactNative.StatusBar.currentHeight || 0;
|
|
186
|
+
return {
|
|
187
|
+
height: windowHeight - statusBarHeight,
|
|
188
|
+
width: windowWidth
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
const screenDimensions = getScreenDimensions();
|
|
192
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
193
|
+
style: styles.mainContainer
|
|
194
|
+
}, !loading && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, show_floating_button && api_key && chatbotConfig && /*#__PURE__*/_react.default.createElement(_FloatingButton.default, {
|
|
195
|
+
onPress: openWebView,
|
|
196
|
+
brandColor: chatbotConfig.brand_color,
|
|
197
|
+
imageUrl: chatbotConfig.image_url
|
|
198
|
+
}), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
199
|
+
style: [styles.webViewWrapper, {
|
|
200
|
+
height: isWebViewVisible ? "100%" : 0
|
|
201
|
+
}],
|
|
202
|
+
pointerEvents: isWebViewVisible ? "auto" : "none"
|
|
203
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
|
|
204
|
+
style: [isFullScreen ? styles.fullScreenContainer : styles.inlineContainer, {
|
|
205
|
+
opacity: fadeAnim
|
|
206
|
+
}]
|
|
207
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNativeWebview.WebView, {
|
|
208
|
+
ref: webViewRef,
|
|
209
|
+
source: {
|
|
210
|
+
uri: webViewUrl
|
|
211
|
+
},
|
|
212
|
+
onMessage: handleMessage,
|
|
213
|
+
style: styles.webview,
|
|
214
|
+
containerStyle: isFullScreen ? {
|
|
215
|
+
width: screenDimensions.width,
|
|
216
|
+
height: screenDimensions.height
|
|
217
|
+
} : undefined,
|
|
218
|
+
allowsInlineMediaPlayback: true,
|
|
219
|
+
mediaPlaybackRequiresUserAction: false,
|
|
220
|
+
allowFileAccess: false,
|
|
221
|
+
geolocationEnabled: false,
|
|
222
|
+
javaScriptEnabled: true,
|
|
223
|
+
domStorageEnabled: true,
|
|
224
|
+
cacheEnabled: true,
|
|
225
|
+
scrollEnabled: true,
|
|
226
|
+
bounces: false,
|
|
227
|
+
onShouldStartLoadWithRequest: request => {
|
|
228
|
+
return request.url.startsWith(_constants.BASE_CHATBOT_URL);
|
|
229
|
+
},
|
|
230
|
+
startInLoadingState: isFirstLoadRef.current,
|
|
231
|
+
onLoadEnd: () => {
|
|
232
|
+
var _webViewRef$current;
|
|
233
|
+
(_webViewRef$current = webViewRef.current) === null || _webViewRef$current === void 0 || _webViewRef$current.injectJavaScript(`
|
|
234
|
+
if (!document.querySelector('meta[name="viewport"]')) {
|
|
235
|
+
var meta = document.createElement('meta');
|
|
236
|
+
meta.name = 'viewport';
|
|
237
|
+
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
|
|
238
|
+
document.getElementsByTagName('head')[0].appendChild(meta);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!document.querySelector('#injectedStyle')) {
|
|
242
|
+
const style = document.createElement('style');
|
|
243
|
+
style.id = 'injectedStyle';
|
|
244
|
+
style.textContent = \`
|
|
245
|
+
html, body, #root, #__next {
|
|
246
|
+
height: 100% !important;
|
|
247
|
+
min-height: 100% !important;
|
|
248
|
+
overflow: hidden !important;
|
|
249
|
+
}
|
|
250
|
+
\`;
|
|
251
|
+
document.head.appendChild(style);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
window.sendToChatbot = function(message) {
|
|
255
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
var closeButton = document.querySelector('.chatbot-close-button');
|
|
259
|
+
if (closeButton) {
|
|
260
|
+
closeButton.addEventListener('click', () => {
|
|
261
|
+
window.sendToChatbot({ type: 'close_chatbot' });
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
true;
|
|
266
|
+
`);
|
|
267
|
+
isFirstLoadRef.current = false;
|
|
268
|
+
},
|
|
269
|
+
onError: syntheticEvent => {
|
|
270
|
+
const {
|
|
271
|
+
nativeEvent
|
|
272
|
+
} = syntheticEvent;
|
|
273
|
+
console.warn("WebView error:", nativeEvent);
|
|
274
|
+
}
|
|
275
|
+
})))));
|
|
276
|
+
};
|
|
277
|
+
const styles = _reactNative.StyleSheet.create({
|
|
278
|
+
mainContainer: {
|
|
279
|
+
flex: 1,
|
|
280
|
+
position: "relative"
|
|
281
|
+
},
|
|
282
|
+
webViewWrapper: {
|
|
283
|
+
position: "absolute",
|
|
284
|
+
top: 0,
|
|
285
|
+
left: 0,
|
|
286
|
+
right: 0,
|
|
287
|
+
bottom: 0,
|
|
288
|
+
overflow: "hidden",
|
|
289
|
+
zIndex: 1000
|
|
290
|
+
},
|
|
291
|
+
fullScreenContainer: {
|
|
292
|
+
position: "absolute",
|
|
293
|
+
top: 0,
|
|
294
|
+
left: 0,
|
|
295
|
+
right: 0,
|
|
296
|
+
bottom: 0,
|
|
297
|
+
backgroundColor: "white",
|
|
298
|
+
zIndex: 1000
|
|
299
|
+
},
|
|
300
|
+
inlineContainer: {
|
|
301
|
+
flex: 1,
|
|
302
|
+
backgroundColor: "white"
|
|
303
|
+
},
|
|
304
|
+
webview: {
|
|
305
|
+
flex: 1,
|
|
306
|
+
backgroundColor: "white"
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
var _default = exports.default = ChatbotSDK;
|
|
2
310
|
//# sourceMappingURL=Chatbotsdk.js.map
|