I'm trying to build conversational Alexa skills using Alexa SDK v1 and dialog intent in node js but I'm facing an issue of the session.
Currently, I'm trying "this.emit(:responsebody)" with "response.shouldsessionattribute" and "response.listen" but still session times out. As I read that "this.emit(':tell') " end the session that's why I replaced this with "this.emit(:responsebody)".Here is code with cloudwatch log error snapshot
const alexaSDK = require('alexa-sdk'); const nforce = require('nforce'); const org = nforce.createConnection({ clientId: "NA", clientSecret: "NA", redirectUri: "NA" }); const handlers = { 'LaunchRequest'() { this.emit(':ask', instructions); }, 'Unhandled'() { console.error('problem', this.event); this.emit(':ask', 'An unhandled problem occurred!'); }, //this intent working fine 'LoginStartIntent'() { const { accessToken } = this.event.session.user; if(!accessToken ) { this.emit(':tellWithLinkAccountCard', ''); } else { //logic for integration } var speechOutput = ""; // this.emit(':tell', speechOutput); (this set the shouldsessionattribute to true) //this.response.shouldEndSession = false; this.response.speak(speechOutput); ( found this as a solution) this.emit(":responseReady"); }, //this is not working error:session is not defiend 'NewLeadsIntent'(){ const { accessToken } = this.event.session.user; if(!accessToken || !instanceUrl ) { this.emit(':tellWithLinkAccountCard', ''); } else { const query = ''; var speechOutput ; console.log('working 1'); // auth and run query org.query({ query:query ,oauth: getOauthObject(accessToken)}, function(err, res){ if(err) { console.log(err); speechOutput = 'Darn, there was a Salesforce problem, sorry'; } else { // logic for sucess responsce } } }); //this.emit(':tell', speechOutput); (this set the shouldsessionattribute to true) this.response.speak(speechOutput); //this.response.shouldEndSession = false; ( found this as a solution) //this.response.listen(); ( found this as a solution) this.emit(":responseReady"); } }, 'AMAZON.HelpIntent'() { const speechOutput = ''; this.emit(':ask', speechOutput, reprompt); }, 'AMAZON.CancelIntent'() { this.emit(':tell', 'Goodbye!'); }, 'AMAZON.StopIntent'() { this.emit(':tell', 'Goodbye!'); } }; function getOauthObject(accessToken) { // Construct our OAuth token based on the access token we were provided from Alexa var oauth = {}; oauth.access_token = accessToken; oauth.instance_url = instanceUrl; return oauth; } exports.handler = function handler(event, context) { const alexa = alexaSDK.handler(event, context); alexa.appId = appId; alexa.registerHandlers(handlers); alexa.execute(); };