added stop button for live chat bot

This commit is contained in:
Harith_dml 2025-06-30 16:45:11 +05:30
parent 497da3c850
commit 8b49ee3e76
2 changed files with 63 additions and 56 deletions

View file

@ -130,6 +130,12 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
} }
}; };
const handleStopListening = () => {
if ('speechSynthesis' in window) {
window.speechSynthesis.cancel();
}
};
const handleCreateTicketFromChat = async () => { const handleCreateTicketFromChat = async () => {
if (!ticketFormData.requester.trim() || !ticketFormData.email.trim()) { if (!ticketFormData.requester.trim() || !ticketFormData.email.trim()) {
@ -208,14 +214,14 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
)} )}
<div <div
className={`max-w-[70%] p-3 rounded-lg ${ className={`max-w-[70%] p-3 rounded-lg ${message.role === 'user'
message.role === 'user'
? 'bg-blue-600 text-white' ? 'bg-blue-600 text-white'
: 'bg-gray-800 text-gray-100 border border-gray-700' : 'bg-gray-800 text-gray-100 border border-gray-700'
}`} }`}
> >
<p className="whitespace-pre-wrap leading-relaxed">{message.content}</p> <p className="whitespace-pre-wrap leading-relaxed">{message.content}</p>
<p className="text-xs opacity-70 mt-2">{message.timestamp}</p> <p className="text-xs opacity-70 mt-2">{message.timestamp}</p>
{message.role !== 'user' && (<button className= "text-red-800" onClick={handleStopListening}>Stop</button>)}
</div> </div>
{message.role === 'user' && ( {message.role === 'user' && (

View file

@ -24,6 +24,7 @@ export class SpeechService {
): void { ): void {
if (!this.recognition || this.isListening) return; if (!this.recognition || this.isListening) return;
this.recognition.onresult = (event) => { this.recognition.onresult = (event) => {
let transcript = ''; let transcript = '';
let confidence = 0; let confidence = 0;