Use only WS for machine chat subscriptions

This commit is contained in:
rever-tecnologia 2025-12-09 14:56:53 -03:00
parent d2108ce16b
commit 988bf25010
2 changed files with 26 additions and 127 deletions

View file

@ -179,6 +179,28 @@ export function TicketChatPanel({ ticketId }: TicketChatPanelProps) {
toast.error(`Mensagem muito longa (max. ${MAX_MESSAGE_LENGTH} caracteres).`)
return
}
// Garantir que a sessão de chat ao vivo exista antes de enviar
if (liveChat?.hasMachine && !hasActiveSession) {
try {
await startLiveChat({
ticketId: ticketId as Id<"tickets">,
actorId: viewerId as Id<"users">,
})
} catch (error: unknown) {
const message = (() => {
if (error instanceof Error) {
const errorMsg = error.message.toLowerCase()
if (errorMsg.includes("offline")) return "Máquina offline. Aguarde a máquina ficar online para iniciar o chat."
if (errorMsg.includes("não encontrad") || errorMsg.includes("not found")) return "Máquina não encontrada"
}
return "Não foi possível iniciar o chat ao vivo."
})()
toast.error(message, { id: "live-chat" })
return
}
}
setIsSending(true)
try {
await postChatMessage({