omnichannel-frontend/src/modules/chat/services/agentPresenceService.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

import { API_BASE_URL } from '../../../shared/services/apiConfig';
async function request(path, options = {}) {
const response = await fetch(`${API_BASE_URL}${path}`, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
if (!response.ok) {
throw new Error('Falha ao atualizar presenca do agente');
}
return response.json();
}
export async function getAgentPresence(userId) {
return request(`/agent/presence/me?userId=${encodeURIComponent(userId)}`);
}
export async function listAgentPresence() {
return request('/agent/presence');
}
export async function pauseAgent(userId) {
return request('/agent/presence/pause', {
method: 'POST',
body: JSON.stringify({ userId }),
});
}
export async function resumeAgent(userId) {
return request('/agent/presence/resume', {
method: 'POST',
body: JSON.stringify({ userId }),
});
}
export async function markAgentOffline(userId) {
return request('/agent/presence/offline', {
method: 'POST',
body: JSON.stringify({ userId }),
});
}