|
| 1 | +/* |
| 2 | + * Your installation or use of this SugarCRM file is subject to the applicable |
| 3 | + * terms available at |
| 4 | + * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/. |
| 5 | + * If you do not agree to all of the applicable terms or do not have the |
| 6 | + * authority to bind the entity as an authorized representative, then do not |
| 7 | + * install or use this SugarCRM file. |
| 8 | + * |
| 9 | + * Copyright (C) SugarCRM Inc. All rights reserved. |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Utils |
| 14 | +*/ |
| 15 | +const chatUtils = require('../utils/sugar/chat-transcript-utils'); |
| 16 | +const comprehendUtils = require('../utils/aws/comprehend-utils'); |
| 17 | +const loggerUtils = require('../utils/logger-utils'); |
| 18 | +const s3Utils = require('../utils/aws/s3-utils'); |
| 19 | +const utils = require('../utils/utils'); |
| 20 | + |
| 21 | +/** |
| 22 | + * Function to update a call with transcript once the transcript is |
| 23 | + * uploaded to S3. |
| 24 | + * |
| 25 | + * @param {Object} event S3 Event that invokes this function |
| 26 | + */ |
| 27 | +const handler = async (event) => { |
| 28 | + // Log S3 Event to cloudwatch for debugging. |
| 29 | + loggerUtils.logS3Event(event); |
| 30 | + |
| 31 | + // Fetch and process transcript from s3 |
| 32 | + let transcript = await s3Utils.getJsonFromS3Event(event); |
| 33 | + console.log('Fetched Chat transcript: \n', transcript); |
| 34 | + |
| 35 | + let batchTranscript = utils.batchTrancsriptByParticipant(transcript); |
| 36 | + console.log('Batch Transcript: \n' + JSON.stringify(batchTranscript, null, 2)); |
| 37 | + let batchSentiment = await comprehendUtils.getBatchTranscriptByParticipant(batchTranscript); |
| 38 | + console.log('Batch Sentiment: \n' + JSON.stringify(batchSentiment, null, 2)); |
| 39 | + |
| 40 | + let stringTranscript = utils.stringTranscriptByParticipant(transcript); |
| 41 | + console.log('String Transcript: \n' + JSON.stringify(stringTranscript, null, 2)); |
| 42 | + let stringSentiment = await comprehendUtils.getStringTranscriptByParticipant(stringTranscript); |
| 43 | + console.log('String Sentiment: \n' + JSON.stringify(stringSentiment, null, 2)); |
| 44 | + |
| 45 | + let annotatedTranscript = chatUtils.createAnnotatedTrancsript(transcript, batchSentiment, stringSentiment); |
| 46 | + console.log('Annotated Transcript: \n' + JSON.stringify(transcript, null, 2)); |
| 47 | + |
| 48 | + return annotatedTranscript; |
| 49 | +}; |
| 50 | + |
| 51 | +exports.handler = handler; |
0 commit comments