Hoje as métricas e séries do BotReports agregam toda a conta — não dá pra ver "a Jasmine da PrimeAL está errando mais que a do Qnn01". Cada unidade tem prompt próprio, então um sintoma localizado precisa de medição localizada. Backend: - Inbox#has_many :reporting_events (relação inversa que faltava) - BotMetricsBuilder aceita inbox_id e filtra bot_conversations + base_reporting_events - bot_metrics endpoint passa inbox_id pelos params permitidos - count_report_builder já suporta scope=inbox; agora funciona pra bot_resolutions_count e bot_handoffs_count graças à relação acima Frontend: - BotReports.vue: ReportFilters com filter-type='inboxes' e dropdown ativo - Quando uma inbox é escolhida, requestPayload inclui inboxId/type/id e os fetches (BotMetrics + ReportContainer) passam o filtro - API client getBotMetrics aceita inboxId; getBotSummary aceita type+id - Sem inbox selecionada: comportamento antigo (agregação da conta) Bonus na rake task de retroativo: - rebuild_bot_resolved.rake: Message.unscope(:order) pra evitar conflito PG::InvalidColumnReference (DISTINCT + ORDER BY default scope) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
127 lines
3.1 KiB
JavaScript
127 lines
3.1 KiB
JavaScript
/* global axios */
|
|
import ApiClient from './ApiClient';
|
|
|
|
const getTimeOffset = () => -new Date().getTimezoneOffset() / 60;
|
|
|
|
class ReportsAPI extends ApiClient {
|
|
constructor() {
|
|
super('reports', { accountScoped: true, apiVersion: 'v2' });
|
|
}
|
|
|
|
getReports({
|
|
metric,
|
|
from,
|
|
to,
|
|
type = 'account',
|
|
id,
|
|
groupBy,
|
|
businessHours,
|
|
}) {
|
|
return axios.get(`${this.url}`, {
|
|
params: {
|
|
metric,
|
|
since: from,
|
|
until: to,
|
|
type,
|
|
id,
|
|
group_by: groupBy,
|
|
business_hours: businessHours,
|
|
timezone_offset: getTimeOffset(),
|
|
},
|
|
});
|
|
}
|
|
|
|
// eslint-disable-next-line default-param-last
|
|
getSummary(since, until, type = 'account', id, groupBy, businessHours) {
|
|
return axios.get(`${this.url}/summary`, {
|
|
params: {
|
|
since,
|
|
until,
|
|
type,
|
|
id,
|
|
group_by: groupBy,
|
|
business_hours: businessHours,
|
|
timezone_offset: getTimeOffset(),
|
|
},
|
|
});
|
|
}
|
|
|
|
getConversationMetric(type = 'account', page = 1) {
|
|
return axios.get(`${this.url}/conversations`, {
|
|
params: {
|
|
type,
|
|
page,
|
|
},
|
|
});
|
|
}
|
|
|
|
getAgentReports({ from: since, to: until, businessHours }) {
|
|
return axios.get(`${this.url}/agents`, {
|
|
params: { since, until, business_hours: businessHours },
|
|
});
|
|
}
|
|
|
|
getConversationsSummaryReports({ from: since, to: until, businessHours }) {
|
|
return axios.get(`${this.url}/conversations_summary`, {
|
|
params: { since, until, business_hours: businessHours },
|
|
});
|
|
}
|
|
|
|
getConversationTrafficCSV({ daysBefore = 6 } = {}) {
|
|
return axios.get(`${this.url}/conversation_traffic`, {
|
|
params: { timezone_offset: getTimeOffset(), days_before: daysBefore },
|
|
});
|
|
}
|
|
|
|
getLabelReports({ from: since, to: until, businessHours }) {
|
|
return axios.get(`${this.url}/labels`, {
|
|
params: { since, until, business_hours: businessHours },
|
|
});
|
|
}
|
|
|
|
getInboxReports({ from: since, to: until, businessHours }) {
|
|
return axios.get(`${this.url}/inboxes`, {
|
|
params: { since, until, business_hours: businessHours },
|
|
});
|
|
}
|
|
|
|
getTeamReports({ from: since, to: until, businessHours }) {
|
|
return axios.get(`${this.url}/teams`, {
|
|
params: { since, until, business_hours: businessHours },
|
|
});
|
|
}
|
|
|
|
getBotMetrics({ from, to, inboxId } = {}) {
|
|
return axios.get(`${this.url}/bot_metrics`, {
|
|
params: { since: from, until: to, inbox_id: inboxId },
|
|
});
|
|
}
|
|
|
|
getBotSummary({ from, to, groupBy, businessHours, type, id } = {}) {
|
|
return axios.get(`${this.url}/bot_summary`, {
|
|
params: {
|
|
since: from,
|
|
until: to,
|
|
type: type || 'account',
|
|
id,
|
|
group_by: groupBy,
|
|
business_hours: businessHours,
|
|
},
|
|
});
|
|
}
|
|
|
|
getInboxLeadsSummary({ inboxId, from, to, groupBy } = {}) {
|
|
return axios.get(`${this.url}/inbox_leads_summary`, {
|
|
params: {
|
|
inbox_id: inboxId,
|
|
since: from,
|
|
until: to,
|
|
group_by: groupBy,
|
|
timezone_offset: getTimeOffset(),
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export default new ReportsAPI();
|