@robylon/react-native-sdk 2.0.16-staging.2 → 2.0.16
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/babel.config.js +15 -15
- package/ios/Podfile +12 -0
- package/lib/commonjs/Chatbotsdk.js +1 -1
- package/lib/commonjs/Chatbotsdk.js.map +1 -1
- package/lib/commonjs/FloatingButton.js +1 -1
- package/lib/commonjs/FloatingButton.js.map +1 -1
- package/lib/commonjs/components/DebugButton.js +2 -0
- package/lib/commonjs/components/DebugButton.js.map +1 -0
- package/lib/commonjs/components/ErrorBoundary.js +2 -0
- package/lib/commonjs/components/ErrorBoundary.js.map +1 -0
- package/lib/commonjs/config.js +1 -1
- package/lib/commonjs/config.js.map +1 -1
- package/lib/commonjs/constants/errorConstants.js +2 -0
- package/lib/commonjs/constants/errorConstants.js.map +1 -0
- package/lib/commonjs/constants.js +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/hooks/useChatbotEvents.js +2 -0
- package/lib/commonjs/hooks/useChatbotEvents.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/ErrorTrackingService.js +2 -0
- package/lib/commonjs/services/ErrorTrackingService.js.map +1 -0
- package/lib/commonjs/types/events.js +2 -0
- package/lib/commonjs/types/events.js.map +1 -0
- package/lib/commonjs/types/react-native-flipper-performance-plugin.d.js +2 -0
- package/lib/commonjs/types/react-native-flipper-performance-plugin.d.js.map +1 -0
- package/lib/commonjs/types/react-native-globals.d.js +2 -0
- package/lib/commonjs/types/react-native-globals.d.js.map +1 -0
- package/lib/commonjs/utils/cookieUtils.js +2 -0
- package/lib/commonjs/utils/cookieUtils.js.map +1 -0
- package/lib/commonjs/utils/debugConfig.js +2 -0
- package/lib/commonjs/utils/debugConfig.js.map +1 -0
- package/lib/commonjs/utils/debugMenu.js +2 -0
- package/lib/commonjs/utils/debugMenu.js.map +1 -0
- package/lib/commonjs/utils/errorHandler.js +2 -0
- package/lib/commonjs/utils/errorHandler.js.map +1 -0
- package/lib/commonjs/utils/logger.js +2 -0
- package/lib/commonjs/utils/logger.js.map +1 -0
- package/lib/commonjs/utils/systemInfo.js +2 -0
- package/lib/commonjs/utils/systemInfo.js.map +1 -0
- package/lib/commonjs/utils/webViewStorage.js +2 -0
- package/lib/commonjs/utils/webViewStorage.js.map +1 -0
- package/lib/commonjs/version.js +2 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/Chatbotsdk.js +1 -1
- package/lib/module/Chatbotsdk.js.map +1 -1
- package/lib/module/FloatingButton.js +1 -1
- package/lib/module/FloatingButton.js.map +1 -1
- package/lib/module/components/DebugButton.js +2 -0
- package/lib/module/components/DebugButton.js.map +1 -0
- package/lib/module/components/ErrorBoundary.js +2 -0
- package/lib/module/components/ErrorBoundary.js.map +1 -0
- package/lib/module/config.js +1 -1
- package/lib/module/config.js.map +1 -1
- package/lib/module/constants/errorConstants.js +2 -0
- package/lib/module/constants/errorConstants.js.map +1 -0
- package/lib/module/constants.js +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/hooks/useChatbotEvents.js +2 -0
- package/lib/module/hooks/useChatbotEvents.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/ErrorTrackingService.js +2 -0
- package/lib/module/services/ErrorTrackingService.js.map +1 -0
- package/lib/module/types/events.js +2 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/react-native-flipper-performance-plugin.d.js +2 -0
- package/lib/module/types/react-native-flipper-performance-plugin.d.js.map +1 -0
- package/lib/module/types/react-native-globals.d.js +2 -0
- package/lib/module/types/react-native-globals.d.js.map +1 -0
- package/lib/module/utils/cookieUtils.js +2 -0
- package/lib/module/utils/cookieUtils.js.map +1 -0
- package/lib/module/utils/debugConfig.js +2 -0
- package/lib/module/utils/debugConfig.js.map +1 -0
- package/lib/module/utils/debugMenu.js +2 -0
- package/lib/module/utils/debugMenu.js.map +1 -0
- package/lib/module/utils/errorHandler.js +2 -0
- package/lib/module/utils/errorHandler.js.map +1 -0
- package/lib/module/utils/logger.js +2 -0
- package/lib/module/utils/logger.js.map +1 -0
- package/lib/module/utils/systemInfo.js +2 -0
- package/lib/module/utils/systemInfo.js.map +1 -0
- package/lib/module/utils/webViewStorage.js +2 -0
- package/lib/module/utils/webViewStorage.js.map +1 -0
- package/lib/module/version.js +2 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/Chatbotsdk.d.ts +9 -10
- package/lib/typescript/Chatbotsdk.d.ts.map +1 -1
- package/lib/typescript/FloatingButton.d.ts.map +1 -1
- package/lib/typescript/components/DebugButton.d.ts +4 -0
- package/lib/typescript/components/DebugButton.d.ts.map +1 -0
- package/lib/typescript/components/ErrorBoundary.d.ts +16 -0
- package/lib/typescript/components/ErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/constants/errorConstants.d.ts +18 -0
- package/lib/typescript/constants/errorConstants.d.ts.map +1 -0
- package/lib/typescript/hooks/useChatbotEvents.d.ts +17 -0
- package/lib/typescript/hooks/useChatbotEvents.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/ErrorTrackingService.d.ts +34 -0
- package/lib/typescript/services/ErrorTrackingService.d.ts.map +1 -0
- package/lib/typescript/types/events.d.ts +22 -0
- package/lib/typescript/types/events.d.ts.map +1 -0
- package/lib/typescript/utils/cookieUtils.d.ts +2 -0
- package/lib/typescript/utils/cookieUtils.d.ts.map +1 -0
- package/lib/typescript/utils/debugConfig.d.ts +8 -0
- package/lib/typescript/utils/debugConfig.d.ts.map +1 -0
- package/lib/typescript/utils/debugMenu.d.ts +3 -0
- package/lib/typescript/utils/debugMenu.d.ts.map +1 -0
- package/lib/typescript/utils/errorHandler.d.ts +2 -0
- package/lib/typescript/utils/errorHandler.d.ts.map +1 -0
- package/lib/typescript/utils/logger.d.ts +7 -0
- package/lib/typescript/utils/logger.d.ts.map +1 -0
- package/lib/typescript/utils/systemInfo.d.ts +19 -0
- package/lib/typescript/utils/systemInfo.d.ts.map +1 -0
- package/lib/typescript/utils/webViewStorage.d.ts +16 -0
- package/lib/typescript/utils/webViewStorage.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +8 -2
- package/scripts/generate-version.js +9 -0
- package/src/ChatbotWebview.tsx +0 -44
- package/src/Chatbotsdk.tsx +0 -399
- package/src/FloatingButton.tsx +0 -57
- package/src/LoadingIndicator.tsx +0 -11
- package/src/Toast.tsx +0 -65
- package/src/config.ts +0 -4
- package/src/constants.ts +0 -4
- package/src/global.d.ts +0 -11
- package/src/index.tsx +0 -2
- package/src/openChatbot.ts +0 -11
- package/src/openChatbot.tsx +0 -0
package/src/Chatbotsdk.tsx
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef, useMemo } from "react";
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
StyleSheet,
|
|
5
|
-
Animated,
|
|
6
|
-
Dimensions,
|
|
7
|
-
Platform,
|
|
8
|
-
StatusBar,
|
|
9
|
-
} from "react-native";
|
|
10
|
-
import { WebView, WebViewMessageEvent } from "react-native-webview";
|
|
11
|
-
import FloatingButton from "./FloatingButton";
|
|
12
|
-
import { API_URL, BASE_CHATBOT_URL } from "./constants";
|
|
13
|
-
|
|
14
|
-
interface ChatbotSDKProps {
|
|
15
|
-
api_key: string;
|
|
16
|
-
user_id?: string;
|
|
17
|
-
user_token?: string;
|
|
18
|
-
additional_params?: Record<string, string>;
|
|
19
|
-
show_floating_button?: boolean;
|
|
20
|
-
onMessage?: (message: any) => void;
|
|
21
|
-
isFullScreen?: boolean;
|
|
22
|
-
enableAnimation?: boolean;
|
|
23
|
-
onOpen?: () => void;
|
|
24
|
-
onClose?: () => void;
|
|
25
|
-
user_info?: {
|
|
26
|
-
name?: string;
|
|
27
|
-
email?: string;
|
|
28
|
-
mobile?: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ChatbotMessage {
|
|
33
|
-
type: string;
|
|
34
|
-
data?: any;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ChatbotConfig {
|
|
38
|
-
brand_color: string;
|
|
39
|
-
image_url: string;
|
|
40
|
-
welcome_message: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const ChatbotSDK: React.FC<ChatbotSDKProps> = ({
|
|
44
|
-
api_key,
|
|
45
|
-
user_id,
|
|
46
|
-
user_token,
|
|
47
|
-
additional_params = {},
|
|
48
|
-
show_floating_button = true,
|
|
49
|
-
onMessage,
|
|
50
|
-
isFullScreen = true,
|
|
51
|
-
enableAnimation = true,
|
|
52
|
-
onOpen,
|
|
53
|
-
onClose,
|
|
54
|
-
user_info,
|
|
55
|
-
}) => {
|
|
56
|
-
const [isWebViewVisible, setIsWebViewVisible] = useState(false);
|
|
57
|
-
const [chatbotConfig, setChatbotConfig] = useState<ChatbotConfig | null>(
|
|
58
|
-
null
|
|
59
|
-
);
|
|
60
|
-
const [loading, setLoading] = useState(true);
|
|
61
|
-
const webViewRef = useRef<WebView>(null);
|
|
62
|
-
const fadeAnim = useRef(new Animated.Value(0)).current;
|
|
63
|
-
const isFirstLoadRef = useRef(true);
|
|
64
|
-
const [toastVisible, setToastVisible] = useState(false);
|
|
65
|
-
const [toastMessage, setToastMessage] = useState("");
|
|
66
|
-
const webViewUrl = useMemo(
|
|
67
|
-
() => constructUrl(),
|
|
68
|
-
[api_key, user_id, additional_params]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const stableAdditionalParams = useMemo(
|
|
72
|
-
() => additional_params,
|
|
73
|
-
[JSON.stringify(additional_params)]
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const triggerAppInit = () => {
|
|
77
|
-
if (webViewRef.current) {
|
|
78
|
-
webViewRef.current.injectJavaScript(`
|
|
79
|
-
// Trigger APP_READY equivalent
|
|
80
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'APP_READY' }));
|
|
81
|
-
true;
|
|
82
|
-
`);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
const fetchChatbotConfig = async () => {
|
|
88
|
-
try {
|
|
89
|
-
const endpointUrl = `${API_URL}/chat/chatbot/get/`;
|
|
90
|
-
const payload = {
|
|
91
|
-
client_user_id: user_id,
|
|
92
|
-
org_id: api_key,
|
|
93
|
-
token: user_token,
|
|
94
|
-
extra_info: stableAdditionalParams,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// setToastMessage(endpointUrl + " : " + BASE_CHATBOT_URL);
|
|
98
|
-
// setToastVisible(true);
|
|
99
|
-
|
|
100
|
-
const response = await fetch(endpointUrl, {
|
|
101
|
-
method: "POST",
|
|
102
|
-
headers: {
|
|
103
|
-
"Content-Type": "application/json",
|
|
104
|
-
},
|
|
105
|
-
body: JSON.stringify(payload),
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
throw new Error("Failed to fetch chatbot configuration");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const data = await response.json();
|
|
113
|
-
const orgInfo = data?.user?.org_info;
|
|
114
|
-
|
|
115
|
-
if (orgInfo) {
|
|
116
|
-
setChatbotConfig({
|
|
117
|
-
brand_color: orgInfo?.config?.brand_colour || "#007AFF",
|
|
118
|
-
image_url: orgInfo?.brand_config?.launcher_logo_url || "",
|
|
119
|
-
welcome_message: orgInfo?.config?.welcome_message || "",
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error("Error fetching chatbot configuration:", error);
|
|
124
|
-
} finally {
|
|
125
|
-
setLoading(false);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
if (api_key && user_id) {
|
|
130
|
-
fetchChatbotConfig();
|
|
131
|
-
}
|
|
132
|
-
}, [api_key, user_id, user_token, stableAdditionalParams]);
|
|
133
|
-
|
|
134
|
-
function constructUrl(): string {
|
|
135
|
-
if (!user_id) return "";
|
|
136
|
-
const params = new URLSearchParams({
|
|
137
|
-
id: api_key,
|
|
138
|
-
user_id,
|
|
139
|
-
...additional_params,
|
|
140
|
-
});
|
|
141
|
-
console.log("BASE_CHATBOT_URL", BASE_CHATBOT_URL);
|
|
142
|
-
return `${BASE_CHATBOT_URL}?${params.toString()}`;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const openWebView = () => {
|
|
146
|
-
setIsWebViewVisible(true);
|
|
147
|
-
if (enableAnimation) {
|
|
148
|
-
Animated.timing(fadeAnim, {
|
|
149
|
-
toValue: 1,
|
|
150
|
-
duration: 250,
|
|
151
|
-
useNativeDriver: true,
|
|
152
|
-
}).start(() => {
|
|
153
|
-
onOpen?.();
|
|
154
|
-
if (!isFirstLoadRef.current) {
|
|
155
|
-
// If not first load, manually trigger initialization
|
|
156
|
-
setTimeout(triggerAppInit, 100);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
} else {
|
|
160
|
-
fadeAnim.setValue(1);
|
|
161
|
-
requestAnimationFrame(() => {
|
|
162
|
-
onOpen?.();
|
|
163
|
-
if (!isFirstLoadRef.current) {
|
|
164
|
-
setTimeout(triggerAppInit, 100);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const closeWebView = () => {
|
|
171
|
-
if (webViewRef.current) {
|
|
172
|
-
console.log("closeWebView");
|
|
173
|
-
webViewRef.current.postMessage(
|
|
174
|
-
JSON.stringify({
|
|
175
|
-
name: "closeFrame",
|
|
176
|
-
domain: "app-domain.com",
|
|
177
|
-
})
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const complete = () => {
|
|
182
|
-
setIsWebViewVisible(false);
|
|
183
|
-
onClose?.();
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
if (enableAnimation) {
|
|
187
|
-
Animated.timing(fadeAnim, {
|
|
188
|
-
toValue: 0,
|
|
189
|
-
duration: 200,
|
|
190
|
-
useNativeDriver: true,
|
|
191
|
-
}).start(complete);
|
|
192
|
-
} else {
|
|
193
|
-
fadeAnim.setValue(0);
|
|
194
|
-
requestAnimationFrame(complete);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const handleMessage = (event: WebViewMessageEvent) => {
|
|
199
|
-
const { data } = event.nativeEvent;
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
const parsedData: ChatbotMessage = JSON.parse(data);
|
|
203
|
-
|
|
204
|
-
if (parsedData.type === "APP_READY") {
|
|
205
|
-
console.log("APP_READY", webViewRef.current && isWebViewVisible);
|
|
206
|
-
if (webViewRef.current && isWebViewVisible) {
|
|
207
|
-
webViewRef.current.injectJavaScript(`
|
|
208
|
-
window.postMessage(${JSON.stringify({
|
|
209
|
-
name: "openFrame",
|
|
210
|
-
domain: "app-domain.com",
|
|
211
|
-
})}, '*');
|
|
212
|
-
window.postMessage(${JSON.stringify({
|
|
213
|
-
name: "registerUserId",
|
|
214
|
-
action: "registerUserId",
|
|
215
|
-
domain: "app-domain.com",
|
|
216
|
-
data: {
|
|
217
|
-
userId: `${user_id}`,
|
|
218
|
-
token: `${user_token}`,
|
|
219
|
-
user_info: {
|
|
220
|
-
...user_info,
|
|
221
|
-
platform: Platform.OS,
|
|
222
|
-
SDK_VERSION: "${SDK_VERSION}",
|
|
223
|
-
OS: Platform.OS,
|
|
224
|
-
browser: Platform.OS,
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
})}, '*');
|
|
228
|
-
`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (typeof parsedData !== "object" || !parsedData.type) {
|
|
233
|
-
console.warn("Invalid message structure");
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
switch (parsedData.type) {
|
|
238
|
-
case "close_chatbot":
|
|
239
|
-
closeWebView();
|
|
240
|
-
break;
|
|
241
|
-
default:
|
|
242
|
-
if (onMessage) onMessage(parsedData);
|
|
243
|
-
}
|
|
244
|
-
} catch (error) {
|
|
245
|
-
console.error("Failed to parse or process WebView message:", error);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const getScreenDimensions = () => {
|
|
250
|
-
const windowHeight = Dimensions.get("window").height;
|
|
251
|
-
const windowWidth = Dimensions.get("window").width;
|
|
252
|
-
const statusBarHeight =
|
|
253
|
-
Platform.OS === "ios" ? 0 : StatusBar.currentHeight || 0;
|
|
254
|
-
|
|
255
|
-
return {
|
|
256
|
-
height: windowHeight - statusBarHeight,
|
|
257
|
-
width: windowWidth,
|
|
258
|
-
};
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const screenDimensions = getScreenDimensions();
|
|
262
|
-
|
|
263
|
-
return (
|
|
264
|
-
<View style={styles.mainContainer}>
|
|
265
|
-
{!loading && (
|
|
266
|
-
<>
|
|
267
|
-
{show_floating_button && api_key && chatbotConfig && (
|
|
268
|
-
<FloatingButton
|
|
269
|
-
onPress={openWebView}
|
|
270
|
-
brandColor={chatbotConfig.brand_color}
|
|
271
|
-
imageUrl={chatbotConfig.image_url}
|
|
272
|
-
/>
|
|
273
|
-
)}
|
|
274
|
-
<View
|
|
275
|
-
style={[
|
|
276
|
-
styles.webViewWrapper,
|
|
277
|
-
{ height: isWebViewVisible ? "100%" : 0 },
|
|
278
|
-
]}
|
|
279
|
-
pointerEvents={isWebViewVisible ? "auto" : "none"}
|
|
280
|
-
>
|
|
281
|
-
<Animated.View
|
|
282
|
-
style={[
|
|
283
|
-
isFullScreen
|
|
284
|
-
? styles.fullScreenContainer
|
|
285
|
-
: styles.inlineContainer,
|
|
286
|
-
{ opacity: fadeAnim },
|
|
287
|
-
]}
|
|
288
|
-
>
|
|
289
|
-
<WebView
|
|
290
|
-
ref={webViewRef}
|
|
291
|
-
source={{ uri: webViewUrl }}
|
|
292
|
-
onMessage={handleMessage}
|
|
293
|
-
style={styles.webview}
|
|
294
|
-
containerStyle={
|
|
295
|
-
isFullScreen
|
|
296
|
-
? {
|
|
297
|
-
width: screenDimensions.width,
|
|
298
|
-
height: screenDimensions.height,
|
|
299
|
-
}
|
|
300
|
-
: undefined
|
|
301
|
-
}
|
|
302
|
-
allowsInlineMediaPlayback={true}
|
|
303
|
-
mediaPlaybackRequiresUserAction={false}
|
|
304
|
-
allowFileAccess={false}
|
|
305
|
-
geolocationEnabled={false}
|
|
306
|
-
javaScriptEnabled={true}
|
|
307
|
-
domStorageEnabled={true}
|
|
308
|
-
cacheEnabled={true}
|
|
309
|
-
scrollEnabled={true}
|
|
310
|
-
bounces={false}
|
|
311
|
-
onShouldStartLoadWithRequest={(request) => {
|
|
312
|
-
return request.url.startsWith(BASE_CHATBOT_URL);
|
|
313
|
-
}}
|
|
314
|
-
startInLoadingState={isFirstLoadRef.current}
|
|
315
|
-
onLoadEnd={() => {
|
|
316
|
-
webViewRef.current?.injectJavaScript(`
|
|
317
|
-
if (!document.querySelector('meta[name="viewport"]')) {
|
|
318
|
-
var meta = document.createElement('meta');
|
|
319
|
-
meta.name = 'viewport';
|
|
320
|
-
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
|
|
321
|
-
document.getElementsByTagName('head')[0].appendChild(meta);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (!document.querySelector('#injectedStyle')) {
|
|
325
|
-
const style = document.createElement('style');
|
|
326
|
-
style.id = 'injectedStyle';
|
|
327
|
-
style.textContent = \`
|
|
328
|
-
html, body, #root, #__next {
|
|
329
|
-
height: 100% !important;
|
|
330
|
-
min-height: 100% !important;
|
|
331
|
-
overflow: hidden !important;
|
|
332
|
-
}
|
|
333
|
-
\`;
|
|
334
|
-
document.head.appendChild(style);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
window.sendToChatbot = function(message) {
|
|
338
|
-
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
var closeButton = document.querySelector('.chatbot-close-button');
|
|
342
|
-
if (closeButton) {
|
|
343
|
-
closeButton.addEventListener('click', () => {
|
|
344
|
-
window.sendToChatbot({ type: 'close_chatbot' });
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
true;
|
|
349
|
-
`);
|
|
350
|
-
isFirstLoadRef.current = false;
|
|
351
|
-
}}
|
|
352
|
-
onError={(syntheticEvent) => {
|
|
353
|
-
const { nativeEvent } = syntheticEvent;
|
|
354
|
-
console.warn("WebView error:", nativeEvent);
|
|
355
|
-
}}
|
|
356
|
-
/>
|
|
357
|
-
</Animated.View>
|
|
358
|
-
</View>
|
|
359
|
-
</>
|
|
360
|
-
)}
|
|
361
|
-
{/* <Toast message={toastMessage} visible={toastVisible} duration={10000} /> */}
|
|
362
|
-
</View>
|
|
363
|
-
);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
const styles = StyleSheet.create({
|
|
367
|
-
mainContainer: {
|
|
368
|
-
flex: 1,
|
|
369
|
-
position: "relative",
|
|
370
|
-
},
|
|
371
|
-
webViewWrapper: {
|
|
372
|
-
position: "absolute",
|
|
373
|
-
top: 0,
|
|
374
|
-
left: 0,
|
|
375
|
-
right: 0,
|
|
376
|
-
bottom: 0,
|
|
377
|
-
overflow: "hidden",
|
|
378
|
-
zIndex: 1000,
|
|
379
|
-
},
|
|
380
|
-
fullScreenContainer: {
|
|
381
|
-
position: "absolute",
|
|
382
|
-
top: 0,
|
|
383
|
-
left: 0,
|
|
384
|
-
right: 0,
|
|
385
|
-
bottom: 0,
|
|
386
|
-
backgroundColor: "white",
|
|
387
|
-
zIndex: 1000,
|
|
388
|
-
},
|
|
389
|
-
inlineContainer: {
|
|
390
|
-
flex: 1,
|
|
391
|
-
backgroundColor: "white",
|
|
392
|
-
},
|
|
393
|
-
webview: {
|
|
394
|
-
flex: 1,
|
|
395
|
-
backgroundColor: "white",
|
|
396
|
-
},
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
export default ChatbotSDK;
|
package/src/FloatingButton.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { TouchableOpacity, StyleSheet, Text, Image } from "react-native";
|
|
3
|
-
|
|
4
|
-
interface FloatingButtonProps {
|
|
5
|
-
onPress: () => void;
|
|
6
|
-
brandColor?: string; // For dynamic branding
|
|
7
|
-
imageUrl?: string; // For brand logo or icon
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
11
|
-
onPress,
|
|
12
|
-
brandColor = "#007AFF", // Default color
|
|
13
|
-
imageUrl,
|
|
14
|
-
}) => {
|
|
15
|
-
return (
|
|
16
|
-
<TouchableOpacity
|
|
17
|
-
style={[styles.button, { backgroundColor: brandColor }]}
|
|
18
|
-
onPress={onPress}
|
|
19
|
-
>
|
|
20
|
-
{imageUrl ? (
|
|
21
|
-
<Image source={{ uri: imageUrl }} style={styles.buttonImage} />
|
|
22
|
-
) : (
|
|
23
|
-
<Text style={styles.buttonText}>Chat</Text>
|
|
24
|
-
)}
|
|
25
|
-
</TouchableOpacity>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const styles = StyleSheet.create({
|
|
30
|
-
button: {
|
|
31
|
-
position: "absolute",
|
|
32
|
-
bottom: 20,
|
|
33
|
-
right: 20,
|
|
34
|
-
borderRadius: 24,
|
|
35
|
-
width: 48,
|
|
36
|
-
height: 48,
|
|
37
|
-
justifyContent: "center",
|
|
38
|
-
alignItems: "center",
|
|
39
|
-
elevation: 5,
|
|
40
|
-
shadowColor: "#000",
|
|
41
|
-
shadowOffset: { width: 0, height: 2 },
|
|
42
|
-
shadowOpacity: 0.25,
|
|
43
|
-
shadowRadius: 3.84,
|
|
44
|
-
},
|
|
45
|
-
buttonText: {
|
|
46
|
-
color: "white",
|
|
47
|
-
fontSize: 16,
|
|
48
|
-
fontWeight: "bold",
|
|
49
|
-
},
|
|
50
|
-
buttonImage: {
|
|
51
|
-
width: 48,
|
|
52
|
-
height: 48,
|
|
53
|
-
borderRadius: 24,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export default FloatingButton;
|
package/src/LoadingIndicator.tsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { View, ActivityIndicator } from "react-native";
|
|
3
|
-
import { WebView } from "react-native-webview";
|
|
4
|
-
|
|
5
|
-
const LoadingIndicator: React.FC = () => (
|
|
6
|
-
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
|
|
7
|
-
<ActivityIndicator size="large" color="#0000ff" />
|
|
8
|
-
</View>
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
export default LoadingIndicator;
|
package/src/Toast.tsx
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
2
|
-
import { View, Text, StyleSheet, Animated } from "react-native";
|
|
3
|
-
|
|
4
|
-
const Toast = ({
|
|
5
|
-
message,
|
|
6
|
-
visible,
|
|
7
|
-
duration = 3000,
|
|
8
|
-
}: {
|
|
9
|
-
message: any;
|
|
10
|
-
visible: boolean;
|
|
11
|
-
duration?: number;
|
|
12
|
-
}) => {
|
|
13
|
-
const [fadeAnim] = useState(new Animated.Value(0));
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (visible) {
|
|
17
|
-
// Fade in the toast
|
|
18
|
-
Animated.timing(fadeAnim, {
|
|
19
|
-
toValue: 1,
|
|
20
|
-
duration: 300,
|
|
21
|
-
useNativeDriver: true,
|
|
22
|
-
}).start(() => {
|
|
23
|
-
// Auto-hide after duration
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
Animated.timing(fadeAnim, {
|
|
26
|
-
toValue: 0,
|
|
27
|
-
duration: 300,
|
|
28
|
-
useNativeDriver: true,
|
|
29
|
-
}).start();
|
|
30
|
-
}, duration);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}, [visible]);
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Animated.View
|
|
37
|
-
style={[
|
|
38
|
-
styles.toastContainer,
|
|
39
|
-
{ opacity: fadeAnim, display: visible ? "flex" : "none" },
|
|
40
|
-
]}
|
|
41
|
-
>
|
|
42
|
-
<Text style={styles.toastText}>{message}</Text>
|
|
43
|
-
</Animated.View>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const styles = StyleSheet.create({
|
|
48
|
-
toastContainer: {
|
|
49
|
-
position: "absolute",
|
|
50
|
-
bottom: 50,
|
|
51
|
-
left: "10%",
|
|
52
|
-
right: "10%",
|
|
53
|
-
backgroundColor: "rgba(0, 0, 0, 0.8)",
|
|
54
|
-
padding: 10,
|
|
55
|
-
borderRadius: 5,
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
justifyContent: "center",
|
|
58
|
-
},
|
|
59
|
-
toastText: {
|
|
60
|
-
color: "#fff",
|
|
61
|
-
textAlign: "center",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
export default Toast;
|
package/src/config.ts
DELETED
package/src/constants.ts
DELETED
package/src/global.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// declare module "react-native" {
|
|
2
|
-
// export const View: any;
|
|
3
|
-
// export const ActivityIndicator: any;
|
|
4
|
-
// export const Linking: any;
|
|
5
|
-
// // Add other React Native exports as needed
|
|
6
|
-
// }
|
|
7
|
-
|
|
8
|
-
declare module "*.json" {
|
|
9
|
-
const value: any;
|
|
10
|
-
export default value;
|
|
11
|
-
}
|
package/src/index.tsx
DELETED
package/src/openChatbot.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Linking } from "react-native";
|
|
2
|
-
import { BASE_CHATBOT_URL } from "./constants";
|
|
3
|
-
|
|
4
|
-
export const openChatbot = (
|
|
5
|
-
chatbotId: string,
|
|
6
|
-
additionalParams: Record<string, string> = {}
|
|
7
|
-
): void => {
|
|
8
|
-
const params = new URLSearchParams({ id: chatbotId, ...additionalParams });
|
|
9
|
-
const url = `${BASE_CHATBOT_URL}?${params.toString()}`;
|
|
10
|
-
Linking.openURL(url);
|
|
11
|
-
};
|
package/src/openChatbot.tsx
DELETED
|
File without changes
|