tjtanjin / react-chatbotify

A modern React library for creating a flexible and extensible chatbot.
https://react-chatbotify.com
MIT License
148 stars 68 forks source link

audio not working #87

Closed ajaysingh7623 closed 1 month ago

ajaysingh7623 commented 1 month ago

image image here i attached the screenshot and the error i am getting in browser plz help on this @tjtanjin

tjtanjin commented 1 month ago

@ajaysingh7623 That message is saying the user needs to interact with the page before audio can be played.

ajaysingh7623 commented 1 month ago

import axios from "axios"; import { CDN_LOTTIES } from "config/env"; import React, { useState } from "react"; import ChatBot from "react-chatbotify"; import { useDispatch } from "react-redux"; function ChatBotify() { const dispatch = useDispatch(); const [quote, setQuote] = useState(""); // Select the session history from the Redux store // const {quote,quoteID} = useSelector((state) => state.chatBotifyReducer); console.log(quote, "session");

// const [sessionHistory, setSessionHistory] = useState({ // quote: "", // quoteID: "" // }); // console.log(sessionHistory, "hh"); async function run(params) { const authToken = localStorage.getItem("authToken"); const payload = { userinput: params?.userInput, history: { quote: "14235436", quoteID: quote ||"" } }; const url = "/api/start"; const config = { headers: { "Content-Type": "application/json", Authorization: Bearer ${authToken} } }; try { const response = await axios.post(url, payload, config); const quote = response?.data?.session_history.quote; const quoteID = response?.data?.session_history.quoteID; setQuote(quoteID); // setSessionHistory((prev) => ({ // ...prev, // quote: quote, // quoteID: quoteID // })); // dispatch({ // type: "SET_SESSION_HISTORY", // payload: response?.data?.session_history // }); if (response.data) { params.streamMessage( response?.data?.bot_response + " " + response?.data?.next_step_recommendation ); } else { console.error("Unexpected response structure:", response); return "Unexpected response from server."; } } catch (error) { console.error("Error during Axios request:", error); return "An error occurred while processing your request."; } } const flow = { start: { message: "Hello, I am CPQ ChatBot, How Can I Help You!", path: "model_loop" }, model_loop: { message: (params) => { run(params); }, path: "model_loop" } };

const themes = [ { id: "minimal_midnight", version: "0.1.0" } ]; const microsoftLogo = ${CDN_LOTTIES.replace( "lotties", "images" )}microsoft-edge.png; const styles = { // chatButtonStyle: { // height: "10%", // width: "10%" // } };

return ( <ChatBot themes={themes} styles={styles} settings={{ audio: { disabled: false, defaultToggledOn: false }, voice: { disabled: false }, chatHistory: { storageKey: "example_audio" }, chatButton: { icon: microsoftLogo } }} flow={flow} /> ); } export default ChatBotify; can u plz go through the code something i am missing so audio is not working

tjtanjin commented 1 month ago

image image here i attached the screenshot and the error i am getting in browser plz help on this @tjtanjin

Based on the message in the yellow box above, the chatbot was already trying to play audio (i.e. audio is working) but was unable to, because the user has yet to interact with the page. Try clicking around and then trigger the next message.

ajaysingh7623 commented 1 month ago

image image here i attached the screenshot and the error i am getting in browser plz help on this @tjtanjin

Based on the message in the yellow box above, the chatbot was already trying to play audio (i.e. audio is working) but was unable to, because the user has yet to interact with the page. Try clicking around and then trigger the next message.

hello @tjtanjin i tried this thing but then also it is happening

tjtanjin commented 1 month ago

The yellow box message appearing is indicative that it is trying to play an audio, but I can't really tell why you're not getting the sound (it seems likely it's a local issue since it works on the playground for you). Is your project available on GitHub? If so I could clone and take a look.

ajaysingh7623 commented 1 month ago

The yellow box message appearing is indicative that it is trying to play an audio, but I can't really tell why you're not getting the sound (it seems likely it's a local issue since it works on the playground for you). Is your project available on GitHub? If so I could clone and take a look.

no it is not in github we can connect on google-meet if u don't mind?

tjtanjin commented 1 month ago

The yellow box message appearing is indicative that it is trying to play an audio, but I can't really tell why you're not getting the sound (it seems likely it's a local issue since it works on the playground for you). Is your project available on GitHub? If so I could clone and take a look.

no it is not in github we can connect on google-meet if u don't mind?

We can use discord if you're already in the server

ajaysingh7623 commented 1 month ago

@tjtanjin Thank you now it is working