@robylon/react-native-sdk 2.0.19-staging.3 → 2.0.19-staging.31

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.
Files changed (55) hide show
  1. package/lib/commonjs/Chatbotsdk.js +11 -69
  2. package/lib/commonjs/Chatbotsdk.js.map +1 -1
  3. package/lib/commonjs/components/ChatbotWebView.js +29 -0
  4. package/lib/commonjs/components/ChatbotWebView.js.map +1 -0
  5. package/lib/commonjs/constants.js +1 -1
  6. package/lib/commonjs/constants.js.map +1 -1
  7. package/lib/commonjs/utils/systemInfo.js +1 -1
  8. package/lib/commonjs/utils/systemInfo.js.map +1 -1
  9. package/lib/commonjs/version.js +1 -1
  10. package/lib/commonjs/version.js.map +1 -1
  11. package/lib/commonjs/versions/version.dev.js +2 -0
  12. package/lib/commonjs/versions/version.dev.js.map +1 -0
  13. package/lib/commonjs/versions/version.production.js +2 -0
  14. package/lib/commonjs/versions/version.production.js.map +1 -0
  15. package/lib/commonjs/versions/version.staging.js +2 -0
  16. package/lib/commonjs/versions/version.staging.js.map +1 -0
  17. package/lib/module/Chatbotsdk.js +11 -69
  18. package/lib/module/Chatbotsdk.js.map +1 -1
  19. package/lib/module/components/ChatbotWebView.js +29 -0
  20. package/lib/module/components/ChatbotWebView.js.map +1 -0
  21. package/lib/module/constants.js +1 -1
  22. package/lib/module/constants.js.map +1 -1
  23. package/lib/module/openChatbot.js +1 -2
  24. package/lib/module/openChatbot.js.map +1 -1
  25. package/lib/module/utils/systemInfo.js +1 -1
  26. package/lib/module/utils/systemInfo.js.map +1 -1
  27. package/lib/module/version.js +1 -1
  28. package/lib/module/version.js.map +1 -1
  29. package/lib/module/versions/version.dev.js +2 -0
  30. package/lib/module/versions/version.dev.js.map +1 -0
  31. package/lib/module/versions/version.production.js +2 -0
  32. package/lib/module/versions/version.production.js.map +1 -0
  33. package/lib/module/versions/version.staging.js +2 -0
  34. package/lib/module/versions/version.staging.js.map +1 -0
  35. package/lib/typescript/Chatbotsdk.d.ts.map +1 -1
  36. package/lib/typescript/components/ChatbotWebView.d.ts +17 -0
  37. package/lib/typescript/components/ChatbotWebView.d.ts.map +1 -0
  38. package/lib/typescript/utils/systemInfo.d.ts +1 -1
  39. package/lib/typescript/version.d.ts +1 -1
  40. package/lib/typescript/version.d.ts.map +1 -1
  41. package/lib/typescript/versions/version.dev.d.ts +2 -0
  42. package/lib/typescript/versions/version.dev.d.ts.map +1 -0
  43. package/lib/typescript/versions/version.production.d.ts +2 -0
  44. package/lib/typescript/versions/version.production.d.ts.map +1 -0
  45. package/lib/typescript/versions/version.staging.d.ts +2 -0
  46. package/lib/typescript/versions/version.staging.d.ts.map +1 -0
  47. package/package.json +10 -7
  48. package/scripts/update-version.js +21 -8
  49. package/src/Chatbotsdk.tsx +101 -127
  50. package/src/components/ChatbotWebView.tsx +74 -0
  51. package/src/utils/systemInfo.ts +2 -2
  52. package/src/version.ts +1 -1
  53. package/src/versions/version.dev.ts +2 -0
  54. package/src/versions/version.production.ts +2 -0
  55. package/src/versions/version.staging.ts +2 -0
@@ -39,6 +39,8 @@ import {
39
39
  getStorageScript,
40
40
  createStorageMessage,
41
41
  } from "./utils/webViewStorage";
42
+ import ChatbotWebView from "./components/ChatbotWebView";
43
+ import { SafeAreaView } from "react-native-safe-area-context";
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
- <ErrorBoundary componentName="ChatbotWebView">
519
- <WebView
520
- ref={webViewRef}
521
- source={{ uri: constructUrl() }}
522
- onMessage={handleMessage}
523
- style={styles.webview}
524
- containerStyle={
525
- isFullScreen
526
- ? {
527
- width: screenDimensions.width,
528
- height: screenDimensions.height,
529
- }
530
- : undefined
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
- allowsInlineMediaPlayback={true}
533
- mediaPlaybackRequiresUserAction={false}
534
- allowFileAccess={false}
535
- geolocationEnabled={false}
536
- javaScriptEnabled={true}
537
- domStorageEnabled={true}
538
- cacheEnabled={true}
539
- scrollEnabled={true}
540
- bounces={false}
541
- onShouldStartLoadWithRequest={(request) => {
542
- return request.url.startsWith(BASE_CHATBOT_URL);
543
- }}
544
- startInLoadingState={isFirstLoadRef.current}
545
- onLoadEnd={() => {
546
- if (__DEV__) {
547
- enableWebViewDebug(webViewRef);
548
- }
549
- webViewRef.current?.injectJavaScript(`
550
- if (!document.querySelector('meta[name="viewport"]')) {
551
- var meta = document.createElement('meta');
552
- meta.name = 'viewport';
553
- meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
554
- document.getElementsByTagName('head')[0].appendChild(meta);
555
- }
556
-
557
- if (!document.querySelector('#injectedStyle')) {
558
- const style = document.createElement('style');
559
- style.id = 'injectedStyle';
560
- style.textContent = \`
561
- html, body, #root, #__next {
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
- </ErrorBoundary>
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: 1000,
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: 1000,
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;
@@ -10,7 +10,7 @@ interface SystemInfo {
10
10
  platform: string;
11
11
  os: string;
12
12
  browser: string;
13
- SDK_VERSION: string;
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 const SDK_VERSION = '2.0.16-staging.2';
2
+ export { SDK_VERSION } from './versions/version.staging';
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = "0.0.0-dev.0";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = "0.0.0";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = '2.0.19-staging.31';