chat: remover placeholder [Anexo]
This commit is contained in:
parent
119ada60a6
commit
ce5ea5dad5
3 changed files with 42 additions and 21 deletions
|
|
@ -612,7 +612,7 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
setIsSending(true)
|
setIsSending(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bodyToSend = messageText || (attachmentsToSend.length > 0 ? "[Anexo]" : "")
|
const bodyToSend = messageText
|
||||||
const cfg = await ensureConfig()
|
const cfg = await ensureConfig()
|
||||||
await invoke("send_chat_message", {
|
await invoke("send_chat_message", {
|
||||||
baseUrl: cfg.apiBaseUrl,
|
baseUrl: cfg.apiBaseUrl,
|
||||||
|
|
@ -814,6 +814,9 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
// No desktop: isFromMachine=true significa mensagem do cliente (maquina)
|
// No desktop: isFromMachine=true significa mensagem do cliente (maquina)
|
||||||
// Layout igual à web: cliente à esquerda, agente à direita
|
// Layout igual à web: cliente à esquerda, agente à direita
|
||||||
const isAgent = !msg.isFromMachine
|
const isAgent = !msg.isFromMachine
|
||||||
|
const bodyText = msg.body.trim()
|
||||||
|
const shouldShowBody =
|
||||||
|
bodyText.length > 0 && !(bodyText === "[Anexo]" && (msg.attachments?.length ?? 0) > 0)
|
||||||
return (
|
return (
|
||||||
<div key={msg.id} className="space-y-2">
|
<div key={msg.id} className="space-y-2">
|
||||||
{firstUnreadAgentMessageId === msg.id && unreadCount > 0 && !isAtBottom && (
|
{firstUnreadAgentMessageId === msg.id && unreadCount > 0 && !isAtBottom && (
|
||||||
|
|
@ -856,7 +859,7 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
{msg.authorName}
|
{msg.authorName}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<p className="whitespace-pre-wrap text-sm">{msg.body}</p>
|
{shouldShowBody && <p className="whitespace-pre-wrap text-sm">{msg.body}</p>}
|
||||||
{/* Anexos */}
|
{/* Anexos */}
|
||||||
{msg.attachments && msg.attachments.length > 0 && (
|
{msg.attachments && msg.attachments.length > 0 && (
|
||||||
<div className="mt-2 space-y-2">
|
<div className="mt-2 space-y-2">
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,33 @@ const getMessagesSchema = z.object({
|
||||||
limit: z.number().optional(),
|
limit: z.number().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const postMessageSchema = z.object({
|
const postMessageSchema = z
|
||||||
machineToken: z.string().min(1),
|
.object({
|
||||||
ticketId: z.string().min(1),
|
machineToken: z.string().min(1),
|
||||||
body: z.string().min(1).max(4000),
|
ticketId: z.string().min(1),
|
||||||
attachments: z
|
body: z.string().max(4000).optional(),
|
||||||
.array(
|
attachments: z
|
||||||
z.object({
|
.array(
|
||||||
storageId: z.string(),
|
z.object({
|
||||||
name: z.string(),
|
storageId: z.string(),
|
||||||
size: z.number().optional(),
|
name: z.string(),
|
||||||
type: z.string().optional(),
|
size: z.number().optional(),
|
||||||
|
type: z.string().optional(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.superRefine((value, ctx) => {
|
||||||
|
const body = (value.body ?? "").trim()
|
||||||
|
const hasAttachments = (value.attachments?.length ?? 0) > 0
|
||||||
|
if (body.length === 0 && !hasAttachments) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "Mensagem vazia",
|
||||||
|
path: ["body"],
|
||||||
})
|
})
|
||||||
)
|
}
|
||||||
.optional(),
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const CORS_METHODS = "POST, OPTIONS"
|
const CORS_METHODS = "POST, OPTIONS"
|
||||||
|
|
||||||
|
|
@ -123,14 +135,18 @@ export async function POST(request: Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const body = (payload.body ?? "").trim()
|
||||||
|
const attachments =
|
||||||
|
payload.attachments && payload.attachments.length > 0 ? payload.attachments : undefined
|
||||||
|
|
||||||
// Retry com backoff exponencial para falhas transientes
|
// Retry com backoff exponencial para falhas transientes
|
||||||
const result = await withRetry(
|
const result = await withRetry(
|
||||||
() =>
|
() =>
|
||||||
client.mutation(api.liveChat.postMachineMessage, {
|
client.mutation(api.liveChat.postMachineMessage, {
|
||||||
machineToken: payload.machineToken,
|
machineToken: payload.machineToken,
|
||||||
ticketId: payload.ticketId as Id<"tickets">,
|
ticketId: payload.ticketId as Id<"tickets">,
|
||||||
body: payload.body,
|
body,
|
||||||
attachments: payload.attachments as
|
attachments: attachments as
|
||||||
| Array<{
|
| Array<{
|
||||||
storageId: Id<"_storage">
|
storageId: Id<"_storage">
|
||||||
name: string
|
name: string
|
||||||
|
|
|
||||||
|
|
@ -759,6 +759,10 @@ export function ChatWidget() {
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{messages.map((msg) => {
|
{messages.map((msg) => {
|
||||||
const isOwn = String(msg.authorId) === String(viewerId)
|
const isOwn = String(msg.authorId) === String(viewerId)
|
||||||
|
const bodyText = msg.body?.trim() ?? ""
|
||||||
|
const shouldShowBody =
|
||||||
|
bodyText.length > 0 &&
|
||||||
|
!(bodyText === "[Anexo]" && (msg.attachments?.length ?? 0) > 0)
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={msg.id}
|
key={msg.id}
|
||||||
|
|
@ -785,9 +789,7 @@ export function ChatWidget() {
|
||||||
{msg.authorName ?? "Cliente"}
|
{msg.authorName ?? "Cliente"}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{msg.body && (
|
{shouldShowBody && <p className="whitespace-pre-wrap text-sm">{msg.body}</p>}
|
||||||
<p className="whitespace-pre-wrap text-sm">{msg.body}</p>
|
|
||||||
)}
|
|
||||||
{/* Anexos da mensagem */}
|
{/* Anexos da mensagem */}
|
||||||
{msg.attachments && msg.attachments.length > 0 && (
|
{msg.attachments && msg.attachments.length > 0 && (
|
||||||
<div className={cn("mt-2 flex flex-wrap gap-1.5", isOwn && "justify-end")}>
|
<div className={cn("mt-2 flex flex-wrap gap-1.5", isOwn && "justify-end")}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue