Update ClientPortal.tsx
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { Ticket, KBArticle, ChatMessage, TicketPriority, TicketStatus, SurveyResult, Attachment, ClientUser, TicketQueue } from '../types';
|
||||
import { Ticket, KBArticle, ChatMessage, TicketPriority, TicketStatus, SurveyResult, Attachment, ClientUser, TicketQueue, AppSettings } from '../types';
|
||||
import { getSupportResponse } from '../services/geminiService';
|
||||
import { ToastType } from './Toast';
|
||||
import {
|
||||
@@ -29,6 +28,7 @@ interface ClientPortalProps {
|
||||
currentUser: ClientUser;
|
||||
articles: KBArticle[];
|
||||
queues: TicketQueue[];
|
||||
settings: AppSettings; // Added settings prop
|
||||
onCreateTicket: (ticket: Omit<Ticket, 'id' | 'createdAt' | 'messages' | 'status'>) => void;
|
||||
onReplyTicket: (ticketId: string, message: string) => void;
|
||||
onSubmitSurvey: (survey: Omit<SurveyResult, 'id' | 'timestamp'>) => void;
|
||||
@@ -41,6 +41,7 @@ export const ClientPortal: React.FC<ClientPortalProps> = ({
|
||||
currentUser,
|
||||
articles,
|
||||
queues,
|
||||
settings,
|
||||
onCreateTicket,
|
||||
onReplyTicket,
|
||||
onSubmitSurvey,
|
||||
@@ -102,11 +103,20 @@ export const ClientPortal: React.FC<ClientPortalProps> = ({
|
||||
setInputMessage('');
|
||||
setIsTyping(true);
|
||||
|
||||
const aiResponseText = await getSupportResponse(
|
||||
userMsg.content,
|
||||
chatMessages.map(m => m.content).slice(-5),
|
||||
articles
|
||||
);
|
||||
const apiKey = settings.aiConfig.apiKey;
|
||||
|
||||
// Check if API Key exists before calling service
|
||||
let aiResponseText = '';
|
||||
if (!apiKey) {
|
||||
aiResponseText = "L'assistente AI non è disponibile al momento (Configurazione incompleta).";
|
||||
} else {
|
||||
aiResponseText = await getSupportResponse(
|
||||
apiKey,
|
||||
userMsg.content,
|
||||
chatMessages.map(m => m.content).slice(-5),
|
||||
articles
|
||||
);
|
||||
}
|
||||
|
||||
const aiMsg: ChatMessage = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
|
||||
Reference in New Issue
Block a user