react-native-srschat 0.1.83 → 0.1.85

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 (59) hide show
  1. package/lib/commonjs/components/email.js +5 -9
  2. package/lib/commonjs/components/email.js.map +1 -1
  3. package/lib/commonjs/components/productCard.js +91 -86
  4. package/lib/commonjs/components/productCard.js.map +1 -1
  5. package/lib/commonjs/components/welcomeButton.js +4 -4
  6. package/lib/commonjs/components/welcomeButton.js.map +1 -1
  7. package/lib/commonjs/contexts/AppContext.js +46 -45
  8. package/lib/commonjs/contexts/AppContext.js.map +1 -1
  9. package/lib/commonjs/hooks/Stream.js +399 -74
  10. package/lib/commonjs/hooks/Stream.js.map +1 -1
  11. package/lib/commonjs/layout/disclaimer.js +36 -32
  12. package/lib/commonjs/layout/disclaimer.js.map +1 -1
  13. package/lib/commonjs/layout/welcome.js +8 -7
  14. package/lib/commonjs/layout/welcome.js.map +1 -1
  15. package/lib/commonjs/layout/window.js +152 -131
  16. package/lib/commonjs/layout/window.js.map +1 -1
  17. package/lib/commonjs/utils/audioRecorder.js.map +1 -1
  18. package/lib/commonjs/utils/storage.js +1 -1
  19. package/lib/module/components/email.js +5 -9
  20. package/lib/module/components/email.js.map +1 -1
  21. package/lib/module/components/productCard.js +94 -89
  22. package/lib/module/components/productCard.js.map +1 -1
  23. package/lib/module/components/welcomeButton.js +4 -4
  24. package/lib/module/components/welcomeButton.js.map +1 -1
  25. package/lib/module/contexts/AppContext.js +47 -46
  26. package/lib/module/contexts/AppContext.js.map +1 -1
  27. package/lib/module/hooks/Stream.js +400 -75
  28. package/lib/module/hooks/Stream.js.map +1 -1
  29. package/lib/module/layout/disclaimer.js +41 -37
  30. package/lib/module/layout/disclaimer.js.map +1 -1
  31. package/lib/module/layout/welcome.js +8 -7
  32. package/lib/module/layout/welcome.js.map +1 -1
  33. package/lib/module/layout/window.js +152 -131
  34. package/lib/module/layout/window.js.map +1 -1
  35. package/lib/module/utils/audioRecorder.js.map +1 -1
  36. package/lib/module/utils/storage.js +1 -1
  37. package/lib/typescript/components/email.d.ts.map +1 -1
  38. package/lib/typescript/components/productCard.d.ts +1 -1
  39. package/lib/typescript/components/productCard.d.ts.map +1 -1
  40. package/lib/typescript/components/welcomeButton.d.ts.map +1 -1
  41. package/lib/typescript/contexts/AppContext.d.ts +2 -2
  42. package/lib/typescript/contexts/AppContext.d.ts.map +1 -1
  43. package/lib/typescript/hooks/Stream.d.ts.map +1 -1
  44. package/lib/typescript/layout/disclaimer.d.ts +1 -1
  45. package/lib/typescript/layout/disclaimer.d.ts.map +1 -1
  46. package/lib/typescript/layout/welcome.d.ts.map +1 -1
  47. package/lib/typescript/layout/window.d.ts.map +1 -1
  48. package/lib/typescript/utils/audioRecorder.d.ts.map +1 -1
  49. package/package.json +2 -1
  50. package/src/components/email.js +4 -16
  51. package/src/components/productCard.js +279 -203
  52. package/src/components/welcomeButton.js +10 -10
  53. package/src/contexts/AppContext.js +185 -106
  54. package/src/hooks/Stream.js +607 -237
  55. package/src/layout/disclaimer.js +125 -78
  56. package/src/layout/welcome.js +58 -20
  57. package/src/layout/window.js +279 -140
  58. package/src/utils/audioRecorder.js +40 -34
  59. package/src/utils/storage.ts +2 -2
@@ -8,7 +8,7 @@ const landscapeQuestions = [
8
8
  { text: 'Do you have part # RBLESPLXME2 in stock?' },
9
9
  { text: 'How do I install the seal on B82456?' },
10
10
  { text: 'Where can I find my POs?' },
11
- { text: '¿Puedes ayudarme en español?' }
11
+ { text: '¿Puedes ayudarme en español?' },
12
12
  ];
13
13
 
14
14
  const poolQuestions = [
@@ -16,7 +16,7 @@ const poolQuestions = [
16
16
  { text: 'Do you have part # JNDDEV48 in stock?' },
17
17
  { text: 'Do you carry Hayward super pumps?' },
18
18
  { text: 'Which grid assembly goes with the Hayward DE4820 filter?' },
19
- { text: '¿Puedes ayudarme en español?' }
19
+ { text: '¿Puedes ayudarme en español?' },
20
20
  ];
21
21
 
22
22
  const ButtonComponent = () => {
@@ -29,10 +29,11 @@ const ButtonComponent = () => {
29
29
  {suggestedQuestions.map((item, index) => (
30
30
  <TouchableOpacity
31
31
  key={index}
32
- style={[styles.button, { borderColor: theme.primaryColor }]}
33
- onPress={() => handleButtonClick(item.text)}
34
- >
35
- <Text style={[styles.buttonText, { color: theme.primaryColor }]}>{item.text}</Text>
32
+ style={[styles.button, { borderColor: '#004687' }]}
33
+ onPress={() => handleButtonClick(item.text)}>
34
+ <Text style={[styles.buttonText, { color: '#004687' }]}>
35
+ {item.text}
36
+ </Text>
36
37
  </TouchableOpacity>
37
38
  ))}
38
39
  </View>
@@ -40,11 +41,10 @@ const ButtonComponent = () => {
40
41
  };
41
42
 
42
43
  const styles = StyleSheet.create({
43
- buttonContainer: {
44
- },
44
+ buttonContainer: {},
45
45
  button: {
46
46
  backgroundColor: 'white',
47
- borderColor: '#437D3D',
47
+ borderColor: '#004687',
48
48
  borderWidth: 1,
49
49
  borderRadius: 18,
50
50
  paddingVertical: 12,
@@ -52,7 +52,7 @@ const styles = StyleSheet.create({
52
52
  marginBottom: 16,
53
53
  },
54
54
  buttonText: {
55
- color: '#437D3D',
55
+ color: '#004687',
56
56
  fontSize: 13,
57
57
  fontWeight: '400',
58
58
  },
@@ -1,14 +1,29 @@
1
- import React, {createContext, useContext, useState, useEffect, useMemo } from "react";
1
+ import React, {
2
+ createContext,
3
+ useContext,
4
+ useState,
5
+ useEffect,
6
+ useMemo,
7
+ } from 'react';
2
8
  import uuid from 'react-native-uuid';
3
9
  // import useAsyncStorage from '../hooks/useAsyncStorage';
4
10
  import { loadChat, updateChat, defaultState } from '../utils/storage';
5
11
 
6
12
  export const AppContext = createContext();
7
13
 
8
- export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConfig = {}, children }) => {
14
+ export const AppProvider = ({
15
+ data,
16
+ onProductCardClick,
17
+ onAddToCartClick,
18
+ uiConfig = {},
19
+ children,
20
+ }) => {
9
21
  // Brand-driven configuration
10
- const version = (data?.brand_version === 'pool' || data?.brand_version === 'landscape') ? data.brand_version : 'landscape';
11
- const API_PREFIX = "https://";
22
+ const version =
23
+ data?.brand_version === 'pool' || data?.brand_version === 'landscape'
24
+ ? data.brand_version
25
+ : 'landscape';
26
+ const API_PREFIX = 'https://';
12
27
 
13
28
  const BRAND_CONFIG = (() => {
14
29
  const isStage = data?.env === 'stage';
@@ -22,7 +37,8 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
22
37
  baseHost: isStage
23
38
  ? 'pool-stage-external-agent-adk-586731320826.us-east1.run.app'
24
39
  : 'pool-prod-external-agent-adk-586731320826.us-east1.run.app',
25
- loggingHost: 'srs-external-agent-logging-586731320826.us-central1.run.app',
40
+ loggingHost:
41
+ 'srs-external-agent-logging-586731320826.us-central1.run.app',
26
42
  },
27
43
  landscape: {
28
44
  primaryColor: '#437D3D',
@@ -32,7 +48,8 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
32
48
  baseHost: isStage
33
49
  ? 'landscape-stage-external-agent-adk-586731320826.us-east1.run.app'
34
50
  : 'landscape-prod-external-agent-adk-586731320826.us-east1.run.app',
35
- loggingHost: 'srs-external-agent-landscape-logging-586731320826.us-central1.run.app',
51
+ loggingHost:
52
+ 'srs-external-agent-landscape-logging-586731320826.us-central1.run.app',
36
53
  },
37
54
  }[version];
38
55
  })();
@@ -57,24 +74,28 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
57
74
 
58
75
  // Default Messages
59
76
  const defaultMessage = [
60
- {type: "ai", text: "Hi there 👋 I'm your Heritage Pool+ AI Assistant. I'm here to help you with Product and Account information during your online visit. I'm still learning and growing - the more we interact and the more feedback you share, the better I can assist you. How can I help you today?"}
61
- ]
77
+ {
78
+ type: 'ai',
79
+ text: `Hi there 👋 I'm your ${brandLogo} AI Assistant. I'm here to help you with Product and Account information during your online visit. I'm still learning and growing - the more we interact and the more feedback you share, the better I can assist you. How can I help you today?`,
80
+ },
81
+ ];
62
82
  const maintenanceMessage = [
63
- { type: "ai", text: "Hi there 👋 I'm your Heritage Pool+ AI Agent. I'm currently undergoing maintenance to improve my services. Thank you for your patience and understanding!",},
83
+ {
84
+ type: 'ai',
85
+ text: "Hi there 👋 I'm your Heritage+ AI Agent. I'm currently undergoing maintenance to improve my services. Thank you for your patience and understanding!",
86
+ },
64
87
  ];
65
88
 
66
-
67
89
  // user data variables
68
90
  const customerToken = data.customer_token;
69
91
 
70
-
71
92
  // Base Variables
72
- const [showModal, setShowModal] = useState("Icon");
93
+ const [showModal, setShowModal] = useState('Icon');
73
94
  const [input, setInput] = useState('');
74
95
  const [messages, setMessages] = useState(defaultState.messages);
75
96
  const [conversationStartTime, setConversationStartTime] = useState(null);
76
- const [lastUserMessage, setLastUserMessage] = useState("");
77
- const [lastMessageId, setLastMessageId] = useState("");
97
+ const [lastUserMessage, setLastUserMessage] = useState('');
98
+ const [lastMessageId, setLastMessageId] = useState('');
78
99
  const [sessionId, setSessionId] = useState(null);
79
100
  const [isListening, setIsListening] = useState(false);
80
101
 
@@ -89,11 +110,11 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
89
110
  // Load persisted state on mount
90
111
  useEffect(() => {
91
112
  if (!customerToken) return;
92
-
113
+
93
114
  const init = async () => {
94
115
  try {
95
116
  const cachedState = await loadChat(customerToken);
96
-
117
+
97
118
  // Update all stateful values
98
119
  setTypingIndicator(cachedState.typingIndicator);
99
120
  setGhostMessage(cachedState.ghostMessage);
@@ -104,34 +125,36 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
104
125
  setMessages(cachedState.messages);
105
126
  // setShowModal(cachedState.showModal);
106
127
 
107
- if (uiConfig.toggleChat === false){
108
- setShowModal("Icon");
109
- }else{
110
- if (!disclaimer){
111
- setShowModal("Form")
112
- }else{
113
- if ((uiConfig.showWelcome === true || cachedState.showWelcome === true) && (messages.length <2)){
128
+ if (uiConfig.toggleChat === false) {
129
+ setShowModal('Icon');
130
+ } else {
131
+ if (!disclaimer) {
132
+ setShowModal('Form');
133
+ } else {
134
+ if (
135
+ (uiConfig.showWelcome === true ||
136
+ cachedState.showWelcome === true) &&
137
+ messages.length < 2
138
+ ) {
114
139
  // console.log("showWelcome", uiConfig.showWelcome, cachedState.showWelcome)
115
- setShowModal("Welcome");
116
- }else{
117
- setShowModal("ChatWindow");
140
+ setShowModal('Welcome');
141
+ } else {
142
+ setShowModal('ChatWindow');
118
143
  }
119
144
  }
120
145
  }
121
-
122
-
123
146
  } catch (error) {
124
147
  console.error('Error loading chat state:', error);
125
148
  }
126
149
  };
127
-
150
+
128
151
  init();
129
152
  }, [customerToken, uiConfig.toggleChat, uiConfig.showWelcome]);
130
153
 
131
154
  // Persist state changes
132
155
  useEffect(() => {
133
156
  if (!customerToken) return;
134
-
157
+
135
158
  const persistState = async () => {
136
159
  const currentState = {
137
160
  typingIndicator,
@@ -142,12 +165,12 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
142
165
  startStreaming,
143
166
  messages,
144
167
  showModal,
145
- showWelcome: uiConfig.showWelcome
168
+ showWelcome: uiConfig.showWelcome,
146
169
  };
147
-
170
+
148
171
  await updateChat(customerToken, currentState);
149
172
  };
150
-
173
+
151
174
  persistState();
152
175
  }, [
153
176
  customerToken,
@@ -159,12 +182,12 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
159
182
  startStreaming,
160
183
  messages,
161
184
  showModal,
162
- uiConfig.showWelcome
185
+ uiConfig.showWelcome,
163
186
  ]);
164
187
 
165
188
  useEffect(() => {
166
- if (showModal == "Off") {
167
- setShowModal("Icon")
189
+ if (showModal == 'Off') {
190
+ setShowModal('Icon');
168
191
  }
169
192
  }, [uiConfig.showIcon]);
170
193
 
@@ -175,20 +198,27 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
175
198
 
176
199
  function handleSend(input) {
177
200
  if (maintenance) {
178
- setMessages([ ...messages, { type: "user", text: input },
179
- { type: "ai", text: "The chat is currently unavailable, please come back later!",},]);
201
+ setMessages([
202
+ ...messages,
203
+ { type: 'user', text: input },
204
+ {
205
+ type: 'ai',
206
+ text: 'The chat is currently unavailable, please come back later!',
207
+ },
208
+ ]);
180
209
  return;
181
210
  }
182
-
211
+
183
212
  // Ensure input is a string and not empty
184
- const userInput = typeof input === 'string' ? input.trim() : String(input || '').trim();
185
-
186
- if (userInput !== "") {
213
+ const userInput =
214
+ typeof input === 'string' ? input.trim() : String(input || '').trim();
215
+
216
+ if (userInput !== '') {
187
217
  // Ensure sessionId exists before starting a conversation
188
218
  if (!sessionId) {
189
219
  const newSessionId = uuid.v4();
190
220
  setSessionId(newSessionId);
191
- console.log("[AppContext] Generated new sessionId:", newSessionId);
221
+ console.log('[AppContext] Generated new sessionId:', newSessionId);
192
222
  }
193
223
  if (messages.length <= 1) {
194
224
  const startTime = new Date().toISOString();
@@ -196,26 +226,26 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
196
226
  }
197
227
 
198
228
  // Create user message object with immutable text
199
- const userMessage = {
200
- type: "user",
229
+ const userMessage = {
230
+ type: 'user',
201
231
  text: userInput,
202
- session_id : data.session_id || data.session || sessionId,
232
+ session_id: data.session_id || data.session || sessionId,
203
233
  };
204
234
 
205
235
  // Initiate streaming
206
- setShowModal("ChatWindow");
236
+ setShowModal('ChatWindow');
207
237
  setLastUserMessage(userInput);
208
238
  setMessages([...messages, userMessage]);
209
239
  setTypingIndicator(true);
210
240
  setGhostMessage(true);
211
241
  setStartStreaming(true);
212
- setInput("")
242
+ setInput('');
213
243
  }
214
244
  }
215
245
 
216
246
  // After form submission
217
247
  function setNextMessage(name) {
218
- setMessages((prevMessages) => {
248
+ setMessages(prevMessages => {
219
249
  const updatedMessages = prevMessages.map((message, index) => {
220
250
  if (index === prevMessages.length - 1 && message.form) {
221
251
  return { ...message, form: false };
@@ -224,7 +254,7 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
224
254
  });
225
255
 
226
256
  const nextMessage = {
227
- type: "ai",
257
+ type: 'ai',
228
258
  text: [`Nice to meet you ${name}. How can I help you today?`],
229
259
  };
230
260
  return [...updatedMessages, nextMessage];
@@ -235,28 +265,28 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
235
265
  async function confirmDisclaimer() {
236
266
  setDisclaimer(true);
237
267
  if (!maintenance) {
238
- setShowModal("Welcome");
268
+ setShowModal('Welcome');
239
269
  setMessages(defaultMessage);
240
270
  } else {
241
- setShowModal("ChatWindow");
271
+ setShowModal('ChatWindow');
242
272
  setMessages(maintenanceMessage);
243
273
  }
244
274
  try {
245
275
  const response = await fetch(
246
- API_PREFIX + LOGGING_URL + "/log-disclaimer",
276
+ API_PREFIX + LOGGING_URL + '/log-disclaimer',
247
277
  {
248
278
  method: 'POST',
249
279
  headers: {
250
280
  'Content-Type': 'application/json',
251
281
  },
252
282
  body: JSON.stringify({ email: data.user_email }),
253
- }
283
+ },
254
284
  );
255
285
  if (!response.ok) {
256
286
  throw new Error(`HTTP error! status: ${response.status}`);
257
287
  }
258
288
  } catch (error) {
259
- console.error("Error in Log disclaimer:", error);
289
+ console.error('Error in Log disclaimer:', error);
260
290
  }
261
291
  }
262
292
 
@@ -268,21 +298,21 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
268
298
 
269
299
  const handleClearState = async () => {
270
300
  if (!maintenance) {
271
- setShowModal("Welcome");
301
+ setShowModal('Welcome');
272
302
  }
273
303
  if (messages.length > 1) {
274
304
  const newState = {
275
305
  ...defaultState,
276
306
  messages: maintenance ? maintenanceMessage : defaultMessage,
277
- showModal: maintenance ? "ChatWindow" : "Welcome"
307
+ showModal: maintenance ? 'ChatWindow' : 'Welcome',
278
308
  };
279
-
309
+
280
310
  // Update all state variables
281
311
  setMessages(newState.messages);
282
312
  setTypingIndicator(false);
283
313
  setGhostMessage(false);
284
314
  setShowModal(newState.showModal);
285
-
315
+
286
316
  // Generate new session
287
317
  const newSessionId = uuid.v4();
288
318
  setSessionId(newSessionId);
@@ -298,7 +328,7 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
298
328
 
299
329
  async function handleFeedback(feedbackValue, messageId) {
300
330
  switchFeedbackOpen(true, messageId, true);
301
- setFeedback((prevFeedback) => {
331
+ setFeedback(prevFeedback => {
302
332
  const updatedFeedback = { ...prevFeedback };
303
333
 
304
334
  if (!updatedFeedback[messageId]) {
@@ -310,63 +340,60 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
310
340
  return updatedFeedback;
311
341
  });
312
342
  try {
313
- const response = await fetch(
314
- API_PREFIX + LOGGING_URL + "/feedback",
315
- {
316
- method: 'POST',
317
- headers: {
318
- 'Content-Type': 'application/json',
319
- },
320
- body: JSON.stringify({
321
- message_id: messageId,
322
- feedback: feedbackValue,
323
- }),
324
- }
325
- );
343
+ const response = await fetch(API_PREFIX + LOGGING_URL + '/feedback', {
344
+ method: 'POST',
345
+ headers: {
346
+ 'Content-Type': 'application/json',
347
+ },
348
+ body: JSON.stringify({
349
+ message_id: messageId,
350
+ feedback: feedbackValue,
351
+ }),
352
+ });
326
353
  if (!response.ok) {
327
354
  throw new Error(`HTTP error! status: ${response.status}`);
328
355
  }
329
356
  //console.log(response)
330
357
  } catch (error) {
331
- console.error("Error in feedback post:", error);
358
+ console.error('Error in feedback post:', error);
332
359
  }
333
360
  }
334
361
 
335
362
  const [feedbackOpen, setFeedbackOpen] = useState({});
336
- const [writeFeedback, setWriteFeedback] = useState("");
337
- const [writeAnswer, setWriteAnswer] = useState("");
363
+ const [writeFeedback, setWriteFeedback] = useState('');
364
+ const [writeAnswer, setWriteAnswer] = useState('');
338
365
 
339
366
  // Written Feedback ----------------------------
340
367
 
341
368
  function switchFeedbackOpen(newVal, messageId, resetvalue) {
342
- console.log(newVal,feedbackOpen[messageId], messageId, resetvalue)
343
- console.log(feedbackOpen)
369
+ console.log(newVal, feedbackOpen[messageId], messageId, resetvalue);
370
+ console.log(feedbackOpen);
344
371
  if (newVal != feedbackOpen[messageId]) {
345
- setWriteFeedback("");
346
- setWriteAnswer("");
372
+ setWriteFeedback('');
373
+ setWriteAnswer('');
347
374
  }
348
375
  if (resetvalue) {
349
- setWriteFeedback("");
350
- setWriteAnswer("");
376
+ setWriteFeedback('');
377
+ setWriteAnswer('');
351
378
  }
352
- if (feedbackOpen[messageId] == "done") {
379
+ if (feedbackOpen[messageId] == 'done') {
353
380
  return;
354
381
  }
355
- setFeedbackOpen((prevFeedback) => {
382
+ setFeedbackOpen(prevFeedback => {
356
383
  const updatedFeedback = { ...prevFeedback };
357
384
  updatedFeedback[messageId] = newVal;
358
385
  return updatedFeedback;
359
386
  });
360
- console.log(feedbackOpen)
387
+ console.log(feedbackOpen);
361
388
  }
362
389
 
363
390
  async function handleWrittenFeedback(messageId) {
364
- if (writeFeedback.trim() !== "" || writeAnswer.trim() !== "") {
391
+ if (writeFeedback.trim() !== '' || writeAnswer.trim() !== '') {
365
392
  //console.log(messageId, writeFeedback)
366
393
  switchFeedbackOpen(-1, messageId, true);
367
394
  try {
368
395
  const response = await fetch(
369
- API_PREFIX + LOGGING_URL + "/feedback-message",
396
+ API_PREFIX + LOGGING_URL + '/feedback-message',
370
397
  {
371
398
  method: 'POST',
372
399
  headers: {
@@ -377,25 +404,25 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
377
404
  feedback_message: writeFeedback,
378
405
  correct_answer: writeAnswer,
379
406
  }),
380
- }
407
+ },
381
408
  );
382
409
  if (!response.ok) {
383
410
  throw new Error(`HTTP error! status: ${response.status}`);
384
411
  }
385
412
  //console.log(response)
386
413
  } catch (error) {
387
- console.error("Error in feedback_message:", error);
414
+ console.error('Error in feedback_message:', error);
388
415
  }
389
416
  }
390
417
  }
391
418
 
392
419
  const formatChatHistory = () => {
393
420
  // Skip the first message (index 0) which is the welcome message
394
- return messages.slice(1).map((message) => {
421
+ return messages.slice(1).map(message => {
395
422
  if (Array.isArray(message.text)) {
396
423
  return {
397
424
  type: message.type,
398
- content: message.text.join("\n"),
425
+ content: message.text.join('\n'),
399
426
  };
400
427
  }
401
428
  return {
@@ -404,22 +431,22 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
404
431
  };
405
432
  });
406
433
  };
407
-
434
+
408
435
  function handleVoiceSend(audio, transcription) {
409
436
  //setReadAloud(true)
410
- handleSend(transcription)
437
+ handleSend(transcription);
411
438
  }
412
439
 
413
440
  // Wrapper function for onAddToCartClick to add middle message
414
- const handleAddToCartWithMessage = (cartData) => {
441
+ const handleAddToCartWithMessage = cartData => {
415
442
  // Add middle message indicating item is being added to cart
416
- setMessages((prevMessages) => [
443
+ setMessages(prevMessages => [
417
444
  ...prevMessages,
418
445
  {
419
- type: "middle",
446
+ type: 'middle',
420
447
  text: `${cartData.quantity} ${cartData.selectedUom} of item ${cartData.product.product_details.product_name} added to cart`,
421
448
  products: [],
422
- product_cards: "False",
449
+ product_cards: 'False',
423
450
  },
424
451
  ]);
425
452
 
@@ -431,15 +458,67 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
431
458
 
432
459
  return (
433
460
  <AppContext.Provider
434
- value={{ showModal, setShowModal, messages, setMessages, handleSend, input, setInput, defaultMessage, typingIndicator, setTypingIndicator,
435
- handleClearState, theme, handleButtonClick, conversationStartTime, setConversationStartTime, lastUserMessage, setLastUserMessage,
436
- ghostMessage, setGhostMessage, ghostCard, setGhostCard, stopActivated, setStopActivated, disclaimer, setDisclaimer,
437
- startStreaming, setStartStreaming, maintenance, setMaintenance, feedback, setFeedback, handleFeedback, feedbackOpen, setFeedbackOpen,
438
- writeFeedback, setWriteFeedback, writeAnswer, setWriteAnswer, BASE_URL, lastMessageId, setLastMessageId,
439
- onProductCardClick, onAddToCartClick: handleAddToCartWithMessage, data, sessionId, setSessionId, handleWrittenFeedback, switchFeedbackOpen, confirmDisclaimer,
440
- formatChatHistory, uiConfig, handleVoiceSend, TRACK_CLICK_URL, ADD_TO_CART_URL, isListening, setIsListening, brandLogo, brandCloudName
441
- }}
442
- >
461
+ value={{
462
+ showModal,
463
+ setShowModal,
464
+ messages,
465
+ setMessages,
466
+ handleSend,
467
+ input,
468
+ setInput,
469
+ defaultMessage,
470
+ typingIndicator,
471
+ setTypingIndicator,
472
+ handleClearState,
473
+ theme,
474
+ handleButtonClick,
475
+ conversationStartTime,
476
+ setConversationStartTime,
477
+ lastUserMessage,
478
+ setLastUserMessage,
479
+ ghostMessage,
480
+ setGhostMessage,
481
+ ghostCard,
482
+ setGhostCard,
483
+ stopActivated,
484
+ setStopActivated,
485
+ disclaimer,
486
+ setDisclaimer,
487
+ startStreaming,
488
+ setStartStreaming,
489
+ maintenance,
490
+ setMaintenance,
491
+ feedback,
492
+ setFeedback,
493
+ handleFeedback,
494
+ feedbackOpen,
495
+ setFeedbackOpen,
496
+ writeFeedback,
497
+ setWriteFeedback,
498
+ writeAnswer,
499
+ setWriteAnswer,
500
+ BASE_URL,
501
+ lastMessageId,
502
+ setLastMessageId,
503
+ onProductCardClick,
504
+ onAddToCartClick: handleAddToCartWithMessage,
505
+ data,
506
+ sessionId,
507
+ setSessionId,
508
+ handleWrittenFeedback,
509
+ switchFeedbackOpen,
510
+ confirmDisclaimer,
511
+ formatChatHistory,
512
+ uiConfig,
513
+ handleVoiceSend,
514
+ TRACK_CLICK_URL,
515
+ ADD_TO_CART_URL,
516
+ isListening,
517
+ setIsListening,
518
+ brandLogo,
519
+ brandCloudName,
520
+ version,
521
+ }}>
443
522
  {children}
444
523
  </AppContext.Provider>
445
524
  );