@robylon/react-native-sdk 2.0.19-staging.3 → 2.0.19-staging.30
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/lib/commonjs/Chatbotsdk.js +11 -69
- package/lib/commonjs/Chatbotsdk.js.map +1 -1
- package/lib/commonjs/components/ChatbotWebView.js +29 -0
- package/lib/commonjs/components/ChatbotWebView.js.map +1 -0
- package/lib/commonjs/constants.js +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/utils/systemInfo.js +1 -1
- package/lib/commonjs/utils/systemInfo.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/commonjs/versions/version.dev.js +2 -0
- package/lib/commonjs/versions/version.dev.js.map +1 -0
- package/lib/commonjs/versions/version.production.js +2 -0
- package/lib/commonjs/versions/version.production.js.map +1 -0
- package/lib/commonjs/versions/version.staging.js +2 -0
- package/lib/commonjs/versions/version.staging.js.map +1 -0
- package/lib/module/Chatbotsdk.js +11 -69
- package/lib/module/Chatbotsdk.js.map +1 -1
- package/lib/module/components/ChatbotWebView.js +29 -0
- package/lib/module/components/ChatbotWebView.js.map +1 -0
- package/lib/module/constants.js +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/openChatbot.js +1 -2
- package/lib/module/openChatbot.js.map +1 -1
- package/lib/module/utils/systemInfo.js +1 -1
- package/lib/module/utils/systemInfo.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/module/versions/version.dev.js +2 -0
- package/lib/module/versions/version.dev.js.map +1 -0
- package/lib/module/versions/version.production.js +2 -0
- package/lib/module/versions/version.production.js.map +1 -0
- package/lib/module/versions/version.staging.js +2 -0
- package/lib/module/versions/version.staging.js.map +1 -0
- package/lib/typescript/Chatbotsdk.d.ts.map +1 -1
- package/lib/typescript/components/ChatbotWebView.d.ts +17 -0
- package/lib/typescript/components/ChatbotWebView.d.ts.map +1 -0
- package/lib/typescript/utils/systemInfo.d.ts +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 +2 -0
- package/lib/typescript/versions/version.dev.d.ts.map +1 -0
- package/lib/typescript/versions/version.production.d.ts +2 -0
- package/lib/typescript/versions/version.production.d.ts.map +1 -0
- package/lib/typescript/versions/version.staging.d.ts +2 -0
- package/lib/typescript/versions/version.staging.d.ts.map +1 -0
- package/package.json +10 -7
- package/scripts/update-version.js +21 -8
- package/src/Chatbotsdk.tsx +101 -127
- package/src/components/ChatbotWebView.tsx +74 -0
- package/src/utils/systemInfo.ts +2 -2
- package/src/version.ts +1 -1
- 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/src/Chatbotsdk.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
Platform,
|
|
14
14
|
StatusBar,
|
|
15
15
|
PixelRatio,
|
|
16
|
+
SafeAreaView,
|
|
16
17
|
} from "react-native";
|
|
17
18
|
import { WebView, WebViewMessageEvent } from "react-native-webview";
|
|
18
19
|
import FloatingButton from "./FloatingButton";
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
getStorageScript,
|
|
40
41
|
createStorageMessage,
|
|
41
42
|
} from "./utils/webViewStorage";
|
|
43
|
+
import ChatbotWebView from "./components/ChatbotWebView";
|
|
42
44
|
|
|
43
45
|
export interface ChatbotProps {
|
|
44
46
|
api_key: string;
|
|
@@ -384,7 +386,8 @@ const Chatbot: React.FC<InternalChatbotProps> = ({
|
|
|
384
386
|
id: api_key,
|
|
385
387
|
});
|
|
386
388
|
console.log("BASE_CHATBOT_URL SDK_VERSION", BASE_CHATBOT_URL, SDK_VERSION);
|
|
387
|
-
return `${BASE_CHATBOT_URL}?${params.toString()}`;
|
|
389
|
+
// return `${BASE_CHATBOT_URL}?${params.toString()}`;
|
|
390
|
+
return "https://demo.robylon.ai/chat/public/RG5x9i1fvk/";
|
|
388
391
|
}
|
|
389
392
|
|
|
390
393
|
// Handle opening the chatbot
|
|
@@ -488,8 +491,16 @@ const Chatbot: React.FC<InternalChatbotProps> = ({
|
|
|
488
491
|
// }
|
|
489
492
|
// }, []);
|
|
490
493
|
|
|
494
|
+
// Add userAgent configuration
|
|
495
|
+
const userAgent = Platform.select({
|
|
496
|
+
android:
|
|
497
|
+
"Mozilla/5.0 (Linux; Android 10; Android SDK built for x86) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36",
|
|
498
|
+
ios: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
|
|
499
|
+
});
|
|
500
|
+
|
|
491
501
|
return (
|
|
492
|
-
<ErrorBoundary componentName="ChatbotSDK">
|
|
502
|
+
// <ErrorBoundary componentName="ChatbotSDK">
|
|
503
|
+
<SafeAreaView style={styles.mainContainer}>
|
|
493
504
|
<View style={styles.mainContainer}>
|
|
494
505
|
{!loading && (
|
|
495
506
|
<>
|
|
@@ -507,139 +518,102 @@ const Chatbot: React.FC<InternalChatbotProps> = ({
|
|
|
507
518
|
</ErrorBoundary>
|
|
508
519
|
<View
|
|
509
520
|
style={[
|
|
510
|
-
styles.webViewWrapper,
|
|
521
|
+
// styles.webViewWrapper,
|
|
511
522
|
{ height: isWebViewVisible ? "100%" : 0 },
|
|
523
|
+
// { height: "100%" },
|
|
512
524
|
]}
|
|
513
|
-
pointerEvents={isWebViewVisible ? "auto" : "none"}
|
|
525
|
+
// pointerEvents={isWebViewVisible ? "auto" : "none"}
|
|
526
|
+
pointerEvents="auto"
|
|
514
527
|
>
|
|
515
|
-
<Animated.View
|
|
528
|
+
{/* <Animated.View
|
|
516
529
|
style={[styles.fullScreenContainer, { opacity: fadeAnim }]}
|
|
517
|
-
>
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
530
|
+
> */}
|
|
531
|
+
{/* <ErrorBoundary componentName="ChatbotWebView"> */}
|
|
532
|
+
<ChatbotWebView
|
|
533
|
+
ref={webViewRef}
|
|
534
|
+
source={{ uri: constructUrl() }}
|
|
535
|
+
onMessage={handleMessage}
|
|
536
|
+
onDebugMessage={(message) => {
|
|
537
|
+
console.log("WebView Debug:", message);
|
|
538
|
+
}}
|
|
539
|
+
style={styles.webview}
|
|
540
|
+
// containerStyle={
|
|
541
|
+
// isFullScreen
|
|
542
|
+
// ? {
|
|
543
|
+
// width: screenDimensions.width,
|
|
544
|
+
// height: screenDimensions.height,
|
|
545
|
+
// }
|
|
546
|
+
// : undefined
|
|
547
|
+
// }
|
|
548
|
+
allowsInlineMediaPlayback={true}
|
|
549
|
+
mediaPlaybackRequiresUserAction={false}
|
|
550
|
+
allowFileAccess={false}
|
|
551
|
+
geolocationEnabled={false}
|
|
552
|
+
javaScriptEnabled={true}
|
|
553
|
+
domStorageEnabled={true}
|
|
554
|
+
cacheEnabled={true}
|
|
555
|
+
scrollEnabled={true}
|
|
556
|
+
bounces={false}
|
|
557
|
+
onShouldStartLoadWithRequest={(request) => {
|
|
558
|
+
// Allow navigation only to trusted domains
|
|
559
|
+
const allowedDomains = [BASE_CHATBOT_URL, "about:blank"];
|
|
560
|
+
return allowedDomains.some((domain) =>
|
|
561
|
+
request.url.startsWith(domain)
|
|
562
|
+
);
|
|
563
|
+
}}
|
|
564
|
+
startInLoadingState={isFirstLoadRef.current}
|
|
565
|
+
onLoadEnd={() => {
|
|
566
|
+
isFirstLoadRef.current = false;
|
|
567
|
+
}}
|
|
568
|
+
onError={(syntheticEvent) => {
|
|
569
|
+
const { nativeEvent } = syntheticEvent;
|
|
570
|
+
errorTracker.trackError(
|
|
571
|
+
new Error(nativeEvent.description),
|
|
572
|
+
"ChatbotWebView",
|
|
573
|
+
{
|
|
574
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
575
|
+
context: {
|
|
576
|
+
url: nativeEvent.url,
|
|
577
|
+
code: nativeEvent.code,
|
|
578
|
+
},
|
|
531
579
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
height: 100% !important;
|
|
563
|
-
min-height: 100% !important;
|
|
564
|
-
overflow: hidden !important;
|
|
565
|
-
}
|
|
566
|
-
\`;
|
|
567
|
-
document.head.appendChild(style);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
window.sendToChatbot = function(message) {
|
|
571
|
-
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
// Only create observer if it doesn't exist
|
|
575
|
-
if (!window.closeButtonObserver) {
|
|
576
|
-
// Setup mutation observer to watch for close button
|
|
577
|
-
window.closeButtonObserver = new MutationObserver(function(mutations) {
|
|
578
|
-
const closeButton = document.querySelector('.chatbot-close-button');
|
|
579
|
-
if (closeButton && !closeButton.hasAttribute('listener-attached')) {
|
|
580
|
-
closeButton.setAttribute('listener-attached', 'true');
|
|
581
|
-
closeButton.addEventListener('click', () => {
|
|
582
|
-
try {
|
|
583
|
-
const message = { type: 'close_chatbot' };
|
|
584
|
-
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
|
585
|
-
} catch (error) {
|
|
586
|
-
console.error('Error sending close message:', error);
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
console.log('Close button listener attached');
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
// Start observing
|
|
594
|
-
window.closeButtonObserver.observe(document.body, {
|
|
595
|
-
childList: true,
|
|
596
|
-
subtree: true
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
// Initial check for existing button
|
|
600
|
-
const existingButton = document.querySelector('.chatbot-close-button');
|
|
601
|
-
if (existingButton && !existingButton.hasAttribute('listener-attached')) {
|
|
602
|
-
existingButton.setAttribute('listener-attached', 'true');
|
|
603
|
-
existingButton.addEventListener('click', () => {
|
|
604
|
-
try {
|
|
605
|
-
const message = { type: 'close_chatbot' };
|
|
606
|
-
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
|
607
|
-
} catch (error) {
|
|
608
|
-
console.error('Error sending close message:', error);
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
console.log('Close button listener attached to existing button');
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
true;
|
|
616
|
-
`);
|
|
617
|
-
isFirstLoadRef.current = false;
|
|
618
|
-
}}
|
|
619
|
-
onError={(syntheticEvent) => {
|
|
620
|
-
const { nativeEvent } = syntheticEvent;
|
|
621
|
-
errorTracker.trackError(
|
|
622
|
-
new Error(nativeEvent.description),
|
|
623
|
-
"ChatbotWebView",
|
|
624
|
-
{
|
|
625
|
-
type: ErrorTypes.RUNTIME_ERROR,
|
|
626
|
-
context: {
|
|
627
|
-
url: nativeEvent.url,
|
|
628
|
-
code: nativeEvent.code,
|
|
629
|
-
},
|
|
630
|
-
}
|
|
631
|
-
);
|
|
632
|
-
}}
|
|
633
|
-
/>
|
|
634
|
-
</ErrorBoundary>
|
|
635
|
-
</Animated.View>
|
|
580
|
+
);
|
|
581
|
+
}}
|
|
582
|
+
userAgent={userAgent}
|
|
583
|
+
originWhitelist={["*"]}
|
|
584
|
+
mixedContentMode="always"
|
|
585
|
+
onContentProcessDidTerminate={() => {
|
|
586
|
+
webViewRef.current?.reload();
|
|
587
|
+
}}
|
|
588
|
+
injectedJavaScriptBeforeContentLoaded={`
|
|
589
|
+
window.onerror = function(message, source, lineno, colno, error) {
|
|
590
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
591
|
+
type: 'ERROR',
|
|
592
|
+
data: {message, source, lineno, colno}
|
|
593
|
+
}));
|
|
594
|
+
return true;
|
|
595
|
+
};
|
|
596
|
+
true;
|
|
597
|
+
`}
|
|
598
|
+
androidLayerType="hardware"
|
|
599
|
+
overScrollMode="never"
|
|
600
|
+
textZoom={100}
|
|
601
|
+
setSupportMultipleWindows={false}
|
|
602
|
+
allowsBackForwardNavigationGestures={false}
|
|
603
|
+
useWebKit={true}
|
|
604
|
+
keyboardDisplayRequiresUserAction={false}
|
|
605
|
+
hideKeyboardAccessoryView={true}
|
|
606
|
+
applicationNameForUserAgent="ChatbotApp"
|
|
607
|
+
/>
|
|
608
|
+
{/* </ErrorBoundary> */}
|
|
609
|
+
{/* </Animated.View> */}
|
|
636
610
|
</View>
|
|
637
611
|
</>
|
|
638
612
|
)}
|
|
639
613
|
{/* <Toast message={toastMessage} visible={toastVisible} duration={10000} /> */}
|
|
640
|
-
{__DEV__ && <DebugButton />}
|
|
641
614
|
</View>
|
|
642
|
-
</
|
|
615
|
+
</SafeAreaView>
|
|
616
|
+
// </ErrorBoundary>
|
|
643
617
|
);
|
|
644
618
|
};
|
|
645
619
|
|
|
@@ -655,7 +629,7 @@ const styles = StyleSheet.create({
|
|
|
655
629
|
right: 0,
|
|
656
630
|
bottom: 0,
|
|
657
631
|
overflow: "hidden",
|
|
658
|
-
zIndex:
|
|
632
|
+
zIndex: 100,
|
|
659
633
|
},
|
|
660
634
|
fullScreenContainer: {
|
|
661
635
|
position: "absolute",
|
|
@@ -664,7 +638,7 @@ const styles = StyleSheet.create({
|
|
|
664
638
|
right: 0,
|
|
665
639
|
bottom: 0,
|
|
666
640
|
backgroundColor: "white",
|
|
667
|
-
zIndex:
|
|
641
|
+
zIndex: 100,
|
|
668
642
|
},
|
|
669
643
|
inlineContainer: {
|
|
670
644
|
flex: 1,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import { WebView, WebViewProps } from "react-native-webview";
|
|
4
|
+
|
|
5
|
+
interface ChatbotWebViewProps extends WebViewProps {
|
|
6
|
+
onDebugMessage?: (message: string) => void;
|
|
7
|
+
useWebKit?: boolean;
|
|
8
|
+
keyboardDisplayRequiresUserAction?: boolean;
|
|
9
|
+
hideKeyboardAccessoryView?: boolean;
|
|
10
|
+
applicationNameForUserAgent?: string;
|
|
11
|
+
textZoom?: number;
|
|
12
|
+
androidLayerType?: "none" | "software" | "hardware";
|
|
13
|
+
setSupportMultipleWindows?: boolean;
|
|
14
|
+
overScrollMode?: "always" | "content" | "never";
|
|
15
|
+
directionalLockEnabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ChatbotWebView = forwardRef<WebView, ChatbotWebViewProps>(
|
|
19
|
+
(props, ref) => {
|
|
20
|
+
const { onDebugMessage, ...restProps } = props;
|
|
21
|
+
|
|
22
|
+
const defaultInjectedJavaScript = `
|
|
23
|
+
// Set viewport
|
|
24
|
+
const meta = document.createElement('meta');
|
|
25
|
+
meta.name = 'viewport';
|
|
26
|
+
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover';
|
|
27
|
+
document.head.appendChild(meta);
|
|
28
|
+
|
|
29
|
+
// Basic touch handling
|
|
30
|
+
document.documentElement.style.webkitTouchCallout = 'none';
|
|
31
|
+
document.documentElement.style.webkitUserSelect = 'none';
|
|
32
|
+
document.documentElement.style.userSelect = 'none';
|
|
33
|
+
|
|
34
|
+
// Make all interactive elements clickable
|
|
35
|
+
const style = document.createElement('style');
|
|
36
|
+
style.textContent = \`
|
|
37
|
+
* { touch-action: manipulation; }
|
|
38
|
+
button, [role="button"], a, input, select, textarea {
|
|
39
|
+
cursor: pointer !important;
|
|
40
|
+
-webkit-tap-highlight-color: transparent;
|
|
41
|
+
}
|
|
42
|
+
\`;
|
|
43
|
+
document.head.appendChild(style);
|
|
44
|
+
|
|
45
|
+
true;
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<WebView
|
|
50
|
+
ref={ref}
|
|
51
|
+
{...restProps}
|
|
52
|
+
injectedJavaScript={`
|
|
53
|
+
${defaultInjectedJavaScript}
|
|
54
|
+
${props.injectedJavaScript || ""}
|
|
55
|
+
`}
|
|
56
|
+
onMessage={props.onMessage}
|
|
57
|
+
style={[{ opacity: 0.99 }, props.style]}
|
|
58
|
+
bounces={false}
|
|
59
|
+
showsHorizontalScrollIndicator={false}
|
|
60
|
+
showsVerticalScrollIndicator={false}
|
|
61
|
+
scalesPageToFit={Platform.OS === "android"}
|
|
62
|
+
automaticallyAdjustContentInsets={false}
|
|
63
|
+
contentInsetAdjustmentBehavior="never"
|
|
64
|
+
decelerationRate="normal"
|
|
65
|
+
javaScriptEnabled={true}
|
|
66
|
+
domStorageEnabled={true}
|
|
67
|
+
scrollEnabled={true}
|
|
68
|
+
directionalLockEnabled={true}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export default ChatbotWebView;
|
package/src/utils/systemInfo.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface SystemInfo {
|
|
|
10
10
|
platform: string;
|
|
11
11
|
os: string;
|
|
12
12
|
browser: string;
|
|
13
|
-
|
|
13
|
+
sdk_version: string;
|
|
14
14
|
device: string;
|
|
15
15
|
screen_size: ScreenSize;
|
|
16
16
|
}
|
|
@@ -77,7 +77,7 @@ export const getSystemInfo = (webViewSystemInfo: {
|
|
|
77
77
|
platform: Platform.OS,
|
|
78
78
|
os: webViewSystemInfo.os || Platform.OS,
|
|
79
79
|
browser: webViewSystemInfo.browser || "WebView",
|
|
80
|
-
SDK_VERSION,
|
|
80
|
+
sdk_version: SDK_VERSION,
|
|
81
81
|
device: getDeviceType(),
|
|
82
82
|
screen_size: getScreenSize(),
|
|
83
83
|
};
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not modify it manually.
|
|
2
|
-
export
|
|
2
|
+
export { SDK_VERSION } from './versions/version.staging';
|