Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS-1264 Improved Logging to debug Lambda Functions #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
},
"scripts": {
"test": "jest --watchAll",
"lint": "eslint ./src ./__tests__"
"lint": "eslint --ext .js src/* __tests__/unit/* --fix"
Copy link
Contributor Author

@jwelborn-sugar jwelborn-sugar Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows us to auto-fix style errors before committing with npm run lint. All of the changes in this commit were from running this command

}
}
4 changes: 2 additions & 2 deletions src/constants/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Copyright (C) SugarCRM Inc. All rights reserved.
*/

module.exports = {
module.exports = {
/**
* URL Partials
*/
HTTPS_PREFIX: 'https://',
HTTPS_PREFIX: 'https://'
};
2 changes: 1 addition & 1 deletion src/core/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) SugarCRM Inc. All rights reserved.
*/

var Bean = require('./bean.js');
let Bean = require('./bean.js');

module.exports = {
createBean: (module, data) => {
Expand Down
15 changes: 7 additions & 8 deletions src/handlers/lex-get-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) SugarCRM Inc. All rights reserved.
*/

const loggerUtils = require("../utils/logger-utils");
const loggerUtils = require('../utils/logger-utils');

/**
* Close dialog with the customer, reporting fulfillmentState Fulfilled
Expand All @@ -24,34 +24,34 @@ function close(sessionAttributes, fulfillmentState, message) {
type: 'Close',
fulfillmentState,
message
},
}
};
}

/**
* Events
* @param intentRequest
* @param callback
*/
function dispatch(intentRequest, callback) {
const sessionAttributes = intentRequest.sessionAttributes;

// assign the whole user input to sessionAttributes.string
sessionAttributes.string = intentRequest.inputTranscript;

callback(
close(
sessionAttributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': 'You entered: ' + sessionAttributes.string

}
)
);
}

/**
* Main handler
* @param event
Expand All @@ -70,4 +70,3 @@ exports.handler = (event, context, callback) => {
callback(err);
}
};

14 changes: 7 additions & 7 deletions src/utils/logger-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
/**
* Log the JSON to AWS Cloudwatch
*
* @param {string} title
* @param {Object} json
* @param {string} title
* @param {Object} json
*/
function logJson (title, json) {
function logJson(title, json) {
console.log(`${title}:\n`, JSON.stringify(json));
}

Expand Down Expand Up @@ -59,18 +59,18 @@ function logReturnValue(returnValue) {
/**
* Log the S3 event for debugging
*
* @param {Object} event
* @param {Object} event
*/
function logS3Event (event) {
function logS3Event(event) {
logJson('S3 Event', event);
}

/**
* Log the Sugar API response for debugging
*
* @param {string} response
* @param {string} response
*/
function logSugarApiResponse (response) {
function logSugarApiResponse(response) {
logJson('Sugar API Response', response);
}

Expand Down
50 changes: 25 additions & 25 deletions src/utils/sugar/call-record-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const CallsConstants = require('../../constants/sugar-modules/calls');
const ErrorMessages = require('../../constants/messages/error');
const UrlConstants = require('../../constants/url');

/**
/**
* Return a single call record, false otherwise
*
* @param {string} contactId the AWS Connect contact ID
Expand Down Expand Up @@ -53,39 +53,39 @@ async function getCallRecord(contactId) {
* Build the call recording URL based on an AWS Connect URL and not S3. Appropriate
* AWS Connect user permissions are required to access the URL
*
* @param {string} contactId
* @param {string} contactId
*/
function buildCallRecordingUrl (contactId) {
let connectInstance = process.env.awsConnectInstance;
let connectDomain = process.env.awsConnectDomain;
let callRecordingPartialUrl = process.env.callRecordingPartialUrl;
function buildCallRecordingUrl(contactId) {
let connectInstance = process.env.awsConnectInstance;
let connectDomain = process.env.awsConnectDomain;
let callRecordingPartialUrl = process.env.callRecordingPartialUrl;

// return empty if contact ID is not defined
if (!contactId) {
console.warn('Call Recording URL Warning: Unable to construct a URL without AWS Connect contact ID');
return '';
}
// return empty if contact ID is not defined
if (!contactId) {
console.warn('Call Recording URL Warning: Unable to construct a URL without AWS Connect contact ID');
return '';
}

// return empty if one or more of the required parameters is not defined
if (!connectInstance || !connectDomain || !callRecordingPartialUrl) {
console.warn('Call Recording URL Warning: Unable to construct a URL with missing required parameter(s). ' +
// return empty if one or more of the required parameters is not defined
if (!connectInstance || !connectDomain || !callRecordingPartialUrl) {
console.warn('Call Recording URL Warning: Unable to construct a URL with missing required parameter(s). ' +
'Please check the following parameters: AwsConnectInstance, AWSConnectDomain, CallRecordingPartialURL');
return '';
}
return '';
}

let encodedConnectInstance = encodeURIComponent(connectInstance);
let encodedContactId = encodeURIComponent(contactId);
let encodedConnectInstance = encodeURIComponent(connectInstance);
let encodedContactId = encodeURIComponent(contactId);

connectDomain = connectDomain.trim();
callRecordingPartialUrl = callRecordingPartialUrl.trim();
connectDomain = connectDomain.trim();
callRecordingPartialUrl = callRecordingPartialUrl.trim();

let url = UrlConstants.HTTPS_PREFIX + encodedConnectInstance + '.' + connectDomain +
let url = UrlConstants.HTTPS_PREFIX + encodedConnectInstance + '.' + connectDomain +
callRecordingPartialUrl + encodedContactId;

return url;
return url;
}

module.exports = {
getCallRecord,
buildCallRecordingUrl
module.exports = {
getCallRecord,
buildCallRecordingUrl
};