I am building a custom skill. Before adding google analytics, the 3 built-ins & 2 customs intents were all working properly, both when tested from AWS console and the service simulator. Now, I get 'The response is invalid' from the service simulator, ONLY for the built-ins intents (the 2 customs intents give a correct lambda response). Here is what have changed in my code since the last working version:
Adding:
var express = require('express'); var request = require('request'); var app = express(); var GA_TRACKING_ID = 'UA_TRACKING_ID'; function trackEvent(category, action, label, value, cb) { console.log('1'); var data = {v: '1', tid: GA_TRACKING_ID, cid: '555', t: 'event', ec: category, ea: action, el: label, ev: value,}; request.post( 'http://www.google-analytics.com/collect', { form: data }, function(err, response) { console.log('2'); if (err) { console.log('3'); return cb(err); } if (response.statusCode !== 200) { console.log('4'); return cb(new Error('Tracking failed')); } console.log('5'); cb(); } ); }
And calling the trackEvent function, similarly in all intents:
Built-in intent example: (=> testing this intent logs out '1' in the CloudWatch, and then execution stops)'AMAZON.CancelIntent': function (intent, session, response) { var self = this; trackEvent('Intent', 'AMAZON.CancelIntent', 'stop', '100', function(err) { if (err) { return next(err); } self.response.speak(STOP_MESSAGE); self.emit(':responseReady'); })Example in a custom intent: (=> testing this intent will output the correct speechOutput)
'DressingTodayIntent': function(intent, session, response) { var speechOutput; var self = this; var cb = getJSON('...', function(err, forecast) { if (err) { console.log('Error occurred while trying to retrieve data', err); } else { speechOutput = getDressingAdvice(forecast, true); } self.response.cardRenderer("Your advice for today:", speechOutput); self.response.speak(speechOutput); self.emit(':responseReady'); }); trackEvent('Intent', 'DressingTodayIntent', 'DressingToday', '100', cb); }
I insist, 'AMAZON.CancelIntent', 'AMAZON.HelpIntent', 'AMAZON.StopIntent' (& 'LaunchRequest') are not working only since I added GA. What did I do wrong?
Last reference, the working intent code, before adding GA:'AMAZON.CancelIntent': function () { this.response.speak(STOP_MESSAGE); this.emit(':responseReady'); },