I am trying to create a Intent where skill can get Input from user until user says "finish".
Asked
Active
Viewed 49 times
1 Answers
5
You can use addElicitSlotDirective for every turn keeping withShouldEndSession(false) and when user says "finish" set withShouldEndSession(true).
This should work for you. Here's the sample how I've implement this in my skill.
const JournalIntentHandler = {
canHandle(handlerInput) {
console.log(JSON.stringify(handlerInput));
const request = handlerInput.requestEnvelope.request;
return (
request.type === "IntentRequest" && request.intent.name === "Journal" && handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
);
},
async handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
let speechText = { text: "" };
let subtitle = "Journal";
endSession.value = false;
speechText.text = "Continue.";
if (!sessionAttributes.savedSpeech) {
sessionAttributes["savedSpeech"] = "";
}
let oldSpeech = sessionAttributes.savedSpeech;
let newSpeech = handlerInput.requestEnvelope.request.intent.slots.speech
.value
? handlerInput.requestEnvelope.request.intent.slots.speech.value
: "";
sessionAttributes.savedSpeech = oldSpeech + " " + newSpeech;
const request = handlerInput.requestEnvelope.request;
if(newSpeech == 'exit' || newSpeech == 'finish'){
endSession.value = true;
speechText.text = `Saved data is <break time='0.2s'/> ${oldSpeech}`
}
return (
handlerInput.responseBuilder
.addElicitSlotDirective('speech')
.speak(speechText.text)
.reprompt("Continue")
.withStandardCard( subtitle, oldSpeech + " " + newSpeech)
.withShouldEndSession(endSession.value)
.getResponse()
);
},
};

marc_s
- 732,580
- 175
- 1,330
- 1,459

Suraj Prakash Sahu
- 316
- 1
- 6
-
1But do they want to end the skill and quit or do they want to move on to do something with the list? Setting withShouldEndSession to true ends the building of the list AND the skill. – LetMyPeopleCode Aug 25 '20 at 06:01
-
@LetMyPeopleCode This gives an idea how to approach the problem, we can create conditioned responseBuilder according to use case. – Suraj Prakash Sahu Aug 25 '20 at 06:09