Alexa sdk v2 using ask-sdk-core custom skill fails with : Session ended with reason: ERROR












0















I'm developing a custom skill and having some trouble with just this intent, that is to say at the very last stage when all conditions are met in the if/else control flow, I mean when it gets to the last else statement, only this one fails to return the expected response, but all returned responses are working just fine, what could I possibly be missing here: Please pay close attention to the last part where resolve(handlerInput.responseBuilder.speak....etc). I'm not sure what I am doing right here, I'd appreciate



const SetDefaultLocationIntentInProgress = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SetDefaultLocationIntent';
},
handle(handlerInput) {
console.log(`In SetDefaultLocationIntentInProgress`);
let cardTitle = speech.getCardTitle('setdefaultloc1');

let city = '';
let state = '';
let zipcode = '';


const { attributesManager, responseBuilder } = handlerInput;
const sessionAttributes = attributesManager.getSessionAttributes();

const currentIntent = handlerInput.requestEnvelope.request.intent;


if (sessionAttributes[currentIntent.name]) {
const tempSlots = sessionAttributes[currentIntent.name].slots;
for (const key in tempSlots) {
if (tempSlots[key].value && !currentIntent.slots[key].value) {
currentIntent.slots[key] = tempSlots[key];
}
}
}

sessionAttributes[currentIntent.name] = currentIntent;
attributesManager.setSessionAttributes(sessionAttributes);

if (currentIntent.slots.City && currentIntent.slots.City.value) {
// User provided value for City slot
city = currentIntent.slots.City.value;
}

if (currentIntent.slots.State && currentIntent.slots.State.value) {
// User provided value for State slot
state = currentIntent.slots.State.value;
}

if (currentIntent.slots.Zipcode && currentIntent.slots.Zipcode.value) {
// User provided value for Zipcode slot
zipcode = currentIntent.slots.Zipcode.value;
}

debugLog(`City: ${city}, State: ${state}, Zipcode: ${zipcode}`);

let speechOutput = '';
let repromtText = '';

if (city.length === 0 && state.length === 0 && zipcode.length === 0) {
// No values provided by user for city, state or zipcode
speechOutput = speech.getSpeechText('setdefaultloc5');
repromtText = speech.getSpeechText('reprompt2');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if(zipcode.length > 0 && !zipCodeValidator(zipcode) ) {
// user provided a zipcode but it is not a valid US zipcode
let speechObject = speech.getSpeechObject('setdefaultloc7');
speechOutput = util.format(speechObject.text, zipcode);
repromtText = speech.getSpeechText('reprompt3');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();

}else {

let params = '';
let lookupFunc = '';
let placeNameLookup = '';
if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
params = zipcode;
lookupFunc = apiCalls.zipcodeLookup;
}else {
if (state.length === 0) {
params = city;
placeNameLookup = city;
}else{
params = `${city}+${state}`;
placeNameLookup = `${city} ${state}`;
}
lookupFunc = apiCalls.placeNameLookup;
}

lookupFunc (params, (error, result, duration) => {

if(error || result === null) {
// API Call failed or result is null
speechOutput = speech.getSpeechText('error2', false);
repromtText = speech.getSpeechText('reprompt3', false);

return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if (Object.keys(result).length === 0) {
// Returned an empty result
if (zipcode.length > 0) {
// was zipcode
let speechObject = speech.getSpeechObject('setdefaultloc4');
repromtText = speech.getSpeechText('reprompt3', false);


speechOutput = util.format(speechObject.text, zipcode);

}else{
// wasn't zipcode
let speechObject = speech.getSpeechObject('setdefaultloc3');

repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

}
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else {
// Api Call successfull with result objects length > 0
return new Promise( (resolve, reject) => {
handlerInput.attributesManager.getPersistentAttributes()
.then((attributes) => {
const defaultLoc = {
name: result.name,
lat: result.lat,
lon: result.lon
};
const userId = handlerInput.requestEnvelope.context.System.user.userId;
attributes['defaultLoc'] = defaultLoc;

debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
handlerInput.attributesManager.setSessionAttributes(attributes);
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();

let speechObject = speech.getSpeechObject('setdefaultloc22');
repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

debugLog(`handlerInput: ${handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse()}`);

resolve(handlerInput.responseBuilder.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse());
})
.catch((error) => {
console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
reject(error);
});
});

}
});
}

},
};









share|improve this question























  • Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

    – R. Vait
    Dec 29 '18 at 16:09













  • thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

    – Amaz Triss
    Dec 29 '18 at 16:29


















0















I'm developing a custom skill and having some trouble with just this intent, that is to say at the very last stage when all conditions are met in the if/else control flow, I mean when it gets to the last else statement, only this one fails to return the expected response, but all returned responses are working just fine, what could I possibly be missing here: Please pay close attention to the last part where resolve(handlerInput.responseBuilder.speak....etc). I'm not sure what I am doing right here, I'd appreciate



const SetDefaultLocationIntentInProgress = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SetDefaultLocationIntent';
},
handle(handlerInput) {
console.log(`In SetDefaultLocationIntentInProgress`);
let cardTitle = speech.getCardTitle('setdefaultloc1');

let city = '';
let state = '';
let zipcode = '';


const { attributesManager, responseBuilder } = handlerInput;
const sessionAttributes = attributesManager.getSessionAttributes();

const currentIntent = handlerInput.requestEnvelope.request.intent;


if (sessionAttributes[currentIntent.name]) {
const tempSlots = sessionAttributes[currentIntent.name].slots;
for (const key in tempSlots) {
if (tempSlots[key].value && !currentIntent.slots[key].value) {
currentIntent.slots[key] = tempSlots[key];
}
}
}

sessionAttributes[currentIntent.name] = currentIntent;
attributesManager.setSessionAttributes(sessionAttributes);

if (currentIntent.slots.City && currentIntent.slots.City.value) {
// User provided value for City slot
city = currentIntent.slots.City.value;
}

if (currentIntent.slots.State && currentIntent.slots.State.value) {
// User provided value for State slot
state = currentIntent.slots.State.value;
}

if (currentIntent.slots.Zipcode && currentIntent.slots.Zipcode.value) {
// User provided value for Zipcode slot
zipcode = currentIntent.slots.Zipcode.value;
}

debugLog(`City: ${city}, State: ${state}, Zipcode: ${zipcode}`);

let speechOutput = '';
let repromtText = '';

if (city.length === 0 && state.length === 0 && zipcode.length === 0) {
// No values provided by user for city, state or zipcode
speechOutput = speech.getSpeechText('setdefaultloc5');
repromtText = speech.getSpeechText('reprompt2');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if(zipcode.length > 0 && !zipCodeValidator(zipcode) ) {
// user provided a zipcode but it is not a valid US zipcode
let speechObject = speech.getSpeechObject('setdefaultloc7');
speechOutput = util.format(speechObject.text, zipcode);
repromtText = speech.getSpeechText('reprompt3');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();

}else {

let params = '';
let lookupFunc = '';
let placeNameLookup = '';
if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
params = zipcode;
lookupFunc = apiCalls.zipcodeLookup;
}else {
if (state.length === 0) {
params = city;
placeNameLookup = city;
}else{
params = `${city}+${state}`;
placeNameLookup = `${city} ${state}`;
}
lookupFunc = apiCalls.placeNameLookup;
}

lookupFunc (params, (error, result, duration) => {

if(error || result === null) {
// API Call failed or result is null
speechOutput = speech.getSpeechText('error2', false);
repromtText = speech.getSpeechText('reprompt3', false);

return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if (Object.keys(result).length === 0) {
// Returned an empty result
if (zipcode.length > 0) {
// was zipcode
let speechObject = speech.getSpeechObject('setdefaultloc4');
repromtText = speech.getSpeechText('reprompt3', false);


speechOutput = util.format(speechObject.text, zipcode);

}else{
// wasn't zipcode
let speechObject = speech.getSpeechObject('setdefaultloc3');

repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

}
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else {
// Api Call successfull with result objects length > 0
return new Promise( (resolve, reject) => {
handlerInput.attributesManager.getPersistentAttributes()
.then((attributes) => {
const defaultLoc = {
name: result.name,
lat: result.lat,
lon: result.lon
};
const userId = handlerInput.requestEnvelope.context.System.user.userId;
attributes['defaultLoc'] = defaultLoc;

debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
handlerInput.attributesManager.setSessionAttributes(attributes);
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();

let speechObject = speech.getSpeechObject('setdefaultloc22');
repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

debugLog(`handlerInput: ${handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse()}`);

resolve(handlerInput.responseBuilder.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse());
})
.catch((error) => {
console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
reject(error);
});
});

}
});
}

},
};









share|improve this question























  • Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

    – R. Vait
    Dec 29 '18 at 16:09













  • thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

    – Amaz Triss
    Dec 29 '18 at 16:29
















0












0








0








I'm developing a custom skill and having some trouble with just this intent, that is to say at the very last stage when all conditions are met in the if/else control flow, I mean when it gets to the last else statement, only this one fails to return the expected response, but all returned responses are working just fine, what could I possibly be missing here: Please pay close attention to the last part where resolve(handlerInput.responseBuilder.speak....etc). I'm not sure what I am doing right here, I'd appreciate



const SetDefaultLocationIntentInProgress = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SetDefaultLocationIntent';
},
handle(handlerInput) {
console.log(`In SetDefaultLocationIntentInProgress`);
let cardTitle = speech.getCardTitle('setdefaultloc1');

let city = '';
let state = '';
let zipcode = '';


const { attributesManager, responseBuilder } = handlerInput;
const sessionAttributes = attributesManager.getSessionAttributes();

const currentIntent = handlerInput.requestEnvelope.request.intent;


if (sessionAttributes[currentIntent.name]) {
const tempSlots = sessionAttributes[currentIntent.name].slots;
for (const key in tempSlots) {
if (tempSlots[key].value && !currentIntent.slots[key].value) {
currentIntent.slots[key] = tempSlots[key];
}
}
}

sessionAttributes[currentIntent.name] = currentIntent;
attributesManager.setSessionAttributes(sessionAttributes);

if (currentIntent.slots.City && currentIntent.slots.City.value) {
// User provided value for City slot
city = currentIntent.slots.City.value;
}

if (currentIntent.slots.State && currentIntent.slots.State.value) {
// User provided value for State slot
state = currentIntent.slots.State.value;
}

if (currentIntent.slots.Zipcode && currentIntent.slots.Zipcode.value) {
// User provided value for Zipcode slot
zipcode = currentIntent.slots.Zipcode.value;
}

debugLog(`City: ${city}, State: ${state}, Zipcode: ${zipcode}`);

let speechOutput = '';
let repromtText = '';

if (city.length === 0 && state.length === 0 && zipcode.length === 0) {
// No values provided by user for city, state or zipcode
speechOutput = speech.getSpeechText('setdefaultloc5');
repromtText = speech.getSpeechText('reprompt2');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if(zipcode.length > 0 && !zipCodeValidator(zipcode) ) {
// user provided a zipcode but it is not a valid US zipcode
let speechObject = speech.getSpeechObject('setdefaultloc7');
speechOutput = util.format(speechObject.text, zipcode);
repromtText = speech.getSpeechText('reprompt3');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();

}else {

let params = '';
let lookupFunc = '';
let placeNameLookup = '';
if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
params = zipcode;
lookupFunc = apiCalls.zipcodeLookup;
}else {
if (state.length === 0) {
params = city;
placeNameLookup = city;
}else{
params = `${city}+${state}`;
placeNameLookup = `${city} ${state}`;
}
lookupFunc = apiCalls.placeNameLookup;
}

lookupFunc (params, (error, result, duration) => {

if(error || result === null) {
// API Call failed or result is null
speechOutput = speech.getSpeechText('error2', false);
repromtText = speech.getSpeechText('reprompt3', false);

return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if (Object.keys(result).length === 0) {
// Returned an empty result
if (zipcode.length > 0) {
// was zipcode
let speechObject = speech.getSpeechObject('setdefaultloc4');
repromtText = speech.getSpeechText('reprompt3', false);


speechOutput = util.format(speechObject.text, zipcode);

}else{
// wasn't zipcode
let speechObject = speech.getSpeechObject('setdefaultloc3');

repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

}
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else {
// Api Call successfull with result objects length > 0
return new Promise( (resolve, reject) => {
handlerInput.attributesManager.getPersistentAttributes()
.then((attributes) => {
const defaultLoc = {
name: result.name,
lat: result.lat,
lon: result.lon
};
const userId = handlerInput.requestEnvelope.context.System.user.userId;
attributes['defaultLoc'] = defaultLoc;

debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
handlerInput.attributesManager.setSessionAttributes(attributes);
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();

let speechObject = speech.getSpeechObject('setdefaultloc22');
repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

debugLog(`handlerInput: ${handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse()}`);

resolve(handlerInput.responseBuilder.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse());
})
.catch((error) => {
console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
reject(error);
});
});

}
});
}

},
};









share|improve this question














I'm developing a custom skill and having some trouble with just this intent, that is to say at the very last stage when all conditions are met in the if/else control flow, I mean when it gets to the last else statement, only this one fails to return the expected response, but all returned responses are working just fine, what could I possibly be missing here: Please pay close attention to the last part where resolve(handlerInput.responseBuilder.speak....etc). I'm not sure what I am doing right here, I'd appreciate



const SetDefaultLocationIntentInProgress = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SetDefaultLocationIntent';
},
handle(handlerInput) {
console.log(`In SetDefaultLocationIntentInProgress`);
let cardTitle = speech.getCardTitle('setdefaultloc1');

let city = '';
let state = '';
let zipcode = '';


const { attributesManager, responseBuilder } = handlerInput;
const sessionAttributes = attributesManager.getSessionAttributes();

const currentIntent = handlerInput.requestEnvelope.request.intent;


if (sessionAttributes[currentIntent.name]) {
const tempSlots = sessionAttributes[currentIntent.name].slots;
for (const key in tempSlots) {
if (tempSlots[key].value && !currentIntent.slots[key].value) {
currentIntent.slots[key] = tempSlots[key];
}
}
}

sessionAttributes[currentIntent.name] = currentIntent;
attributesManager.setSessionAttributes(sessionAttributes);

if (currentIntent.slots.City && currentIntent.slots.City.value) {
// User provided value for City slot
city = currentIntent.slots.City.value;
}

if (currentIntent.slots.State && currentIntent.slots.State.value) {
// User provided value for State slot
state = currentIntent.slots.State.value;
}

if (currentIntent.slots.Zipcode && currentIntent.slots.Zipcode.value) {
// User provided value for Zipcode slot
zipcode = currentIntent.slots.Zipcode.value;
}

debugLog(`City: ${city}, State: ${state}, Zipcode: ${zipcode}`);

let speechOutput = '';
let repromtText = '';

if (city.length === 0 && state.length === 0 && zipcode.length === 0) {
// No values provided by user for city, state or zipcode
speechOutput = speech.getSpeechText('setdefaultloc5');
repromtText = speech.getSpeechText('reprompt2');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if(zipcode.length > 0 && !zipCodeValidator(zipcode) ) {
// user provided a zipcode but it is not a valid US zipcode
let speechObject = speech.getSpeechObject('setdefaultloc7');
speechOutput = util.format(speechObject.text, zipcode);
repromtText = speech.getSpeechText('reprompt3');
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();

}else {

let params = '';
let lookupFunc = '';
let placeNameLookup = '';
if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
params = zipcode;
lookupFunc = apiCalls.zipcodeLookup;
}else {
if (state.length === 0) {
params = city;
placeNameLookup = city;
}else{
params = `${city}+${state}`;
placeNameLookup = `${city} ${state}`;
}
lookupFunc = apiCalls.placeNameLookup;
}

lookupFunc (params, (error, result, duration) => {

if(error || result === null) {
// API Call failed or result is null
speechOutput = speech.getSpeechText('error2', false);
repromtText = speech.getSpeechText('reprompt3', false);

return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else if (Object.keys(result).length === 0) {
// Returned an empty result
if (zipcode.length > 0) {
// was zipcode
let speechObject = speech.getSpeechObject('setdefaultloc4');
repromtText = speech.getSpeechText('reprompt3', false);


speechOutput = util.format(speechObject.text, zipcode);

}else{
// wasn't zipcode
let speechObject = speech.getSpeechObject('setdefaultloc3');

repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

}
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse();
}else {
// Api Call successfull with result objects length > 0
return new Promise( (resolve, reject) => {
handlerInput.attributesManager.getPersistentAttributes()
.then((attributes) => {
const defaultLoc = {
name: result.name,
lat: result.lat,
lon: result.lon
};
const userId = handlerInput.requestEnvelope.context.System.user.userId;
attributes['defaultLoc'] = defaultLoc;

debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
handlerInput.attributesManager.setSessionAttributes(attributes);
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();

let speechObject = speech.getSpeechObject('setdefaultloc22');
repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

debugLog(`handlerInput: ${handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse()}`);

resolve(handlerInput.responseBuilder.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse());
})
.catch((error) => {
console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
reject(error);
});
});

}
});
}

},
};






javascript node.js alexa alexa-skills-kit alexa-skill






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 2:52









Amaz TrissAmaz Triss

12




12













  • Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

    – R. Vait
    Dec 29 '18 at 16:09













  • thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

    – Amaz Triss
    Dec 29 '18 at 16:29





















  • Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

    – R. Vait
    Dec 29 '18 at 16:09













  • thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

    – Amaz Triss
    Dec 29 '18 at 16:29



















Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

– R. Vait
Dec 29 '18 at 16:09







Can you try printing out what error message do you get? Can you add this code to the session ended request handler and post the message it returns? console.log(`Error occured: ${handlerInput.requestEnvelope.request.error.type}, ${handlerInput.requestEnvelope.request.error.message}`)

– R. Vait
Dec 29 '18 at 16:09















thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

– Amaz Triss
Dec 29 '18 at 16:29







thanks for the reply @R.Vait, it shows an error instead because error.type and error.message are not inaccessible,

– Amaz Triss
Dec 29 '18 at 16:29














1 Answer
1






active

oldest

votes


















0














Finally solved the problem: It was merely a promise issue I wasn't handling properly, I had to wrap everything in the else statement in a promise and this is how I restructured the last else statement to get the desired result.



else {
return new Promise((resolve, reject) => {
let params = '';
let lookupFunc = '';
let placeNameLookup = '';
if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
params = zipcode;
lookupFunc = apiCalls.zipcodeLookup;
}else {
if (state.length === 0) {
params = city;
placeNameLookup = city;
}else{
params = `${city}+${state}`;
placeNameLookup = `${city} ${state}`;
}
lookupFunc = apiCalls.placeNameLookup;
}

lookupFunc (params, (error, result, duration) => {

if(error || result === null) {
// API Call failed or result is null
speechOutput = speech.getSpeechText('error2', false);
repromtText = speech.getSpeechText('reprompt3', false);

resolove(handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse());
}else if (Object.keys(result).length === 0) {
// Returned an empty result
if (zipcode.length > 0) {
// was zipcode
let speechObject = speech.getSpeechObject('setdefaultloc4');
repromtText = speech.getSpeechText('reprompt3', false);


speechOutput = util.format(speechObject.text, zipcode);

}else{
// wasn't zipcode
let speechObject = speech.getSpeechObject('setdefaultloc3');

repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

}
resolve(handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(repromtText)
.withSimpleCard(cardTitle, speechOutput)
.withShouldEndSession(false)
.getResponse());
}else {
// Api Call successfull with result objects length > 0
handlerInput.attributesManager.getPersistentAttributes()
.then((attributes) => {
const defaultLoc = {
name: result.name,
lat: result.lat,
lon: result.lon
};
const userId = handlerInput.requestEnvelope.context.System.user.userId;
attributes['defaultLoc'] = defaultLoc;

debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
handlerInput.attributesManager.setSessionAttributes(attributes);
handlerInput.attributesManager.setPersistentAttributes(attributes);
handlerInput.attributesManager.savePersistentAttributes();

let speechObject = speech.getSpeechObject('setdefaultloc22');
repromtText = speech.getSpeechText('reprompt3', false);

speechOutput = util.format(speechObject.text, zipcode);

debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

debugLog(`handlerInput: ${handlerInput.responseBuilder}`);

resolve(handlerInput.responseBuilder.speak(speechOutput)
.reprompt(repromtText)
.withShouldEndSession(false)
.getResponse());
})
.catch((error) => {
console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
reject(error);
});

}
});

});
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966313%2falexa-sdk-v2-using-ask-sdk-core-custom-skill-fails-with-session-ended-with-rea%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Finally solved the problem: It was merely a promise issue I wasn't handling properly, I had to wrap everything in the else statement in a promise and this is how I restructured the last else statement to get the desired result.



    else {
    return new Promise((resolve, reject) => {
    let params = '';
    let lookupFunc = '';
    let placeNameLookup = '';
    if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
    params = zipcode;
    lookupFunc = apiCalls.zipcodeLookup;
    }else {
    if (state.length === 0) {
    params = city;
    placeNameLookup = city;
    }else{
    params = `${city}+${state}`;
    placeNameLookup = `${city} ${state}`;
    }
    lookupFunc = apiCalls.placeNameLookup;
    }

    lookupFunc (params, (error, result, duration) => {

    if(error || result === null) {
    // API Call failed or result is null
    speechOutput = speech.getSpeechText('error2', false);
    repromtText = speech.getSpeechText('reprompt3', false);

    resolove(handlerInput.responseBuilder
    .speak(speechOutput)
    .reprompt(repromtText)
    .withSimpleCard(cardTitle, speechOutput)
    .withShouldEndSession(false)
    .getResponse());
    }else if (Object.keys(result).length === 0) {
    // Returned an empty result
    if (zipcode.length > 0) {
    // was zipcode
    let speechObject = speech.getSpeechObject('setdefaultloc4');
    repromtText = speech.getSpeechText('reprompt3', false);


    speechOutput = util.format(speechObject.text, zipcode);

    }else{
    // wasn't zipcode
    let speechObject = speech.getSpeechObject('setdefaultloc3');

    repromtText = speech.getSpeechText('reprompt3', false);

    speechOutput = util.format(speechObject.text, zipcode);

    }
    resolve(handlerInput.responseBuilder
    .speak(speechOutput)
    .reprompt(repromtText)
    .withSimpleCard(cardTitle, speechOutput)
    .withShouldEndSession(false)
    .getResponse());
    }else {
    // Api Call successfull with result objects length > 0
    handlerInput.attributesManager.getPersistentAttributes()
    .then((attributes) => {
    const defaultLoc = {
    name: result.name,
    lat: result.lat,
    lon: result.lon
    };
    const userId = handlerInput.requestEnvelope.context.System.user.userId;
    attributes['defaultLoc'] = defaultLoc;

    debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
    handlerInput.attributesManager.setSessionAttributes(attributes);
    handlerInput.attributesManager.setPersistentAttributes(attributes);
    handlerInput.attributesManager.savePersistentAttributes();

    let speechObject = speech.getSpeechObject('setdefaultloc22');
    repromtText = speech.getSpeechText('reprompt3', false);

    speechOutput = util.format(speechObject.text, zipcode);

    debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

    debugLog(`handlerInput: ${handlerInput.responseBuilder}`);

    resolve(handlerInput.responseBuilder.speak(speechOutput)
    .reprompt(repromtText)
    .withShouldEndSession(false)
    .getResponse());
    })
    .catch((error) => {
    console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
    reject(error);
    });

    }
    });

    });
    }





    share|improve this answer




























      0














      Finally solved the problem: It was merely a promise issue I wasn't handling properly, I had to wrap everything in the else statement in a promise and this is how I restructured the last else statement to get the desired result.



      else {
      return new Promise((resolve, reject) => {
      let params = '';
      let lookupFunc = '';
      let placeNameLookup = '';
      if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
      params = zipcode;
      lookupFunc = apiCalls.zipcodeLookup;
      }else {
      if (state.length === 0) {
      params = city;
      placeNameLookup = city;
      }else{
      params = `${city}+${state}`;
      placeNameLookup = `${city} ${state}`;
      }
      lookupFunc = apiCalls.placeNameLookup;
      }

      lookupFunc (params, (error, result, duration) => {

      if(error || result === null) {
      // API Call failed or result is null
      speechOutput = speech.getSpeechText('error2', false);
      repromtText = speech.getSpeechText('reprompt3', false);

      resolove(handlerInput.responseBuilder
      .speak(speechOutput)
      .reprompt(repromtText)
      .withSimpleCard(cardTitle, speechOutput)
      .withShouldEndSession(false)
      .getResponse());
      }else if (Object.keys(result).length === 0) {
      // Returned an empty result
      if (zipcode.length > 0) {
      // was zipcode
      let speechObject = speech.getSpeechObject('setdefaultloc4');
      repromtText = speech.getSpeechText('reprompt3', false);


      speechOutput = util.format(speechObject.text, zipcode);

      }else{
      // wasn't zipcode
      let speechObject = speech.getSpeechObject('setdefaultloc3');

      repromtText = speech.getSpeechText('reprompt3', false);

      speechOutput = util.format(speechObject.text, zipcode);

      }
      resolve(handlerInput.responseBuilder
      .speak(speechOutput)
      .reprompt(repromtText)
      .withSimpleCard(cardTitle, speechOutput)
      .withShouldEndSession(false)
      .getResponse());
      }else {
      // Api Call successfull with result objects length > 0
      handlerInput.attributesManager.getPersistentAttributes()
      .then((attributes) => {
      const defaultLoc = {
      name: result.name,
      lat: result.lat,
      lon: result.lon
      };
      const userId = handlerInput.requestEnvelope.context.System.user.userId;
      attributes['defaultLoc'] = defaultLoc;

      debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
      handlerInput.attributesManager.setSessionAttributes(attributes);
      handlerInput.attributesManager.setPersistentAttributes(attributes);
      handlerInput.attributesManager.savePersistentAttributes();

      let speechObject = speech.getSpeechObject('setdefaultloc22');
      repromtText = speech.getSpeechText('reprompt3', false);

      speechOutput = util.format(speechObject.text, zipcode);

      debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

      debugLog(`handlerInput: ${handlerInput.responseBuilder}`);

      resolve(handlerInput.responseBuilder.speak(speechOutput)
      .reprompt(repromtText)
      .withShouldEndSession(false)
      .getResponse());
      })
      .catch((error) => {
      console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
      reject(error);
      });

      }
      });

      });
      }





      share|improve this answer


























        0












        0








        0







        Finally solved the problem: It was merely a promise issue I wasn't handling properly, I had to wrap everything in the else statement in a promise and this is how I restructured the last else statement to get the desired result.



        else {
        return new Promise((resolve, reject) => {
        let params = '';
        let lookupFunc = '';
        let placeNameLookup = '';
        if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
        params = zipcode;
        lookupFunc = apiCalls.zipcodeLookup;
        }else {
        if (state.length === 0) {
        params = city;
        placeNameLookup = city;
        }else{
        params = `${city}+${state}`;
        placeNameLookup = `${city} ${state}`;
        }
        lookupFunc = apiCalls.placeNameLookup;
        }

        lookupFunc (params, (error, result, duration) => {

        if(error || result === null) {
        // API Call failed or result is null
        speechOutput = speech.getSpeechText('error2', false);
        repromtText = speech.getSpeechText('reprompt3', false);

        resolove(handlerInput.responseBuilder
        .speak(speechOutput)
        .reprompt(repromtText)
        .withSimpleCard(cardTitle, speechOutput)
        .withShouldEndSession(false)
        .getResponse());
        }else if (Object.keys(result).length === 0) {
        // Returned an empty result
        if (zipcode.length > 0) {
        // was zipcode
        let speechObject = speech.getSpeechObject('setdefaultloc4');
        repromtText = speech.getSpeechText('reprompt3', false);


        speechOutput = util.format(speechObject.text, zipcode);

        }else{
        // wasn't zipcode
        let speechObject = speech.getSpeechObject('setdefaultloc3');

        repromtText = speech.getSpeechText('reprompt3', false);

        speechOutput = util.format(speechObject.text, zipcode);

        }
        resolve(handlerInput.responseBuilder
        .speak(speechOutput)
        .reprompt(repromtText)
        .withSimpleCard(cardTitle, speechOutput)
        .withShouldEndSession(false)
        .getResponse());
        }else {
        // Api Call successfull with result objects length > 0
        handlerInput.attributesManager.getPersistentAttributes()
        .then((attributes) => {
        const defaultLoc = {
        name: result.name,
        lat: result.lat,
        lon: result.lon
        };
        const userId = handlerInput.requestEnvelope.context.System.user.userId;
        attributes['defaultLoc'] = defaultLoc;

        debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
        handlerInput.attributesManager.setSessionAttributes(attributes);
        handlerInput.attributesManager.setPersistentAttributes(attributes);
        handlerInput.attributesManager.savePersistentAttributes();

        let speechObject = speech.getSpeechObject('setdefaultloc22');
        repromtText = speech.getSpeechText('reprompt3', false);

        speechOutput = util.format(speechObject.text, zipcode);

        debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

        debugLog(`handlerInput: ${handlerInput.responseBuilder}`);

        resolve(handlerInput.responseBuilder.speak(speechOutput)
        .reprompt(repromtText)
        .withShouldEndSession(false)
        .getResponse());
        })
        .catch((error) => {
        console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
        reject(error);
        });

        }
        });

        });
        }





        share|improve this answer













        Finally solved the problem: It was merely a promise issue I wasn't handling properly, I had to wrap everything in the else statement in a promise and this is how I restructured the last else statement to get the desired result.



        else {
        return new Promise((resolve, reject) => {
        let params = '';
        let lookupFunc = '';
        let placeNameLookup = '';
        if (zipcode.length > 0 && zipCodeValidator(zipcode)) {
        params = zipcode;
        lookupFunc = apiCalls.zipcodeLookup;
        }else {
        if (state.length === 0) {
        params = city;
        placeNameLookup = city;
        }else{
        params = `${city}+${state}`;
        placeNameLookup = `${city} ${state}`;
        }
        lookupFunc = apiCalls.placeNameLookup;
        }

        lookupFunc (params, (error, result, duration) => {

        if(error || result === null) {
        // API Call failed or result is null
        speechOutput = speech.getSpeechText('error2', false);
        repromtText = speech.getSpeechText('reprompt3', false);

        resolove(handlerInput.responseBuilder
        .speak(speechOutput)
        .reprompt(repromtText)
        .withSimpleCard(cardTitle, speechOutput)
        .withShouldEndSession(false)
        .getResponse());
        }else if (Object.keys(result).length === 0) {
        // Returned an empty result
        if (zipcode.length > 0) {
        // was zipcode
        let speechObject = speech.getSpeechObject('setdefaultloc4');
        repromtText = speech.getSpeechText('reprompt3', false);


        speechOutput = util.format(speechObject.text, zipcode);

        }else{
        // wasn't zipcode
        let speechObject = speech.getSpeechObject('setdefaultloc3');

        repromtText = speech.getSpeechText('reprompt3', false);

        speechOutput = util.format(speechObject.text, zipcode);

        }
        resolve(handlerInput.responseBuilder
        .speak(speechOutput)
        .reprompt(repromtText)
        .withSimpleCard(cardTitle, speechOutput)
        .withShouldEndSession(false)
        .getResponse());
        }else {
        // Api Call successfull with result objects length > 0
        handlerInput.attributesManager.getPersistentAttributes()
        .then((attributes) => {
        const defaultLoc = {
        name: result.name,
        lat: result.lat,
        lon: result.lon
        };
        const userId = handlerInput.requestEnvelope.context.System.user.userId;
        attributes['defaultLoc'] = defaultLoc;

        debugLog("Writing attributes to DynamoDB: " + userId + ", " + "defaultlocation: " + JSON.stringify(defaultLoc));
        handlerInput.attributesManager.setSessionAttributes(attributes);
        handlerInput.attributesManager.setPersistentAttributes(attributes);
        handlerInput.attributesManager.savePersistentAttributes();

        let speechObject = speech.getSpeechObject('setdefaultloc22');
        repromtText = speech.getSpeechText('reprompt3', false);

        speechOutput = util.format(speechObject.text, zipcode);

        debugLog(`SpeechOutput After saving user location: ${speechOutput}`);

        debugLog(`handlerInput: ${handlerInput.responseBuilder}`);

        resolve(handlerInput.responseBuilder.speak(speechOutput)
        .reprompt(repromtText)
        .withShouldEndSession(false)
        .getResponse());
        })
        .catch((error) => {
        console.log(`Error in SetDefaultLocationIntent promise: ${error}`);
        reject(error);
        });

        }
        });

        });
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 29 '18 at 17:31









        Amaz TrissAmaz Triss

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966313%2falexa-sdk-v2-using-ask-sdk-core-custom-skill-fails-with-session-ended-with-rea%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas