Adiciona widget de chat flutuante global
- Widget no canto inferior direito em todas as paginas - Mostra sessoes de chat ativas do agente - Suporta multiplas sessoes com seletor - Badge com contador de mensagens nao lidas - Pode minimizar ou fechar - Query listAgentSessions para buscar sessoes ativas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2a78d14a74
commit
8c465008bf
4 changed files with 360 additions and 1 deletions
|
|
@ -510,3 +510,45 @@ export const getTicketSession = query({
|
|||
}
|
||||
},
|
||||
})
|
||||
|
||||
// Listar sessoes ativas de um agente (para widget flutuante)
|
||||
export const listAgentSessions = query({
|
||||
args: {
|
||||
agentId: v.id("users"),
|
||||
},
|
||||
handler: async (ctx, { agentId }) => {
|
||||
const agent = await ctx.db.get(agentId)
|
||||
if (!agent) {
|
||||
return []
|
||||
}
|
||||
|
||||
// Buscar todas as sessoes ativas do tenant do agente
|
||||
const sessions = await ctx.db
|
||||
.query("liveChatSessions")
|
||||
.withIndex("by_tenant_status", (q) =>
|
||||
q.eq("tenantId", agent.tenantId).eq("status", "ACTIVE")
|
||||
)
|
||||
.collect()
|
||||
|
||||
// Buscar detalhes dos tickets
|
||||
const result = await Promise.all(
|
||||
sessions.map(async (session) => {
|
||||
const ticket = await ctx.db.get(session.ticketId)
|
||||
return {
|
||||
ticketId: session.ticketId,
|
||||
ticketRef: ticket?.reference ?? 0,
|
||||
ticketSubject: ticket?.subject ?? "",
|
||||
sessionId: session._id,
|
||||
agentId: session.agentId,
|
||||
agentName: session.agentSnapshot?.name ?? "Agente",
|
||||
unreadCount: session.unreadByAgent ?? 0,
|
||||
lastActivityAt: session.lastActivityAt,
|
||||
startedAt: session.startedAt,
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// Ordenar por ultima atividade (mais recente primeiro)
|
||||
return result.sort((a, b) => b.lastActivityAt - a.lastActivityAt)
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue