diff --git a/app/javascript/dashboard/store/modules/reports.js b/app/javascript/dashboard/store/modules/reports.js
index 99b2acf18..bb62a9b17 100644
--- a/app/javascript/dashboard/store/modules/reports.js
+++ b/app/javascript/dashboard/store/modules/reports.js
@@ -234,6 +234,19 @@ export const actions = {
console.error(error);
});
},
+ downloadConversationsSummaryReports(_, reportObj) {
+ return Report.getConversationsSummaryReports(reportObj)
+ .then(response => {
+ downloadCsvFile(reportObj.fileName, response.data);
+ AnalyticsHelper.track(REPORTS_EVENTS.DOWNLOAD_REPORT, {
+ reportType: 'conversations_summary',
+ businessHours: reportObj?.businessHours,
+ });
+ })
+ .catch(error => {
+ console.error(error);
+ });
+ },
downloadLabelReports(_, reportObj) {
return Report.getLabelReports(reportObj)
.then(response => {
diff --git a/app/javascript/dashboard/store/modules/specs/reports/actions.spec.js b/app/javascript/dashboard/store/modules/specs/reports/actions.spec.js
index 41e5a1d79..1a6cd99e8 100644
--- a/app/javascript/dashboard/store/modules/specs/reports/actions.spec.js
+++ b/app/javascript/dashboard/store/modules/specs/reports/actions.spec.js
@@ -201,4 +201,24 @@ describe('#actions', () => {
);
});
});
+
+ describe('#downloadConversationsSummaryReports', () => {
+ it('open CSV download prompt if API is success', async () => {
+ const data = `Conversations,Messages received,Messages sent,Avg first response time,Avg resolution time,Resolution count,Avg customer waiting time
+ 217,323,623,23 hours 22 minutes,179 days 18 hours,30,48 days 4 hours`;
+ axios.get.mockResolvedValue({ data });
+ const param = {
+ from: 1631039400,
+ to: 1635013800,
+ fileName: 'conversations-summary-report-24-10-2021.csv',
+ };
+ actions.downloadConversationsSummaryReports(1, param);
+ await flushPromises();
+
+ expect(DownloadHelper.downloadCsvFile).toBeCalledWith(
+ param.fileName,
+ data
+ );
+ });
+ });
});
diff --git a/app/views/api/v2/accounts/reports/conversations_summary.csv.erb b/app/views/api/v2/accounts/reports/conversations_summary.csv.erb
new file mode 100644
index 000000000..5055739b6
--- /dev/null
+++ b/app/views/api/v2/accounts/reports/conversations_summary.csv.erb
@@ -0,0 +1,16 @@
+<%= CSVSafe.generate_line [I18n.t('reports.period', since: Date.strptime(params[:since], '%s'), until: Date.strptime(params[:until], '%s'))] %>
+
+<% headers = [
+ I18n.t('reports.conversation_csv.conversations_count'),
+ I18n.t('reports.conversation_csv.incoming_messages_count'),
+ I18n.t('reports.conversation_csv.outgoing_messages_count'),
+ I18n.t('reports.conversation_csv.avg_first_response_time'),
+ I18n.t('reports.conversation_csv.avg_resolution_time'),
+ I18n.t('reports.conversation_csv.resolution_count'),
+ I18n.t('reports.conversation_csv.avg_customer_waiting_time')
+]
+%>
+<%= CSVSafe.generate_line headers -%>
+<% @report_data.each do |row| %>
+<%= CSVSafe.generate_line row -%>
+<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d9ca2f1be..bacd007bb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -172,6 +172,14 @@ en:
avg_resolution_time: Avg resolution time
resolution_count: Resolution Count
avg_customer_waiting_time: Avg customer waiting time
+ conversation_csv:
+ conversations_count: Conversations
+ incoming_messages_count: Messages received
+ outgoing_messages_count: Messages sent
+ avg_first_response_time: Avg first response time
+ avg_resolution_time: Avg resolution time
+ resolution_count: Resolution count
+ avg_customer_waiting_time: Avg customer waiting time
conversation_traffic_csv:
timezone: Timezone
sla_csv:
diff --git a/config/routes.rb b/config/routes.rb
index aa06d8f09..bdc8e4fe6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -430,6 +430,7 @@ Rails.application.routes.draw do
get :labels
get :teams
get :conversations
+ get :conversations_summary
get :conversation_traffic
get :bot_metrics
end