tango-app-api-audio-analytics 1.0.24 → 1.0.26

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audio-analytics",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "audioAnalytics",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,6 +24,7 @@
24
24
  "mongodb": "^6.21.0",
25
25
  "nodemon": "^3.1.14",
26
26
  "tango-api-schema": "^2.5.62",
27
+ "tango-app-api-audio-analytics": "^1.0.24",
27
28
  "tango-app-api-middleware": "^3.6.18",
28
29
  "winston": "^3.19.0",
29
30
  "winston-daily-rotate-file": "^5.0.0"
@@ -458,6 +458,7 @@ Only return the JSON array, no other text.`;
458
458
  const CHAT_STREAM_API = 'http://65.2.124.154:8000/api/chat/stream';
459
459
  const AUDIO_STREAM_API = 'http://65.2.124.154:8000/api/chat/audio';
460
460
  const EYE_TEST_STREAM_API = 'http://65.2.124.154:8000/api/chat/pet';
461
+ // const CONVERSATION_STREAM_API = 'http://65.2.124.154:8000/api/chat/audio';
461
462
 
462
463
 
463
464
  /**
@@ -562,7 +563,7 @@ export async function aiStreamResponse( req, res ) {
562
563
  };
563
564
  /* eslint-enable camelcase */
564
565
 
565
- const response = await fetch( analyticsType === 'audio'? AUDIO_STREAM_API: analyticsType === 'eyetest'? EYE_TEST_STREAM_API: CHAT_STREAM_API, {
566
+ const response = await fetch( analyticsType === 'audio'? AUDIO_STREAM_API:analyticsType === 'transcript'? AUDIO_STREAM_API: analyticsType === 'eyetest'? EYE_TEST_STREAM_API: CHAT_STREAM_API, {
566
567
  method: 'POST',
567
568
  headers: {
568
569
  'Content-Type': 'application/json',
@@ -4,6 +4,7 @@ import {
4
4
  getConversationsListFromLambda,
5
5
  exportConversationsFromLambda,
6
6
  getConversationDetailsFromLambda,
7
+ getTranscriptListFromLambda,
7
8
  // filterConversationsBySearch,
8
9
  // sortConversations,
9
10
  } from '../services/conversation.service.js';
@@ -158,7 +159,115 @@ export const getConversationsList = async ( req, res ) => {
158
159
  } );
159
160
  }
160
161
  };
162
+ /**
163
+ * Get Transcript Analysis List
164
+ * POST /Transcripts/list
165
+ * @param {Object} req - Express request object
166
+ * @param {Object} req.body - Request body with query parameters
167
+ * @param {string} req.body.startDate - Start date for filtering
168
+ * @param {string} req.body.endDate - End date for filtering
169
+ * @param {string[]} req.body.storeId - Array of store IDs for filtering
170
+ * @param {string[]} req.body.clientId - Optional array of client IDs
171
+ * @param {boolean} req.body.isAI - Filter for AI Transcripts
172
+ * @param {string} req.body.analyticsType - Type of analytics (audio, text, all)
173
+ * @param {string} req.body.searchValue - Search term for filtering
174
+ * @param {number} req.body.limit - Pagination limit
175
+ * @param {number} req.body.offset - Pagination offset
176
+ * @param {boolean} req.body.isExport - Flag to export as CSV
177
+ * @param {Object} res - Express response object
178
+ * @return {void} Returns JSON response with Transcripts list or CSV file
179
+ */
180
+ export const getTranscriptsList = async ( req, res ) => {
181
+ try {
182
+ const {
183
+ startDate,
184
+ endDate,
185
+ storeId,
186
+ clientId,
187
+ cohortType,
188
+ isAI,
189
+ analyticsType,
190
+ searchValue,
191
+ limit,
192
+ offset,
193
+ isExport,
194
+ _id,
195
+ name,
196
+ } = req.body;
197
+
198
+ // Validation
199
+ if ( !startDate || !endDate || !storeId ) {
200
+ return res.status( 400 ).json( {
201
+ status: 'error',
202
+ message: 'Missing required parameters: startDate, endDate, storeId',
203
+ code: 'MISSING_PARAMETERS',
204
+ timestamp: new Date().toISOString(),
205
+ } );
206
+ }
207
+
208
+ logger.info( {
209
+ message: 'Fetching Transcripts list',
210
+ startDate,
211
+ endDate,
212
+ storeId,
213
+ isExport,
214
+ } );
161
215
 
216
+ // let Transcripts;
217
+ // let totalCount;
218
+
219
+
220
+ // Call Lambda to get Transcripts (non-export)
221
+ const lambdaResponse = await getTranscriptListFromLambda( {
222
+ startDate,
223
+ endDate,
224
+ storeId,
225
+ clientId,
226
+ cohortType,
227
+ isAI,
228
+ analyticsType,
229
+ searchValue,
230
+ limit,
231
+ offset,
232
+ _id,
233
+ name,
234
+ } );
235
+ // Transcripts = lambdaResponse.Transcripts || [];
236
+ // totalCount = lambdaResponse.totalCount || Transcripts.length;
237
+
238
+ // // Apply search filter if provided
239
+ // if ( searchValue ) {
240
+ // Transcripts = filterTranscriptsBySearch( Transcripts, searchValue );
241
+ // }
242
+
243
+ // // Apply sorting
244
+ // Transcripts = sortTranscripts( Transcripts, 'date', 'desc' );
245
+
246
+ // Return paginated JSON response
247
+ return res.status( 200 ).json( {
248
+ status: 'success',
249
+ data: lambdaResponse,
250
+ // {
251
+ // result: lambdaResponse,
252
+ // pagination: {
253
+ // limit,
254
+ // offset,
255
+ // total: totalCount,
256
+ // hasMore: ( offset + limit ) < totalCount,
257
+ // },
258
+ // },
259
+ timestamp: new Date().toISOString(),
260
+ } );
261
+ } catch ( error ) {
262
+ logger.error( { error, message: 'Error fetching Transcripts list', body: req.body } );
263
+ return res.status( 500 ).json( {
264
+ status: 'error',
265
+ message: error.message || 'Internal server error',
266
+ code: 'INTERNAL_ERROR',
267
+ timestamp: new Date().toISOString(),
268
+ } );
269
+ }
270
+ };
162
271
  /**
163
272
  * Get Single Conversation Details
164
273
  * POST /conversations/:conversationId
@@ -527,6 +527,23 @@ export const conversationsListValid = joi.object( {
527
527
  offset: joi.number().integer().min( 0 ).optional().default( 0 ).description( 'Pagination offset' ),
528
528
  } ).strict();
529
529
 
530
+ /**
531
+ * Transcript List Schema
532
+ */
533
+ export const transcriptListValid = joi.object( {
534
+ startDate: joi.string().required().pattern( /^\d{4}-\d{2}-\d{2}$/ ).description( 'Start date in YYYY-MM-DD format' ),
535
+ endDate: joi.string().required().pattern( /^\d{4}-\d{2}-\d{2}$/ ).description( 'End date in YYYY-MM-DD format' ),
536
+ storeId: joi.array().items( joi.string() ).required().min( 1 ).description( 'Array of store IDs' ),
537
+ clientId: joi.array().items( joi.string() ).optional().description( 'Array of client IDs' ),
538
+ cohortType: joi.array().items( joi.string() ).required().min( 1 ).description( 'Array of cohort types' ),
539
+ isAI: joi.boolean().optional().description( 'Filter for AI-generated conversations' ),
540
+ analyticsType: joi.string().optional().valid( 'audio', 'text', 'all' ).description( 'Type of analytics' ),
541
+ searchValue: joi.string().optional().description( 'Search term' ),
542
+ isExport: joi.boolean().optional().description( 'Flag to export as CSV' ),
543
+ limit: joi.number().integer().min( 1 ).max( 1000 ).optional().default( 10 ).description( 'Pagination limit' ),
544
+ offset: joi.number().integer().min( 0 ).optional().default( 0 ).description( 'Pagination offset' ),
545
+ } ).strict();
546
+
530
547
  /**
531
548
  * Conversation Details Schema
532
549
  */
@@ -2,10 +2,10 @@
2
2
  import express from 'express';
3
3
  import { validate } from 'tango-app-api-middleware';
4
4
  import { createCohortValid, createBulkCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid, deleteCohortValid } from '../dtos/audioAnalytics.dtos.js';
5
- import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatHistoryListValid, getChatValid, getGeminiResponseValid } from '../dtos/audioAnalytics.dtos.js';
5
+ import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatHistoryListValid, getChatValid, getGeminiResponseValid, transcriptListValid } from '../dtos/audioAnalytics.dtos.js';
6
6
  import { createCohort, createBulkCohort, updateCohort, deleteCohort, getCohort, listCohortsByClient, chatHistoryList, getChat, getGeminiResponse, aiStreamResponse } from '../controllers/audioAnalytics.controller.js';
7
7
  import { getCohortAnalysisCard } from '../controllers/cohortAnalytics.controller.js';
8
- import { getConversationsList, getConversationDetails } from '../controllers/conversationAnalytics.controller.js';
8
+ import { getConversationsList, getTranscriptsList, getConversationDetails } from '../controllers/conversationAnalytics.controller.js';
9
9
 
10
10
  export const audioAnalyticsrouter = express.Router(); ;
11
11
 
@@ -30,6 +30,7 @@ audioAnalyticsrouter.post( '/cohort-analysis-card', validate( cohortAnalysisCard
30
30
 
31
31
  // Conversation Analytics Routes
32
32
  audioAnalyticsrouter.post( '/conversations/list', validate( conversationsListValid ), getConversationsList );
33
+ audioAnalyticsrouter.post( '/transcript/list', validate( transcriptListValid ), getTranscriptsList );
33
34
  audioAnalyticsrouter.post( '/conversations/:conversationId', validate( conversationDetailsValid ), getConversationDetails );
34
35
 
35
36
 
@@ -93,6 +93,51 @@ export async function getConversationsListFromLambda( params ) {
93
93
  }
94
94
  }
95
95
 
96
+ /**
97
+ * Call Lambda to get transcript list
98
+ * @param {Object} params - Request parameters
99
+ * @param {string} params.startDate - Start date (YYYY-MM-DD)
100
+ * @param {string} params.endDate - End date (YYYY-MM-DD)
101
+ * @param {string[]} params.storeId - Array of store IDs
102
+ * @param {string[]} params.clientId - Array of client IDs
103
+ * @param {boolean} params.isAI - Filter for AI conversations
104
+ * @param {string} params.analyticsType - Type of analytics
105
+ * @param {string} params.searchValue - Search term
106
+ * @param {number} params.limit - Pagination limit
107
+ * @param {number} params.offset - Pagination offset
108
+ * @return {Promise<Object>} Response from Lambda
109
+ */
110
+ export async function getTranscriptListFromLambda( params ) {
111
+ try {
112
+ const LAMBDA_ENDPOINT = JSON.parse( process.env.URL ) || 'http://lambda-api:8000';
113
+ logger.info( { message: 'Calling Lambda for transcript list', params } );
114
+ const payload = {
115
+ startDate: params.startDate,
116
+ endDate: params.endDate,
117
+ storeId: params.storeId,
118
+ clientId: params.clientId,
119
+ cohort_id: params?.cohortType?.[0],
120
+ _id: params?._id,
121
+ name: params?.name,
122
+ isAI: params.isAI,
123
+ analyticsType: params.analyticsType,
124
+ searchValue: params.searchValue,
125
+ limit: params.limit,
126
+ offset: params.offset,
127
+ };
128
+ console.log( LAMBDA_ENDPOINT.transcriptList, payload );
129
+ const response = await axios.post( `${LAMBDA_ENDPOINT.transcriptList}`, payload, {
130
+ timeout: 30000,
131
+ } );
132
+
133
+ logger.info( { message: 'Lambda response received for transcript list', payload, totalCount: response } );
134
+ return response.data;
135
+ } catch ( error ) {
136
+ logger.error( { error, message: 'Error calling Lambda for transcript list', params } );
137
+ throw new Error( `Failed to fetch transcript list: ${error.message}` );
138
+ }
139
+ }
140
+
96
141
  /**
97
142
  * Call Lambda to get conversations for export
98
143
  * @param {Object} params - Request parameters