我正在尝试建立一个新的简单的重新提示技能来计划一次旅行。通过文本命令在https://echosim.io上测试开发人员测试时,它的工作正常,它只响应第一次,之后响应是#34;抱歉,我不知道"每时每刻。请告诉我我在做什么错误。
我的技能JSON
{"interactionModel":{"languageModel":{"invocationName":"plan a short trip","intents":[{"name":"AMAZON.CancelIntent","samples":["Ghuso","abort","Cancel"]},{"name":"AMAZON.HelpIntent","samples":["Help me","Suggest me","Help"]},{"name":"AMAZON.StopIntent","samples":["Fuck off","do not proceed","quit","abort","exit","stop"]},{"name":"planMyTrip","slots":[{"name":"toCity","type":"IN_City","samples":["I'm planning to go to {toCity} on {travelDate} from {fromCity} for {activity}","I'm planning to go to {toCity} on {travelDate} for {activity}","I'm planning to go to {toCity} on {travelDate} from {fromCity} ","I'm planning to go to {toCity} on {travelDate}","I'm planning to go to {toCity}","I'll go to {toCity}","I would like to go to {toCity}","{toCity}"]},{"name":"travelDate","type":"AMAZON.DATE","samples":["I'll leave on {travelDate} for {activity}","I'll leave on {travelDate} for {activity} from {fromCity}","I'll leave on {travelDate} for {activity} from {fromCity} to {toCity}","I'll leave on {travelDate} for {activity} to {toCity}","I'll leave on {travelDate} for {activity} to {toCity} from {fromCity}","I'll leave on {travelDate} from {fromCity}","I'll leave on {travelDate} from {fromCity} to {toCity}","I'll leave on {travelDate} from {fromCity} to {toCity} for {activity}","I'll leave on {travelDate} from {fromCity} for {activity}","I'll leave on {travelDate} to {toCity}","I'll leave on {travelDate} to {toCity} from {fromCity}","I'll leave on {travelDate} to {toCity} from {fromCity} for {activity}","I'll leave on {travelDate} to {toCity} for {activity}","I'll leave on {travelDate}","I'm planning to leave on {travelDate} for {activity}","I'm planning to leave on {travelDate} for {activity} from {fromCity}","I'm planning to leave on {travelDate} for {activity} from {fromCity} to {toCity}","I'm planning to leave on {travelDate} for {activity} to {toCity}","I'm planning to leave on {travelDate} for {activity} to {toCity} from {fromCity}","I'm planning to leave on {travelDate} from {fromCity}","I'm planning to leave on {travelDate} from {fromCity} to {toCity}","I'm planning to leave on {travelDate} from {fromCity} to {toCity} for {activity}","I'm planning to leave on {travelDate} from {fromCity} for {activity}","I'm planning to leave on {travelDate} to {toCity}","I'm planning to leave on {travelDate} to {toCity} from {fromCity}","I'm planning to leave on {travelDate} to {toCity} from {fromCity} for {activity}","I'm planning to leave on {travelDate} to {toCity} for {activity}","I'm planning to leave on {travelDate}","I would like to leave on {travelDate} for {activity}","I would like to leave on {travelDate} for {activity} from {fromCity}","I would like to leave on {travelDate} for {activity} from {fromCity} to {toCity}","I would like to leave on {travelDate} for {activity} to {toCity}","I would like to leave on {travelDate} for {activity} to {toCity} from {fromCity}","I would like to leave on {travelDate} from {fromCity}","I would like to leave on {travelDate} from {fromCity} to {toCity}","I would like to leave on {travelDate} from {fromCity} to {toCity} for {activity}","I would like to leave on {travelDate} from {fromCity} for {activity}","I would like to leave on {travelDate} to {toCity}","I would like to leave on {travelDate} to {toCity} from {fromCity}","I would like to leave on {travelDate} to {toCity} from {fromCity} for {activity}","I would like to leave on {travelDate} to {toCity} for {activity}","I would like to leave on {travelDate}","{travelDate}"]},{"name":"fromCity","type":"IN_City","samples":["I'll start my journey from {fromCity} to {toCity} for {activity}","I'll start my journey from {fromCity}","I'll start my journey from {fromCity} to {toCity}","I'll start my journey from {fromCity} to {toCity} on {travelDate}","I'll start my journey from {fromCity} to {toCity} on {travelDate} for {activity}","I'll catch train from {fromCity}","I'll start my trip from {fromCity} to {toCity} on {travelDate} for {activity}","I'll start my trip from {fromCity} to {toCity} for {activity}","I'll start my trip from {fromCity} to {toCity} on {travelDate}","I'll start my trip from {fromCity} to {toCity}","I'll start my travel from {fromCity}","I'll start my trip from {fromCity}","I would like to start my journey from {fromCity}","{fromCity}"]},{"name":"activity","type":"Activity_List"}],"samples":["I'll leave on {travelDate} for {activity}","I'll leave on {travelDate} for {activity} from {fromCity}","I'll leave on {travelDate} for {activity} from {fromCity} to {toCity}","I'll leave on {travelDate} for {activity} to {toCity}","I'll leave on {travelDate} for {activity} to {toCity} from {fromCity}","I'll leave on {travelDate} from {fromCity}","I'll leave on {travelDate} from {fromCity} to {toCity}","I'll leave on {travelDate} from {fromCity} to {toCity} for {activity}","I'll leave on {travelDate} from {fromCity} for {activity}","I'll leave on {travelDate} to {toCity}","I'll leave on {travelDate} to {toCity} from {fromCity}","I'll leave on {travelDate} to {toCity} from {fromCity} for {activity}","I'll leave on {travelDate} to {toCity} for {activity}","I'll leave on {travelDate}","I'm planning to leave on {travelDate} for {activity}","I'm planning to leave on {travelDate} for {activity} from {fromCity}","I'm planning to leave on {travelDate} for {activity} from {fromCity} to {toCity}","I'm planning to leave on {travelDate} for {activity} to {toCity}","I'm planning to leave on {travelDate} for {activity} to {toCity} from {fromCity}","I'm planning to leave on {travelDate} from {fromCity}","I'm planning to leave on {travelDate} from {fromCity} to {toCity}","I'm planning to leave on {travelDate} from {fromCity} to {toCity} for {activity}","I'm planning to leave on {travelDate} from {fromCity} for {activity}","I'm planning to leave on {travelDate} to {toCity}","I'm planning to leave on {travelDate} to {toCity} from {fromCity}","I'm planning to leave on {travelDate} to {toCity} from {fromCity} for {activity}","I'm planning to leave on {travelDate} to {toCity} for {activity}","I'm planning to leave on {travelDate}","I would like to leave on {travelDate} for {activity}","I would like to leave on {travelDate} for {activity} from {fromCity}","I would like to leave on {travelDate} for {activity} from {fromCity} to {toCity}","I would like to leave on {travelDate} for {activity} to {toCity}","I would like to leave on {travelDate} for {activity} to {toCity} from {fromCity}","I would like to leave on {travelDate} from {fromCity}","I would like to leave on {travelDate} from {fromCity} to {toCity}","I would like to leave on {travelDate} from {fromCity} to {toCity} for {activity}","I would like to leave on {travelDate} from {fromCity} for {activity}","I would like to leave on {travelDate} to {toCity}","I would like to leave on {travelDate} to {toCity} from {fromCity}","I would like to leave on {travelDate} to {toCity} from {fromCity} for {activity}","I would like to leave on {travelDate} to {toCity} for {activity}","I would like to leave on {travelDate}","I'll start my journey from {fromCity} to {toCity} for {activity}","I'll start my journey from {fromCity}","I'll start my journey from {fromCity} to {toCity}","I'll start my journey from {fromCity} to {toCity} on {travelDate}","I'll start my journey from {fromCity} to {toCity} on {travelDate} for {activity}","I'll catch train from {fromCity}","I'll start my trip from {fromCity} to {toCity} on {travelDate} for {activity}","I'll start my trip from {fromCity} to {toCity} for {activity}","I'll start my trip from {fromCity} to {toCity} on {travelDate}","I'll start my trip from {fromCity} to {toCity}","I'll start my travel from {fromCity}","I'll start my trip from {fromCity}","I would like to start my journey from {fromCity}","I'll leave from {fromCity} to {toCity} on {travelDate} for {activity}","I'll leave to {toCity} on {travelDate}","I'll leave to {toCity}","I'll leave from {fromCity} to {toCity}","I'll leave from {fromCity} to {toCity} on {travelDate}","I'll leave from {fromCity}","I'm thinking to leave to {toCity} from {fromCity} on {travelDate} for {activity}","I'm thinking to leave to {toCity} on {travelDate}","I'm thinking to leave to {toCity} from {fromCity}","I'm thinking to leave to {toCity} from {fromCity} on {travelDate}","I'm thinking to leave to {toCity}","I'm thinking to leave on {travelDate} to {toCity}","I would like to go to {toCity} from {fromCity} on {travelDate} for {activity}","I would like to go to {toCity} on {travelDate} for {activity}","I would like to go to {toCity} for {activity}","I would like to go to {toCity} on {travelDate}","I would like to go to {toCity} from {fromCity} on {travelDate}","I would like to go to {toCity} from {fromCity}","I would like to go to {toCity} from {fromCity} for {activity}","I would like to go to {toCity}"]}],"types":[{"name":"IN_City","values":[{"name":{"value":"Bangaluru","synonyms":["Banglore"]}},{"name":{"value":"Kolkata","synonyms":["Calcutta"]}},{"name":{"value":"Chennai","synonyms":["Madras"]}},{"name":{"value":"Mumbai","synonyms":["Bombay"]}},{"name":{"value":"New Delhi","synonyms":["Nation Capital","Delhi"]}},{"name":{"value":"Banaras","synonyms":["Varansi"]}},{"name":{"value":"Kanpur"}},{"name":{"value":"Gorakhpur"}},{"name":{"value":"Lucknow","synonyms":["State Capital"]}},{"name":{"value":"Gonda","synonyms":["My Place"]}}]},{"name":"Activity_List","values":[{"name":{"value":"Eat panipuri"}},{"name":{"value":"Eat Ice Cream"}},{"name":{"value":"Hiking"}}]}]},"dialog":{"intents":[{"name":"planMyTrip","confirmationRequired":false,"prompts":{},"slots":[{"name":"toCity","type":"IN_City","confirmationRequired":false,"elicitationRequired":true,"prompts":{"elicitation":"Elicit.Slot.1452754453084.1423120820396"}},{"name":"travelDate","type":"AMAZON.DATE","confirmationRequired":false,"elicitationRequired":true,"prompts":{"elicitation":"Elicit.Slot.1452754453084.1050959742258"}},{"name":"fromCity","type":"IN_City","confirmationRequired":false,"elicitationRequired":true,"prompts":{"elicitation":"Elicit.Slot.1452754453084.1184330774841"}},{"name":"activity","type":"Activity_List","confirmationRequired":false,"elicitationRequired":false,"prompts":{}}]}]},"prompts":[{"id":"Elicit.Slot.1452754453084.1423120820396","variations":[{"type":"PlainText","value":"which city you want to go?"},{"type":"PlainText","value":"where would you want to go?"},{"type":"PlainText","value":"Where would you like to go?"},{"type":"PlainText","value":"Let's plan a trip. Where would you like to go?"},{"type":"PlainText","value":"Let me know where you'd like to go?"}]},{"id":"Elicit.Slot.1452754453084.1050959742258","variations":[{"type":"PlainText","value":"when are you planning to leave?"},{"type":"PlainText","value":"when is this trip?"},{"type":"PlainText","value":"When you want to leave?"},{"type":"PlainText","value":"Let me know, when you want to leave?"}]},{"id":"Elicit.Slot.1452754453084.1184330774841","variations":[{"type":"PlainText","value":"where from will you start your travel?"},{"type":"PlainText","value":"where from will you start your trip?"},{"type":"PlainText","value":"Where from you want to start your journey?"},{"type":"PlainText","value":"Let me know, where from you want to start your journey?"}]}]}}
我的lambda函数
/* eslint-disable func-names */
/* eslint quote-props: ['error', 'consistent']*/
// alexa-cookbook sample code
// There are three sections, Text Strings, Skill Code, and Helper Function(s).
// You can copy and paste the entire file contents as the code for a new Lambda function,
// or copy & paste section #3, the helper function, to the bottom of your existing Lambda code.
// TODO add URL to this entry in the cookbook
// 1. Text strings =====================================================================================================
// Modify these strings and messages to change the behavior of your Lambda function
let speechOutput;
const tripIntro = [
`This sounds like a cool trip. `,
`This will be fun. `,
`Oh, I like this trip. `,
`Oh, I like this trip. `
];
const languageStrings = {
'en': {
translation: {
SKILL_NAME: 'Plan My Trip',
WELCOME_MESSAGE: 'Let\'s plan a trip. Where would you like to go?',
WELCOME_REPROMPT: 'Let me know where you\'d like to go or when you\'d like to go on your trip',
HELP_MESSAGE: 'You can tell me such as, I would like to go to New Delhi or I\'m planning to go to Mumbai or I\'ll go to Kanpur',
HELP_REPROMPT: 'You can say things like, I\'m planning to go to Gonda on Next Saturday.',
STOP_MESSAGE: 'Fir milenge chalte chalte',
NOT_FOUND_MESSAGE: 'I\'m sorry, I currently do not find any thing to serve you.',
NOT_FOUND_REPROMPT: 'What else can I help with?',
},
},
'en-US': {
translation: {
SKILL_NAME: 'Plan My Trip',
WELCOME_MESSAGE: 'Let\'s plan a trip. Where would you like to go?',
WELCOME_REPROMPT: 'Let me know where you\'d like to go or when you\'d like to go on your trip',
HELP_MESSAGE: 'You can tell me such as, I would like to go to New Delhi or I\'m planning to go to Mumbai or I\'ll go to Kanpur',
HELP_REPROMPT: 'You can say things like, I\'m planning to go to Gonda on Next Saturday.',
STOP_MESSAGE: 'Fir milenge chalte chalte',
NOT_FOUND_MESSAGE: 'I\'m sorry, I currently do not find any thing to serve you.',
NOT_FOUND_REPROMPT: 'What else can I help with?',
},
},
'en-IN': {
translation: {
SKILL_NAME: 'Plan My Trip',
WELCOME_MESSAGE: 'Let\'s plan a trip. Where would you like to go?',
WELCOME_REPROMPT: 'Let me know where you\'d like to go or when you\'d like to go on your trip',
HELP_MESSAGE: 'You can tell me such as, I would like to go to New Delhi or I\'m planning to go to Mumbai or I\'ll go to Kanpur',
HELP_REPROMPT: 'You can say things like, I\'m planning to go to Gonda on Next Saturday.',
STOP_MESSAGE: 'Fir milenge chalte chalte',
NOT_FOUND_MESSAGE: 'I\'m sorry, I currently do not find any thing to serve you.',
NOT_FOUND_REPROMPT: 'What else can I help with?',
},
}
};
// 2. Skill Code =======================================================================================================
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = 'amzn1.ask.skill.4768447b-85d7-4d6b-8d1e-8ae2f49a4e59';
const handlers = {
'LaunchRequest': function () {
this.attributes.speechOutput = this.t('WELCOME_MESSAGE', this.t('SKILL_NAME'));
this.attributes.repromptSpeech = this.t('WELCOME_REPROMPT');
this.response.speak(this.attributes.speechOutput).listen(this.attributes.repromptSpeech);
this.emit(':responseReady');
},
'planMyTrip': function () {
//delegate to Alexa to collect all the required slot values
let filledSlots = delegateSlotCollection.call(this);
//compose speechOutput that simply reads all the collected slot values
speechOutput = randomPhrase(tripIntro);
//activity is optional so we'll add it to the output
//only when we have a valid activity
let travelMode = isSlotValid(this.event.request, `travelMode`);
if (travelMode)
speechOutput += travelMode;
else
speechOutput += `You'll go `;
//Now let's recap the trip
let fromCity = this.event.request.intent.slots.fromCity.value;
let toCity = this.event.request.intent.slots.toCity.value;
let travelDate = this.event.request.intent.slots.travelDate.value;
speechOutput += ` from ${fromCity} to ${toCity} on ${travelDate}`;
let activity = isSlotValid(this.event.request, `activity`);
if (activity)
speechOutput += ` to go ${activity}`;
//say the results
this.response.speak(speechOutput);
this.emit(`:responseReady`);
},
'AMAZON.HelpIntent': function () {
this.attributes.speechOutput = this.t('HELP_MESSAGE');
this.attributes.repromptSpeech = this.t('HELP_REPROMPT');
this.response.speak(this.attributes.speechOutput).listen(this.attributes.repromptSpeech);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.emit('SessionEndedRequest');
},
'AMAZON.StopIntent': function () {
this.emit('SessionEndedRequest');
},
'AMAZON.RepeatIntent': function () {
this.response.speak(this.attributes.speechOutput).listen(this.attributes.repromptSpeech);
this.emit(':responseReady');
},
'SessionEndedRequest': function () {
this.attributes.speechOutput = this.t('STOP_MESSAGE');
this.response.speak(this.attributes.speechOutput);
this.emit(':responseReady');
},
'Unhandled': function () {
this.attributes.speechOutput = this.t('HELP_MESSAGE');
this.attributes.repromptSpeech = this.t('HELP_REPROMPT');
this.response.speak(this.attributes.speechOutput).listen(this.attributes.repromptSpeech);
this.emit(':responseReady');
},
};
exports.handler = (event, context) => {
let alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
// END of Intent Handlers {} ========================================================================================
// 3. Helper Function =================================================================================================
function delegateSlotCollection(){
console.log(`in delegateSlotCollection`);
console.log(`current dialogState: ${this.event.request.dialogState}`);
if (this.event.request.dialogState === `STARTED`) {
console.log(`in Beginning`);
let updatedIntent = this.event.request.intent;
//optionally pre-fill slots: update the intent object with slot values for which
//you have defaults, then return Dialog.Delegate with this updated intent
// in the updatedIntent property
this.emit(`:delegate`, updatedIntent);
} else if (this.event.request.dialogState !== `COMPLETED`) {
console.log(`in not completed`);
// return a Dialog.Delegate directive with no updatedIntent property.
this.emit(`:delegate`);
} else {
console.log(`in completed`);
console.log(`returning: `+ JSON.stringify(this.event.request.intent));
// Dialog is now complete and all required slots should be filled,
// so call your normal intent handler.
return this.event.request.intent;
}
}
function randomPhrase(array) {
// the argument is an array [] of words or phrases
let i = 0;
i = Math.floor(Math.random() * array.length);
return(array[i]);
}
function isSlotValid(request, slotName){
let slot = request.intent.slots[slotName];
//console.log(`request = `+JSON.stringify(request)); //uncomment if you want to see the request
let slotValue;
//if we have a slot, get the text and store it into speechOutput
if (slot && slot.value) {
//we have a value in the slot
slotValue = slot.value.toLowerCase();
return slotValue;
} else {
//we didn't get a value in the slot.
return false;
}
}