# Pull Request Template ## Description This PR adds support for exporting conversation summary reports as CSV. Previously, the Conversations report incorrectly showed an option to download agent reports; this has now been fixed to export conversation-level data instead. Fixes https://linear.app/chatwoot/issue/CW-6176/conversation-reports-export-button-exports-agent-reports-instead ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ### Screenshot <img width="1859" height="1154" alt="image" src="https://github.com/user-attachments/assets/419d26f4-fda9-4782-aea6-55ffad0c37ab" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
114 lines
2.7 KiB
JavaScript
114 lines
2.7 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 } = {}) {
|
|
return axios.get(`${this.url}/bot_metrics`, {
|
|
params: { since: from, until: to },
|
|
});
|
|
}
|
|
|
|
getBotSummary({ from, to, groupBy, businessHours } = {}) {
|
|
return axios.get(`${this.url}/bot_summary`, {
|
|
params: {
|
|
since: from,
|
|
until: to,
|
|
type: 'account',
|
|
group_by: groupBy,
|
|
business_hours: businessHours,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export default new ReportsAPI();
|