this might be an easy one but I couldn't figure it out in days.
I want to make Alexa have a conversation, like;
>> Alexa, start testSkill.
A: Test Skill started. Tell me a number.
>> One.
A: Okay, tell me a color now.
>> Blue.
A: And finally, tell me an animal name.
>> Chicken.
A: You told me one, blue and chicken.
I found out that I have to handle the Session Attributes of the skill, which is a JSON holds and transfers the information between intents.
I use functions like this ;
function testConversation(intent, session, callback) {
var cardTitle = intent.name;
var repromptText = "";
var sessionAttributes = { // I don't know how to handle this
nameOfPairOne: "",
nameOfPairTwo: "",
};
var shouldEndSession = false;
var speechOutput = "";
var color= convertToASCII(intent.slots.color.value);
sessionAttributes.nameOfPairOne = color;
speechOutput = "You said "+sessionAttributes.nameOfPairOne+". Please say another thing. ";
callback(sessionAttributes, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
function testConversation2(intent, session, callback) {
var cardTitle = intent.name;
var repromptText = "";
var sessionAttributes = session.attributes;
var shouldEndSession = false;
var speechOutput = "";
var number = convertToASCII(intent.slots.number.value);
sessionAttributes.nameOfPairTwo = number;
speechOutput = "You first said "+sessionAttributes.nameOfPairOne+", and now said "+sessionAttributes.nameOfPairTwo;
callback(sessionAttributes, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
//------Helpers that build all of the responses ---------//
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};
}
A piece of code from onIntent() function where I call the above functions. (I know it's wrong but couldn't figure out the right way)
else if ("getColorNum" == intentName) {
if (session.attributes.nameOfPairOne === "") {
testConversation(intent, session, callback);
} else {
testConversation2(intent, session, callback);
}
}
And the Intent Schema JSON is like that;
"intents": [
{
"intent": "getColorNum",
"slots": [
{
"name": "Color",
"type": "ColorSlot"
},
{
"name": "Number",
"type": "NumberSlot"
}
]
}
] }
So, am I doing all of the things wrong ? Where is the mistake ? And, how can I build a conversation like I mentioned ? Thanks from now.