diff --git a/src/dashbot-amazon-alexa.js b/src/dashbot-amazon-alexa.js index dfebf7d..8ef5ad3 100644 --- a/src/dashbot-amazon-alexa.js +++ b/src/dashbot-amazon-alexa.js @@ -57,11 +57,29 @@ function DashBotAmazonAlexa(apiKey, urlRoot, debug, printErrors) { that.logOutgoing = function(event, response, context) { var timestamp = new Date().getTime(); + // get session attributes + var eventAttributes = event && event.session && event.session.attributes || {}; + var responseAttributes = response && response.sessionAttributes || {}; + // clone event and response + var trimmedEvent = _.cloneDeep(event); + var trimmedResponse = _.cloneDeep(response); + // remove extra attribute values from event + for (var eventKey in eventAttributes) { + if (eventAttributes.hasOwnProperty(eventKey) && eventKey !== 'STATE') { + delete trimmedEvent.session.attributes[eventKey]; + } + } + // remove extra attribute values from response + for (var responseKey in responseAttributes) { + if (responseAttributes.hasOwnProperty(responseKey) && responseKey !== 'STATE') { + delete trimmedResponse.sessionAttributes[responseKey]; + } + } var data = { dashbot_timestamp: timestamp, - event: event, + event: trimmedEvent, context: context, - response: response + response: trimmedResponse }; return internalLogOutgoing(data, 'npm'); }; @@ -120,4 +138,4 @@ function DashBotAmazonAlexa(apiKey, urlRoot, debug, printErrors) { } -module.exports = DashBotAmazonAlexa; \ No newline at end of file +module.exports = DashBotAmazonAlexa;