Ir al contenido

Activar Disponibilidad

Marca al agente como disponible para recibir chats entrantes.

  1. En la barra superior del chat, cambia el estado a “Disponible”
  2. El sistema comenzará a asignar chats automáticamente
Detalles técnicos — Activar disponibilidad
// Servidor: Supabase Realtime channels
const chatChannel = supabase.channel(`chat:${sessionId}`)
.on('broadcast', { event: 'message' }, (payload) => {
appendMessage(payload.message);
})
.subscribe();
// Enviar mensaje
async function sendMessage(sessionId: string, content: string) {
await supabase.channel(`chat:${sessionId}`)
.send({
type: 'broadcast',
event: 'message',
payload: {
id: crypto.randomUUID(),
content,
sender_id: currentUser.id,
sender_name: currentUser.name,
timestamp: new Date().toISOString(),
}
});
// Persistir en DB
await supabase.from('chat_messages').insert({
session_id: sessionId,
sender_id: currentUser.id,
content,
type: 'text',
});
}
-- Función para asignar el agente con menos chats activos
CREATE OR REPLACE FUNCTION assign_chat_agent(p_team_id UUID)
RETURNS UUID AS $$
SELECT user_id FROM support_agent_status
WHERE team_id = p_team_id
AND status = 'available'
ORDER BY active_chats ASC, last_assigned_at ASC
LIMIT 1;
$$ LANGUAGE sql;