tango-app-api-audio-analytics 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/controllers/audioAnalytics.controller.js +45 -0
- package/src/controllers/conversationAnalytics.controller.js +9 -11
- package/src/dtos/audioAnalytics.dtos.js +14 -0
- package/src/routes/audioAnalytics.routes.js +3 -2
- package/src/services/conversation.service.js +9 -7
package/package.json
CHANGED
|
@@ -45,6 +45,51 @@ export async function createCohort( req, res ) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
export async function createBulkCohort( req, res ) {
|
|
49
|
+
try {
|
|
50
|
+
const { clientId, cohorts } = req.body;
|
|
51
|
+
|
|
52
|
+
const results = [];
|
|
53
|
+
const failed = [];
|
|
54
|
+
|
|
55
|
+
for ( const cohortItem of cohorts ) {
|
|
56
|
+
const cohortId = `cohort_${clientId}_${randomUUID()}`;
|
|
57
|
+
|
|
58
|
+
const cohortData = {
|
|
59
|
+
clientId,
|
|
60
|
+
cohortId,
|
|
61
|
+
source: [],
|
|
62
|
+
cohortName: cohortItem.cohortName,
|
|
63
|
+
cohortDescription: cohortItem.cohortDescription,
|
|
64
|
+
metrics: [],
|
|
65
|
+
createdAt: new Date().toISOString(),
|
|
66
|
+
updatedAt: new Date().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const result = await insertWithId( 'tango-audio-config', cohortId, cohortData );
|
|
70
|
+
logger.info( { result } );
|
|
71
|
+
|
|
72
|
+
if ( result && result.body && result.body.result === 'created' ) {
|
|
73
|
+
results.push( { cohortId, cohortName: cohortItem.cohortName } );
|
|
74
|
+
} else {
|
|
75
|
+
failed.push( { cohortName: cohortItem.cohortName, reason: 'Insert failed' } );
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return res.sendSuccess( {
|
|
80
|
+
message: 'Bulk cohort creation completed',
|
|
81
|
+
created: results,
|
|
82
|
+
failed,
|
|
83
|
+
totalCreated: results.length,
|
|
84
|
+
totalFailed: failed.length,
|
|
85
|
+
} );
|
|
86
|
+
} catch ( error ) {
|
|
87
|
+
const err = error.message || 'Internal Server Error';
|
|
88
|
+
logger.error( { error: error, message: req.body, function: 'createBulkCohort' } );
|
|
89
|
+
return res.sendError( err, 500 );
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
48
93
|
export async function updateCohort( req, res ) {
|
|
49
94
|
try {
|
|
50
95
|
const { cohortId, ...updateFields } = req.body;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// import { sampleConversationData, sampleConversationsList } from '../models/conversationAnalysis.model.js';
|
|
2
|
-
import { logger } from 'tango-app-api-middleware';
|
|
2
|
+
import { logger, downloadint } from 'tango-app-api-middleware';
|
|
3
3
|
import {
|
|
4
4
|
getConversationsListFromLambda,
|
|
5
5
|
exportConversationsFromLambda,
|
|
6
6
|
getConversationDetailsFromLambda,
|
|
7
|
-
exportConversationsToCSV,
|
|
8
7
|
// filterConversationsBySearch,
|
|
9
8
|
// sortConversations,
|
|
10
9
|
} from '../services/conversation.service.js';
|
|
@@ -34,7 +33,7 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
34
33
|
endDate,
|
|
35
34
|
storeId,
|
|
36
35
|
clientId,
|
|
37
|
-
|
|
36
|
+
cohortType,
|
|
38
37
|
isAI,
|
|
39
38
|
analyticsType,
|
|
40
39
|
searchValue,
|
|
@@ -61,7 +60,7 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
61
60
|
isExport,
|
|
62
61
|
} );
|
|
63
62
|
|
|
64
|
-
let conversations;
|
|
63
|
+
// let conversations;
|
|
65
64
|
// let totalCount;
|
|
66
65
|
|
|
67
66
|
// If export is requested, call the export Lambda function
|
|
@@ -72,7 +71,7 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
72
71
|
endDate,
|
|
73
72
|
storeId,
|
|
74
73
|
clientId,
|
|
75
|
-
|
|
74
|
+
cohortType,
|
|
76
75
|
isExport,
|
|
77
76
|
limit,
|
|
78
77
|
offset,
|
|
@@ -83,7 +82,7 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
83
82
|
|
|
84
83
|
logger.info( {
|
|
85
84
|
message: 'Export Lambda response received',
|
|
86
|
-
recordCount:
|
|
85
|
+
recordCount: exportResponse.data.length,
|
|
87
86
|
} );
|
|
88
87
|
|
|
89
88
|
// Apply search filter if provided
|
|
@@ -94,11 +93,9 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
94
93
|
// // Apply sorting
|
|
95
94
|
// conversations = sortConversations( conversations, 'date', 'desc' );
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
res.setHeader( 'Content-Disposition', 'attachment; filename=conversations.csv' );
|
|
101
|
-
return res.send( csv );
|
|
96
|
+
res.setHeader( 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
|
|
97
|
+
res.setHeader( 'Content-Disposition', `attachment; filename=conversations-${Date.now()}.xlsx` );
|
|
98
|
+
return downloadint( exportResponse.data, res );
|
|
102
99
|
} catch ( error ) {
|
|
103
100
|
logger.error( { error, message: 'Error in export Lambda call', body: req.body } );
|
|
104
101
|
throw error;
|
|
@@ -111,6 +108,7 @@ export const getConversationsList = async ( req, res ) => {
|
|
|
111
108
|
endDate,
|
|
112
109
|
storeId,
|
|
113
110
|
clientId,
|
|
111
|
+
cohortType,
|
|
114
112
|
isAI,
|
|
115
113
|
analyticsType,
|
|
116
114
|
searchValue,
|
|
@@ -588,6 +588,20 @@ export const createCohortValid = {
|
|
|
588
588
|
body: createCohortSchema,
|
|
589
589
|
};
|
|
590
590
|
|
|
591
|
+
const bulkCohortItemSchema = joi.object( {
|
|
592
|
+
cohortName: joi.string().required(),
|
|
593
|
+
cohortDescription: joi.string().required(),
|
|
594
|
+
} );
|
|
595
|
+
|
|
596
|
+
export const createBulkCohortSchema = joi.object( {
|
|
597
|
+
clientId: joi.string().required(),
|
|
598
|
+
cohorts: joi.array().items( bulkCohortItemSchema ).min( 1 ).required(),
|
|
599
|
+
} );
|
|
600
|
+
|
|
601
|
+
export const createBulkCohortValid = {
|
|
602
|
+
body: createBulkCohortSchema,
|
|
603
|
+
};
|
|
604
|
+
|
|
591
605
|
const cohortUpdateMetricSchema = joi.object( {
|
|
592
606
|
metricName: joi.string().required(),
|
|
593
607
|
metricDescription: joi.string().required(),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { createCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid } from '../dtos/audioAnalytics.dtos.js';
|
|
4
|
+
import { createCohortValid, createBulkCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid } from '../dtos/audioAnalytics.dtos.js';
|
|
5
5
|
import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatStreamValid } from '../dtos/audioAnalytics.dtos.js';
|
|
6
|
-
import { createCohort, updateCohort, getCohort, listCohortsByClient, chatStream } from '../controllers/audioAnalytics.controller.js';
|
|
6
|
+
import { createCohort, createBulkCohort, updateCohort, getCohort, listCohortsByClient, chatStream } from '../controllers/audioAnalytics.controller.js';
|
|
7
7
|
import { getCohortAnalysisCard } from '../controllers/cohortAnalytics.controller.js';
|
|
8
8
|
import { getConversationsList, getConversationDetails } from '../controllers/conversationAnalytics.controller.js';
|
|
9
9
|
|
|
@@ -17,6 +17,7 @@ audioAnalyticsrouter.get( '/test', ( req, res ) => {
|
|
|
17
17
|
|
|
18
18
|
// Cohort Management Routes
|
|
19
19
|
audioAnalyticsrouter.post( '/create-cohort', validate( createCohortValid ), createCohort );
|
|
20
|
+
audioAnalyticsrouter.post( '/create-bulk-cohort', validate( createBulkCohortValid ), createBulkCohort );
|
|
20
21
|
audioAnalyticsrouter.post( '/update-cohort', validate( updateCohortValid ), updateCohort );
|
|
21
22
|
audioAnalyticsrouter.get( '/get-cohort/:cohortId', validate( getCohortValid ), getCohort );
|
|
22
23
|
audioAnalyticsrouter.get( '/list-cohorts', validate( listCohortsByClientValid ), listCohortsByClient );
|
|
@@ -72,6 +72,7 @@ export async function getConversationsListFromLambda( params ) {
|
|
|
72
72
|
endDate: params.endDate,
|
|
73
73
|
storeId: params.storeId,
|
|
74
74
|
clientId: params.clientId,
|
|
75
|
+
cohort_id: params.cohortType,
|
|
75
76
|
isAI: params.isAI,
|
|
76
77
|
analyticsType: params.analyticsType,
|
|
77
78
|
searchValue: params.searchValue,
|
|
@@ -108,17 +109,18 @@ export async function exportConversationsFromLambda( params ) {
|
|
|
108
109
|
const payload = {
|
|
109
110
|
startDate: params.startDate,
|
|
110
111
|
endDate: params.endDate,
|
|
111
|
-
|
|
112
|
-
clientId: Array.isArray( params.clientId ) ? params.clientId : [ params.clientId ],
|
|
113
|
-
|
|
114
|
-
isExport: params.isExport ?? true,
|
|
115
|
-
limit: params.limit || 10,
|
|
116
|
-
offset: params.offset || 0,
|
|
112
|
+
store_id: Array.isArray( params.storeId ) ? params.storeId : [ params.storeId ],
|
|
113
|
+
// clientId: Array.isArray( params.clientId ) ? params.clientId : [ params.clientId ],
|
|
114
|
+
cohort_id: params.cohortType?.[0],
|
|
115
|
+
// isExport: params.isExport ?? true,
|
|
116
|
+
// limit: params.limit || 10,
|
|
117
|
+
// offset: params.offset || 0,
|
|
117
118
|
};
|
|
118
119
|
|
|
119
120
|
logger.info( { message: 'Calling Lambda for conversations export', url: LAMBDA_ENDPOINT.cohortConversationList, payload } );
|
|
120
121
|
|
|
121
|
-
const response = await axios.post( `${LAMBDA_ENDPOINT.
|
|
122
|
+
// const response = await axios.post( `${LAMBDA_ENDPOINT.cohortConversationExport}`, payload, {
|
|
123
|
+
const response = await axios.post( `https://p2wmglvvtfj7nh2pdzljaiidnm0beycj.lambda-url.ap-south-1.on.aws/`, payload, {
|
|
122
124
|
headers: {
|
|
123
125
|
'Content-Type': 'application/json',
|
|
124
126
|
},
|