react-native-srschat 0.1.77 → 0.1.78

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.
@@ -10,7 +10,6 @@ import {
10
10
  findNodeHandle
11
11
  } from "react-native";
12
12
  import Ionicons from "react-native-vector-icons/Ionicons";
13
- import axios from "axios";
14
13
  import { AppContext } from "../contexts/AppContext";
15
14
  import { Header } from "./header";
16
15
  import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
@@ -169,9 +168,21 @@ export const EmailForm = ({ panHandlers }) => {
169
168
 
170
169
  console.log("Email composition request payload:", payload);
171
170
 
172
- const response = await axios.post(`${API_PREFIX}${BASE_URL}/compose-email`, payload);
171
+ const response = await fetch(`${API_PREFIX}${BASE_URL}/compose-email`, {
172
+ method: 'POST',
173
+ headers: {
174
+ 'Content-Type': 'application/json',
175
+ },
176
+ body: JSON.stringify(payload),
177
+ });
178
+
179
+ if (!response.ok) {
180
+ throw new Error(`HTTP error! status: ${response.status}`);
181
+ }
182
+
183
+ const responseData = await response.json();
173
184
 
174
- const textToType = response.data.message;
185
+ const textToType = responseData.message;
175
186
  let currentText = "";
176
187
  const typingSpeed = 10;
177
188
 
@@ -181,16 +192,15 @@ export const EmailForm = ({ panHandlers }) => {
181
192
  setMessage(currentText);
182
193
  }
183
194
 
184
- setSubject(response.data.subject || "");
185
- setUserEmail(response.data.user_email || userEmail || "");
195
+ setSubject(responseData.subject || "");
196
+ setUserEmail(responseData.user_email || userEmail || "");
186
197
  // Don't overwrite branch email if response doesn't have it
187
- if (response.data.branch_email) {
188
- setBranchEmail(response.data.branch_email);
198
+ if (responseData.branch_email) {
199
+ setBranchEmail(responseData.branch_email);
189
200
  }
190
201
 
191
202
  } catch (error) {
192
203
  setError(
193
- error.response?.data?.message ||
194
204
  error.message ||
195
205
  "Failed to compose email"
196
206
  );
@@ -216,15 +226,26 @@ export const EmailForm = ({ panHandlers }) => {
216
226
  const chatHistory = formatChatHistory().map(({ variant_type, ...rest }) => rest);
217
227
  console.log("Sending email with chat history:", chatHistory);
218
228
 
219
- await axios.post(`https://${BASE_URL}/send-email`, {
220
- user_email: userEmail,
221
- subject,
222
- message,
223
- chat_history: chatHistory,
224
- conversation_start_time: conversationStartTime,
225
- customer_name: data?.customer_name,
226
- branch_email: branchEmail || data?.branch_email || ""
229
+ const response = await fetch(`https://${BASE_URL}/send-email`, {
230
+ method: 'POST',
231
+ headers: {
232
+ 'Content-Type': 'application/json',
233
+ },
234
+ body: JSON.stringify({
235
+ user_email: userEmail,
236
+ subject,
237
+ message,
238
+ chat_history: chatHistory,
239
+ conversation_start_time: conversationStartTime,
240
+ customer_name: data?.customer_name,
241
+ branch_email: branchEmail || data?.branch_email || ""
242
+ }),
227
243
  });
244
+
245
+ if (!response.ok) {
246
+ throw new Error(`HTTP error! status: ${response.status}`);
247
+ }
248
+
228
249
  setSuccess(true);
229
250
  setTimeout(() => {
230
251
  setSuccess(false);
@@ -232,7 +253,6 @@ export const EmailForm = ({ panHandlers }) => {
232
253
  }, 2000);
233
254
  } catch (error) {
234
255
  setError(
235
- error.response?.data?.message ||
236
256
  error.message ||
237
257
  "Failed to send email",
238
258
  );
@@ -2,7 +2,6 @@ import React, { useState, useContext, useEffect } from "react";
2
2
  import { View, Text, Image, TouchableOpacity, TextInput, StyleSheet, Platform, Keyboard, ActionSheetIOS, Alert } from "react-native";
3
3
  import { AppContext } from "../contexts/AppContext";
4
4
  import Ionicons from 'react-native-vector-icons/Ionicons';
5
- import axios from 'axios';
6
5
 
7
6
 
8
7
  export const ProductCard = ({ prod, onFocusQuantityInput, messageId }) => {
@@ -273,9 +272,21 @@ export const ProductCard = ({ prod, onFocusQuantityInput, messageId }) => {
273
272
  message_id: messageId
274
273
  };
275
274
  console.log("add to cart payload", payload);
276
- axios.post(ADD_TO_CART_URL, payload)
275
+ fetch(ADD_TO_CART_URL, {
276
+ method: 'POST',
277
+ headers: {
278
+ 'Content-Type': 'application/json',
279
+ },
280
+ body: JSON.stringify(payload),
281
+ })
277
282
  .then(response => {
278
- console.log("log addToCart response", response);
283
+ if (!response.ok) {
284
+ throw new Error(`HTTP error! status: ${response.status}`);
285
+ }
286
+ return response.json();
287
+ })
288
+ .then(data => {
289
+ console.log("log addToCart response", data);
279
290
  })
280
291
  .catch(error => {
281
292
  console.log("log addToCart error", error);
@@ -1,6 +1,5 @@
1
1
  import React, {createContext, useContext, useState, useEffect, useMemo } from "react";
2
2
  import uuid from 'react-native-uuid';
3
- import axios from "axios";
4
3
  // import useAsyncStorage from '../hooks/useAsyncStorage';
5
4
  import { loadChat, updateChat, defaultState } from '../utils/storage';
6
5
 
@@ -243,10 +242,19 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
243
242
  setMessages(maintenanceMessage);
244
243
  }
245
244
  try {
246
- const response = await axios.post(
245
+ const response = await fetch(
247
246
  API_PREFIX + LOGGING_URL + "/log-disclaimer",
248
- { email: data.user_email },
247
+ {
248
+ method: 'POST',
249
+ headers: {
250
+ 'Content-Type': 'application/json',
251
+ },
252
+ body: JSON.stringify({ email: data.user_email }),
253
+ }
249
254
  );
255
+ if (!response.ok) {
256
+ throw new Error(`HTTP error! status: ${response.status}`);
257
+ }
250
258
  } catch (error) {
251
259
  console.error("Error in Log disclaimer:", error);
252
260
  }
@@ -302,13 +310,22 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
302
310
  return updatedFeedback;
303
311
  });
304
312
  try {
305
- const response = await axios.post(
313
+ const response = await fetch(
306
314
  API_PREFIX + LOGGING_URL + "/feedback",
307
315
  {
308
- message_id: messageId,
309
- feedback: feedbackValue,
310
- },
316
+ method: 'POST',
317
+ headers: {
318
+ 'Content-Type': 'application/json',
319
+ },
320
+ body: JSON.stringify({
321
+ message_id: messageId,
322
+ feedback: feedbackValue,
323
+ }),
324
+ }
311
325
  );
326
+ if (!response.ok) {
327
+ throw new Error(`HTTP error! status: ${response.status}`);
328
+ }
312
329
  //console.log(response)
313
330
  } catch (error) {
314
331
  console.error("Error in feedback post:", error);
@@ -348,14 +365,23 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
348
365
  //console.log(messageId, writeFeedback)
349
366
  switchFeedbackOpen(-1, messageId, true);
350
367
  try {
351
- const response = await axios.post(
368
+ const response = await fetch(
352
369
  API_PREFIX + LOGGING_URL + "/feedback-message",
353
370
  {
354
- message_id: messageId,
355
- feedback_message: writeFeedback,
356
- correct_answer: writeAnswer,
357
- },
371
+ method: 'POST',
372
+ headers: {
373
+ 'Content-Type': 'application/json',
374
+ },
375
+ body: JSON.stringify({
376
+ message_id: messageId,
377
+ feedback_message: writeFeedback,
378
+ correct_answer: writeAnswer,
379
+ }),
380
+ }
358
381
  );
382
+ if (!response.ok) {
383
+ throw new Error(`HTTP error! status: ${response.status}`);
384
+ }
359
385
  //console.log(response)
360
386
  } catch (error) {
361
387
  console.error("Error in feedback_message:", error);
@@ -1,37 +1,48 @@
1
1
  // textToSpeech.js
2
2
  import React,{ useState, useContext} from 'react';
3
- import axios from 'axios';
4
3
  import Sound from 'react-native-sound';
5
4
  import { AppContext } from '../contexts/AppContext';
6
5
 
7
6
  export const TextToSpeech = async (inputText) => {
8
7
  const { data } = useContext(AppContext)
9
8
  try {
10
- const response = await axios.post(
9
+ const response = await fetch(
11
10
  'https://api.openai.com/v1/audio/speech',
12
11
  {
13
- model: 'tts-1',
14
- voice: 'alloy',
15
- input: inputText,
16
- },
17
- {
12
+ method: 'POST',
18
13
  headers: {
19
14
  Authorization: `Bearer ${data.openai_key}`,
20
15
  'Content-Type': 'application/json',
21
16
  },
22
- responseType: 'arraybuffer',
17
+ body: JSON.stringify({
18
+ model: 'tts-1',
19
+ voice: 'alloy',
20
+ input: inputText,
21
+ }),
23
22
  }
24
23
  );
25
24
 
26
- const audioFile = `data:audio/mp3;base64,${Buffer.from(response.data).toString('base64')}`;
25
+ if (!response.ok) {
26
+ throw new Error(`HTTP error! status: ${response.status}`);
27
+ }
27
28
 
28
- const sound = new Sound(audioFile, null, (error) => {
29
- if (error) {
30
- console.error('Error playing sound:', error);
31
- } else {
32
- sound.play();
33
- }
34
- });
29
+ const blob = await response.blob();
30
+ const reader = new FileReader();
31
+
32
+ reader.onloadend = () => {
33
+ const base64data = reader.result.split(',')[1];
34
+ const audioFile = `data:audio/mp3;base64,${base64data}`;
35
+
36
+ const sound = new Sound(audioFile, null, (error) => {
37
+ if (error) {
38
+ console.error('Error playing sound:', error);
39
+ } else {
40
+ sound.play();
41
+ }
42
+ });
43
+ };
44
+
45
+ reader.readAsDataURL(blob);
35
46
  } catch (error) {
36
47
  console.error('Error generating TTS:', error);
37
48
  }