Skip to content

Instantly share code, notes, and snippets.

@bxio
Created September 27, 2015 19:12
Show Gist options
  • Save bxio/df15111866f95d04f34a to your computer and use it in GitHub Desktop.
Save bxio/df15111866f95d04f34a to your computer and use it in GitHub Desktop.
function handleFirstIntent(intent, session, callback){
sessionAttributes = {
questionsAsked: 0,
questionsWanted: 0,
questionBank: [],
}
sessionAttributes.questionsWanted = intent.slots.NumToAsk.value;
var cardTitle = "Welcome";
var speechOutput = "Asking "+sessionAttributes.questionsWanted+" questions.";
// If the user either does not reply to the welcome message or says something that is not
// understood, they will be prompted again with this text.
var repromptText = null;
var shouldEndSession = false;
callback(sessionAttributes,
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
function handleSecondIntent(intent, session, callback){
var sessionAttributes = session.attributes;
var cardTitle = "Welcome";
var speechOutput = "Answering "+sessionAttributes.questionsWanted+" questions.";
// If the user either does not reply to the welcome message or says something that is not
// understood, they will be prompted again with this text.
var repromptText = null;
var shouldEndSession = false;
callback(sessionAttributes,
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
return {
outputSpeech: {
type: "PlainText",
text: output
},
card: {
type: "Simple",
title: "SessionSpeechlet - " + title,
content: "SessionSpeechlet - " + output
},
reprompt: {
outputSpeech: {
type: "PlainText",
text: repromptText
}
},
shouldEndSession: shouldEndSession
}
}
function buildResponse(sessionAttributes, speechletResponse) {
return {
version: "1.0",
sessionAttributes: sessionAttributes,
response: speechletResponse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment