srs-heritage-chatbot 1.0.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.
Files changed (187) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +194 -0
  3. package/lib/commonjs/assets/chat-icon-mobile.svg +1 -0
  4. package/lib/commonjs/assets/heritage.png +0 -0
  5. package/lib/commonjs/assets/posiden.svg +51 -0
  6. package/lib/commonjs/components/LoadingTips.js +104 -0
  7. package/lib/commonjs/components/LoadingTips.js.map +1 -0
  8. package/lib/commonjs/components/email.js +461 -0
  9. package/lib/commonjs/components/email.js.map +1 -0
  10. package/lib/commonjs/components/feedback.js +114 -0
  11. package/lib/commonjs/components/feedback.js.map +1 -0
  12. package/lib/commonjs/components/header.js +126 -0
  13. package/lib/commonjs/components/header.js.map +1 -0
  14. package/lib/commonjs/components/input.js +144 -0
  15. package/lib/commonjs/components/input.js.map +1 -0
  16. package/lib/commonjs/components/productCard.js +688 -0
  17. package/lib/commonjs/components/productCard.js.map +1 -0
  18. package/lib/commonjs/components/progressCircle.js +99 -0
  19. package/lib/commonjs/components/progressCircle.js.map +1 -0
  20. package/lib/commonjs/components/testing.js +74 -0
  21. package/lib/commonjs/components/testing.js.map +1 -0
  22. package/lib/commonjs/components/voice.js +184 -0
  23. package/lib/commonjs/components/voice.js.map +1 -0
  24. package/lib/commonjs/components/welcomeButton.js +149 -0
  25. package/lib/commonjs/components/welcomeButton.js.map +1 -0
  26. package/lib/commonjs/components/welcomeInput.js +137 -0
  27. package/lib/commonjs/components/welcomeInput.js.map +1 -0
  28. package/lib/commonjs/contexts/AppContext.js +552 -0
  29. package/lib/commonjs/contexts/AppContext.js.map +1 -0
  30. package/lib/commonjs/hooks/Stream.js +599 -0
  31. package/lib/commonjs/hooks/Stream.js.map +1 -0
  32. package/lib/commonjs/hooks/useAsyncStorage.js +36 -0
  33. package/lib/commonjs/hooks/useAsyncStorage.js.map +1 -0
  34. package/lib/commonjs/index.js +44 -0
  35. package/lib/commonjs/index.js.map +1 -0
  36. package/lib/commonjs/layout/disclaimer.js +208 -0
  37. package/lib/commonjs/layout/disclaimer.js.map +1 -0
  38. package/lib/commonjs/layout/ex.js +254 -0
  39. package/lib/commonjs/layout/ex.js.map +1 -0
  40. package/lib/commonjs/layout/icon.js +118 -0
  41. package/lib/commonjs/layout/icon.js.map +1 -0
  42. package/lib/commonjs/layout/layout.js +168 -0
  43. package/lib/commonjs/layout/layout.js.map +1 -0
  44. package/lib/commonjs/layout/welcome.js +160 -0
  45. package/lib/commonjs/layout/welcome.js.map +1 -0
  46. package/lib/commonjs/layout/window.js +396 -0
  47. package/lib/commonjs/layout/window.js.map +1 -0
  48. package/lib/commonjs/utils/audioRecorder.js +412 -0
  49. package/lib/commonjs/utils/audioRecorder.js.map +1 -0
  50. package/lib/commonjs/utils/cloudinary.js +69 -0
  51. package/lib/commonjs/utils/cloudinary.js.map +1 -0
  52. package/lib/commonjs/utils/storage.js +76 -0
  53. package/lib/commonjs/utils/storage.js.map +1 -0
  54. package/lib/commonjs/utils/textToSpeech.js +53 -0
  55. package/lib/commonjs/utils/textToSpeech.js.map +1 -0
  56. package/lib/module/assets/chat-icon-mobile.svg +1 -0
  57. package/lib/module/assets/heritage.png +0 -0
  58. package/lib/module/assets/posiden.svg +51 -0
  59. package/lib/module/components/LoadingTips.js +95 -0
  60. package/lib/module/components/LoadingTips.js.map +1 -0
  61. package/lib/module/components/email.js +452 -0
  62. package/lib/module/components/email.js.map +1 -0
  63. package/lib/module/components/feedback.js +105 -0
  64. package/lib/module/components/feedback.js.map +1 -0
  65. package/lib/module/components/header.js +117 -0
  66. package/lib/module/components/header.js.map +1 -0
  67. package/lib/module/components/input.js +135 -0
  68. package/lib/module/components/input.js.map +1 -0
  69. package/lib/module/components/productCard.js +679 -0
  70. package/lib/module/components/productCard.js.map +1 -0
  71. package/lib/module/components/progressCircle.js +91 -0
  72. package/lib/module/components/progressCircle.js.map +1 -0
  73. package/lib/module/components/testing.js +66 -0
  74. package/lib/module/components/testing.js.map +1 -0
  75. package/lib/module/components/voice.js +175 -0
  76. package/lib/module/components/voice.js.map +1 -0
  77. package/lib/module/components/welcomeButton.js +140 -0
  78. package/lib/module/components/welcomeButton.js.map +1 -0
  79. package/lib/module/components/welcomeInput.js +128 -0
  80. package/lib/module/components/welcomeInput.js.map +1 -0
  81. package/lib/module/contexts/AppContext.js +542 -0
  82. package/lib/module/contexts/AppContext.js.map +1 -0
  83. package/lib/module/hooks/Stream.js +592 -0
  84. package/lib/module/hooks/Stream.js.map +1 -0
  85. package/lib/module/hooks/useAsyncStorage.js +29 -0
  86. package/lib/module/hooks/useAsyncStorage.js.map +1 -0
  87. package/lib/module/index.js +36 -0
  88. package/lib/module/index.js.map +1 -0
  89. package/lib/module/layout/disclaimer.js +199 -0
  90. package/lib/module/layout/disclaimer.js.map +1 -0
  91. package/lib/module/layout/ex.js +253 -0
  92. package/lib/module/layout/ex.js.map +1 -0
  93. package/lib/module/layout/icon.js +108 -0
  94. package/lib/module/layout/icon.js.map +1 -0
  95. package/lib/module/layout/layout.js +160 -0
  96. package/lib/module/layout/layout.js.map +1 -0
  97. package/lib/module/layout/welcome.js +150 -0
  98. package/lib/module/layout/welcome.js.map +1 -0
  99. package/lib/module/layout/window.js +387 -0
  100. package/lib/module/layout/window.js.map +1 -0
  101. package/lib/module/utils/audioRecorder.js +398 -0
  102. package/lib/module/utils/audioRecorder.js.map +1 -0
  103. package/lib/module/utils/cloudinary.js +61 -0
  104. package/lib/module/utils/cloudinary.js.map +1 -0
  105. package/lib/module/utils/storage.js +67 -0
  106. package/lib/module/utils/storage.js.map +1 -0
  107. package/lib/module/utils/textToSpeech.js +43 -0
  108. package/lib/module/utils/textToSpeech.js.map +1 -0
  109. package/lib/typescript/components/LoadingTips.d.ts +3 -0
  110. package/lib/typescript/components/LoadingTips.d.ts.map +1 -0
  111. package/lib/typescript/components/email.d.ts +6 -0
  112. package/lib/typescript/components/email.d.ts.map +1 -0
  113. package/lib/typescript/components/feedback.d.ts +6 -0
  114. package/lib/typescript/components/feedback.d.ts.map +1 -0
  115. package/lib/typescript/components/header.d.ts +3 -0
  116. package/lib/typescript/components/header.d.ts.map +1 -0
  117. package/lib/typescript/components/input.d.ts +6 -0
  118. package/lib/typescript/components/input.d.ts.map +1 -0
  119. package/lib/typescript/components/productCard.d.ts +7 -0
  120. package/lib/typescript/components/productCard.d.ts.map +1 -0
  121. package/lib/typescript/components/progressCircle.d.ts +3 -0
  122. package/lib/typescript/components/progressCircle.d.ts.map +1 -0
  123. package/lib/typescript/components/testing.d.ts +6 -0
  124. package/lib/typescript/components/testing.d.ts.map +1 -0
  125. package/lib/typescript/components/voice.d.ts +5 -0
  126. package/lib/typescript/components/voice.d.ts.map +1 -0
  127. package/lib/typescript/components/welcomeButton.d.ts +4 -0
  128. package/lib/typescript/components/welcomeButton.d.ts.map +1 -0
  129. package/lib/typescript/components/welcomeInput.d.ts +6 -0
  130. package/lib/typescript/components/welcomeInput.d.ts.map +1 -0
  131. package/lib/typescript/contexts/AppContext.d.ts +10 -0
  132. package/lib/typescript/contexts/AppContext.d.ts.map +1 -0
  133. package/lib/typescript/hooks/Stream.d.ts +2 -0
  134. package/lib/typescript/hooks/Stream.d.ts.map +1 -0
  135. package/lib/typescript/hooks/useAsyncStorage.d.ts +2 -0
  136. package/lib/typescript/hooks/useAsyncStorage.d.ts.map +1 -0
  137. package/lib/typescript/index.d.ts +8 -0
  138. package/lib/typescript/index.d.ts.map +1 -0
  139. package/lib/typescript/layout/disclaimer.d.ts +5 -0
  140. package/lib/typescript/layout/disclaimer.d.ts.map +1 -0
  141. package/lib/typescript/layout/ex.d.ts +1 -0
  142. package/lib/typescript/layout/ex.d.ts.map +1 -0
  143. package/lib/typescript/layout/icon.d.ts +3 -0
  144. package/lib/typescript/layout/icon.d.ts.map +1 -0
  145. package/lib/typescript/layout/layout.d.ts +3 -0
  146. package/lib/typescript/layout/layout.d.ts.map +1 -0
  147. package/lib/typescript/layout/welcome.d.ts +6 -0
  148. package/lib/typescript/layout/welcome.d.ts.map +1 -0
  149. package/lib/typescript/layout/window.d.ts +5 -0
  150. package/lib/typescript/layout/window.d.ts.map +1 -0
  151. package/lib/typescript/utils/audioRecorder.d.ts +9 -0
  152. package/lib/typescript/utils/audioRecorder.d.ts.map +1 -0
  153. package/lib/typescript/utils/cloudinary.d.ts +17 -0
  154. package/lib/typescript/utils/cloudinary.d.ts.map +1 -0
  155. package/lib/typescript/utils/storage.d.ts +29 -0
  156. package/lib/typescript/utils/storage.d.ts.map +1 -0
  157. package/lib/typescript/utils/textToSpeech.d.ts +2 -0
  158. package/lib/typescript/utils/textToSpeech.d.ts.map +1 -0
  159. package/package.json +109 -0
  160. package/src/assets/chat-icon-mobile.svg +1 -0
  161. package/src/assets/heritage.png +0 -0
  162. package/src/assets/posiden.svg +51 -0
  163. package/src/components/LoadingTips.js +99 -0
  164. package/src/components/email.js +467 -0
  165. package/src/components/feedback.js +114 -0
  166. package/src/components/header.js +119 -0
  167. package/src/components/input.js +133 -0
  168. package/src/components/productCard.js +815 -0
  169. package/src/components/progressCircle.js +88 -0
  170. package/src/components/testing.js +60 -0
  171. package/src/components/voice.js +228 -0
  172. package/src/components/welcomeButton.js +161 -0
  173. package/src/components/welcomeInput.js +133 -0
  174. package/src/contexts/AppContext.js +678 -0
  175. package/src/hooks/Stream.js +655 -0
  176. package/src/hooks/useAsyncStorage.js +33 -0
  177. package/src/index.js +30 -0
  178. package/src/layout/disclaimer.js +231 -0
  179. package/src/layout/ex.js +252 -0
  180. package/src/layout/icon.js +105 -0
  181. package/src/layout/layout.js +160 -0
  182. package/src/layout/welcome.js +172 -0
  183. package/src/layout/window.js +476 -0
  184. package/src/utils/audioRecorder.js +445 -0
  185. package/src/utils/cloudinary.js +61 -0
  186. package/src/utils/storage.ts +89 -0
  187. package/src/utils/textToSpeech.js +49 -0
@@ -0,0 +1,160 @@
1
+ import React, { useRef, useState, useContext, useEffect } from 'react';
2
+ import { View, Animated, PanResponder, Pressable, StyleSheet } from 'react-native';
3
+ import { AppContext } from '../contexts/AppContext';
4
+
5
+ // Pages
6
+ import { ChatWindow } from './window';
7
+ import { ChatIcon } from './icon';
8
+ import { Welcome } from './welcome'
9
+ import { Disclaimer } from './disclaimer';
10
+ import { EmailForm } from '../components/email';
11
+
12
+ export const Layout = () => {
13
+ const { showModal, setShowModal, uiConfig, disclaimer, maintenance, messages } = useContext(AppContext);
14
+
15
+ const panY = useRef(new Animated.Value(0)).current;
16
+ const isDragging = useRef(false);
17
+
18
+ const handleClick = () => {
19
+ if ((uiConfig.showIcon ?? true) !== true) {
20
+ setShowModal("Off");
21
+ } else {
22
+ setShowModal("Icon");
23
+ }
24
+ };
25
+
26
+ /* Currently removed this from the child components.
27
+ If activating drag to close, put {...panHandlers} in the view around the
28
+ header on each page (welcome, window, disclaimer) */
29
+ const panResponder = PanResponder.create({
30
+ onStartShouldSetPanResponder: () => true,
31
+ onMoveShouldSetPanResponder: () => true,
32
+ onPanResponderGrant: () => {
33
+ isDragging.current = true;
34
+ },
35
+ onPanResponderMove: (evt, gestureState) => {
36
+ if (isDragging.current && gestureState.dy >= 0) {
37
+ panY.setValue(gestureState.dy);
38
+ }
39
+ },
40
+ onPanResponderRelease: (evt, gestureState) => {
41
+ if (gestureState.dy > 120) {
42
+ // Close if dragged far enough
43
+ Animated.timing(panY, {
44
+ toValue: 600, // Off-screen
45
+ duration: 200,
46
+ useNativeDriver: false,
47
+ }).start(() => {
48
+ handleClick();
49
+ panY.setValue(0); // Reset for next time
50
+ });
51
+ } else {
52
+ // Snap back to full height
53
+ Animated.spring(panY, {
54
+ toValue: 0,
55
+ friction: 6,
56
+ tension: 80,
57
+ useNativeDriver: false,
58
+ }).start();
59
+ }
60
+ isDragging.current = false;
61
+ },
62
+ });
63
+
64
+ // uiConfig.showIcon, uiConfig.toggleChat
65
+
66
+ useEffect(() => {
67
+ // Add null check for uiConfig first
68
+ if (!uiConfig) {
69
+ setShowModal("Icon"); // Default fallback if uiConfig is missing
70
+ return;
71
+ }
72
+
73
+ if (uiConfig.toggleChat) {
74
+ if (!disclaimer) {
75
+ setShowModal("Form");
76
+ } else {
77
+ if (messages.length > 1 || maintenance) {
78
+ setShowModal("ChatWindow");
79
+ }
80
+ else {
81
+ setShowModal("Welcome")
82
+ }
83
+ }
84
+ } else {
85
+ setShowModal("Icon"); // Default to Icon/bubble state
86
+ }
87
+ }, [uiConfig?.toggleChat]); // Use optional chaining in dependency array
88
+
89
+ return (
90
+ <View style={styles.layout} pointerEvents="box-none">
91
+ {showModal === "Icon" && ((uiConfig?.showIcon ?? true)) && (
92
+ <ChatIcon />
93
+ )}
94
+ {showModal === "ChatWindow" && (
95
+ <>
96
+ {/* <Pressable style={styles.outsideTouchable} onPress={() => handleClick()} /> */}
97
+ <Animated.View style={[styles.container, { transform: [{ translateY: panY }] }]}>
98
+ <ChatWindow panHandlers={panResponder.panHandlers} />
99
+ </Animated.View>
100
+ </>
101
+ )}
102
+ {showModal === "Welcome" && (
103
+ <>
104
+ {/* <Pressable style={styles.outsideTouchable} onPress={() => handleClick()} /> */}
105
+ <Animated.View style={[styles.container, { transform: [{ translateY: panY }] }]}>
106
+ <Welcome panHandlers={panResponder.panHandlers} />
107
+ </Animated.View>
108
+ </>
109
+ )}
110
+ {showModal === "Form" &&
111
+ <>
112
+ {/* <Pressable style={styles.outsideTouchable} onPress={() => handleClick()} /> */}
113
+ <Animated.View style={[styles.container, { transform: [{ translateY: panY }] }]}>
114
+ <Disclaimer panHandlers={panResponder.panHandlers} />
115
+ </Animated.View>
116
+ </>
117
+ }
118
+ {showModal === "Email" &&
119
+ <>
120
+ {/* <Pressable style={styles.outsideTouchable} onPress={() => handleClick()} /> */}
121
+ <Animated.View style={[styles.container, { transform: [{ translateY: panY }] }]}>
122
+ <EmailForm panHandlers={panResponder.panHandlers} />
123
+ </Animated.View>
124
+ </>
125
+ }
126
+ </View>
127
+ );
128
+ };
129
+
130
+ const styles = StyleSheet.create({
131
+ layout: {
132
+ flex: 1,
133
+ position: 'absolute',
134
+ top: 0,
135
+ left: 0,
136
+ right: 0,
137
+ bottom: 0,
138
+ backgroundColor: 'rgba(0, 0, 0, 0)',
139
+ justifyContent: 'flex-end',
140
+ },
141
+ container: {
142
+ flex: 1,
143
+ backgroundColor: '#f6f6f6',
144
+ position: 'absolute',
145
+ zIndex: 1000,
146
+ left: 0,
147
+ right: 0,
148
+ bottom: 0,
149
+ top: 0,
150
+ pointerEvents: 'box-none',
151
+ /* borderTopWidth: 1,
152
+ borderTopColor: '#DDD',
153
+ borderTopLeftRadius: 16,
154
+ borderTopRightRadius: 16, */
155
+ overflow: 'hidden',
156
+ },
157
+ outsideTouchable: {
158
+ flex: 1,
159
+ },
160
+ });
@@ -0,0 +1,172 @@
1
+ // Welcome.js
2
+ import React, { useContext } from 'react';
3
+ import {
4
+ View,
5
+ Text,
6
+ TouchableOpacity,
7
+ ScrollView,
8
+ StyleSheet,
9
+ } from 'react-native';
10
+ import Ionicons from 'react-native-vector-icons/Ionicons';
11
+ import { AppContext } from '../contexts/AppContext';
12
+ import { WelcomeInput } from '../components/welcomeInput';
13
+ import ButtonComponent from '../components/welcomeButton';
14
+ import CloudinaryImage from '../utils/cloudinary';
15
+
16
+ export const Welcome = ({ panHandlers }) => {
17
+ const {
18
+ setShowModal,
19
+ uiConfig,
20
+ onProductCardClick,
21
+ onAddToCartClick,
22
+ data,
23
+ theme,
24
+ brandLogo,
25
+ version,
26
+ } = useContext(AppContext);
27
+
28
+ const handleClick = () => {
29
+ if ((uiConfig.showIcon ?? true) !== true) {
30
+ setShowModal('Off');
31
+ } else {
32
+ setShowModal('Icon');
33
+ }
34
+
35
+ if (typeof uiConfig.setToggleChat === 'function') {
36
+ uiConfig.setToggleChat(false);
37
+ }
38
+ };
39
+
40
+ return (
41
+ <View style={styles.container}>
42
+ <View
43
+ style={[
44
+ styles.parentContainer,
45
+ { backgroundColor: theme.primaryColor },
46
+ ]}>
47
+ {/* Top section */}
48
+ <View
49
+ style={[
50
+ styles.topContainer,
51
+ { backgroundColor: theme.primaryColor },
52
+ ]}>
53
+ <View style={styles.topHeader}>
54
+ {/* Logo container with absolute positioning */}
55
+ <View style={styles.logoContainer}>
56
+ <CloudinaryImage
57
+ cldImg={brandLogo}
58
+ imageStyle={{ width: 150, height: 35 }}
59
+ />
60
+ </View>
61
+ <TouchableOpacity
62
+ onPress={handleClick}
63
+ style={styles.collapseButton}>
64
+ <Ionicons name="chevron-down" size={26} color="white" />
65
+ </TouchableOpacity>
66
+ </View>
67
+
68
+ <View
69
+ style={[
70
+ styles.blueContainer,
71
+ { backgroundColor: theme.primaryColor },
72
+ ]}>
73
+ <Text style={styles.welcomeHeader}>
74
+ Hi {data?.customer_name || ''} 👋
75
+ </Text>
76
+ <Text style={styles.welcomeBody2}>
77
+ {`I’m your ${
78
+ version === 'pool' ? 'HeritagePool+' : 'Heritage+'
79
+ } AI Assistant. I can help you during your online visit with Product and Account information.`}
80
+ </Text>
81
+ <WelcomeInput />
82
+ <Text style={styles.textBeta}>
83
+ Beta version. AI Assistant is still learning!
84
+ </Text>
85
+ </View>
86
+ </View>
87
+
88
+ {/* Bottom section */}
89
+ <ScrollView style={styles.bottomContainer}>
90
+ <Text style={styles.welcomeBody}>Suggested Questions...</Text>
91
+ <ButtonComponent />
92
+ </ScrollView>
93
+ </View>
94
+ </View>
95
+ );
96
+ };
97
+
98
+ const styles = StyleSheet.create({
99
+ container: {
100
+ flex: 1,
101
+ },
102
+ parentContainer: {
103
+ flexGrow: 1,
104
+ backgroundColor: '#437D3D',
105
+ paddingTop: 60,
106
+ },
107
+ topContainer: {
108
+ backgroundColor: '#437D3D',
109
+ paddingBottom: 5,
110
+ },
111
+ topHeader: {
112
+ paddingHorizontal: 15,
113
+ paddingTop: 10,
114
+ flexDirection: 'row',
115
+ alignItems: 'flex-end',
116
+ alignSelf: 'flex-end', // Add this to position the entire topHeader to the right
117
+ position: 'relative',
118
+ },
119
+ logoContainer: {
120
+ // position: 'absolute',
121
+ // left: 15,
122
+ // top: 10,
123
+ // left: '50%',
124
+ // transform: [{ translateX: -65 }],
125
+ // top: 10,
126
+ },
127
+ collapseButton: {
128
+ paddingHorizontal: 0,
129
+ justifyContent: 'center',
130
+ alignItems: 'center',
131
+ },
132
+ blueContainer: {
133
+ backgroundColor: '#437D3D',
134
+ padding: 15,
135
+ margin: 10,
136
+ borderRadius: 20,
137
+ },
138
+ welcomeHeader: {
139
+ fontSize: 24,
140
+ marginBottom: 10,
141
+ color: '#f6f6f6',
142
+ fontWeight: '600',
143
+ },
144
+ welcomeBody2: {
145
+ fontSize: 13,
146
+ lineHeight: 18,
147
+ color: '#f6f6f6',
148
+ fontWeight: '400',
149
+ marginBottom: 15,
150
+ },
151
+ textBeta: {
152
+ textAlign: 'center',
153
+ fontSize: 11,
154
+ color: '#f6f6f6',
155
+ fontWeight: '400',
156
+ marginTop: 5,
157
+ },
158
+ bottomContainer: {
159
+ paddingHorizontal: 25,
160
+ backgroundColor: '#f6f6f6',
161
+ paddingTop: 30,
162
+ },
163
+ welcomeBody: {
164
+ fontSize: 13,
165
+ marginBottom: 10,
166
+ color: '#808080',
167
+ fontWeight: '400',
168
+ lineHeight: 18,
169
+ },
170
+ });
171
+
172
+ export default Welcome;