在 Alexa 中处理 Null
Handling Null in Alexa
我为 Alexa 提交了一项技能,但我从亚马逊团队收到了以下错误:
Issue: [StateIntent] Intent, [State] slot
Steps To Reproduce:
User: "Alexa open states symbols"
Skill: "Welcome to state symbols. Give me the name of a state and I will give you symbols used by the state. You can also say random before the state to get a random symbol or ask for specific information for a symbol for a state. I have information about state dog, state flower, state motto, state song, state tree, state bird and state mineral"
User: "tell me about {}"
Skill: "There was a problem with the requested skill's response"
换句话说,我不处理插槽为空的情况。我尝试了几种不同的方法来解决代码中的 null 但所有方法都返回相同的错误 我该如何解决这个问题?这是代码的示例部分。
function handleStateResponse(intent, session, callback){
var state = intent.slots.State.value.toLowerCase( );
if (!states[state]){
var speechOutput= `I couldn't find that state would you like to ask about another state?`;
var repromptText = `Please try again`;
var header =`not found`;
}else{
var state_dog = states[state].state_dog;
speechOutput = `${capitalizeFirst(state)}'s state dog is the ${state_dog}`;
repromptText = `Would you like to learn about another state?`;
header =capitalizeFirst(state);
}
var shouldEndSession=false;
callback(session.attributes, buildSpeechletResponse(header, speechOutput, repromptText, shouldEndSession));
要事第一。如果您还没有记录传入的请求,您应该这样做。它包括对请求有价值的信息(即意图、槽、ID……)。 Here您可以看到不同请求类型的结构。
好的,回到您的用户场景,用户将插槽留空。换句话说,Alexa 向您的 lambda 函数发送了一个 request 和一个空槽。看起来像这样。
{
"type": "IntentRequest",
"intent": {
"name": "StateIntent",
"confirmationStatus": "NONE",
"slots": {
"State": {
"name": "State",
"confirmationStatus": "NONE"
}
}
}
}
当 Alexa 发送带有空槽的请求时,它不会在您的 'State'-object 中包含 value 成员。
所以要对此进行测试。您只需添加一个 if 子句。
if (intent.slots.State.value) {
// *Here you can check if the value is right or just continue with the state_dog part*
}
else {
// *Here you can prepare the callback params for 'empty slot'*
}
希望这对您有所帮助,祝您认证顺利。
我为 Alexa 提交了一项技能,但我从亚马逊团队收到了以下错误:
Issue: [StateIntent] Intent, [State] slot
Steps To Reproduce:
User: "Alexa open states symbols"
Skill: "Welcome to state symbols. Give me the name of a state and I will give you symbols used by the state. You can also say random before the state to get a random symbol or ask for specific information for a symbol for a state. I have information about state dog, state flower, state motto, state song, state tree, state bird and state mineral"
User: "tell me about {}"
Skill: "There was a problem with the requested skill's response"
换句话说,我不处理插槽为空的情况。我尝试了几种不同的方法来解决代码中的 null 但所有方法都返回相同的错误 我该如何解决这个问题?这是代码的示例部分。
function handleStateResponse(intent, session, callback){
var state = intent.slots.State.value.toLowerCase( );
if (!states[state]){
var speechOutput= `I couldn't find that state would you like to ask about another state?`;
var repromptText = `Please try again`;
var header =`not found`;
}else{
var state_dog = states[state].state_dog;
speechOutput = `${capitalizeFirst(state)}'s state dog is the ${state_dog}`;
repromptText = `Would you like to learn about another state?`;
header =capitalizeFirst(state);
}
var shouldEndSession=false;
callback(session.attributes, buildSpeechletResponse(header, speechOutput, repromptText, shouldEndSession));
要事第一。如果您还没有记录传入的请求,您应该这样做。它包括对请求有价值的信息(即意图、槽、ID……)。 Here您可以看到不同请求类型的结构。
好的,回到您的用户场景,用户将插槽留空。换句话说,Alexa 向您的 lambda 函数发送了一个 request 和一个空槽。看起来像这样。
{
"type": "IntentRequest",
"intent": {
"name": "StateIntent",
"confirmationStatus": "NONE",
"slots": {
"State": {
"name": "State",
"confirmationStatus": "NONE"
}
}
}
}
当 Alexa 发送带有空槽的请求时,它不会在您的 'State'-object 中包含 value 成员。
所以要对此进行测试。您只需添加一个 if 子句。
if (intent.slots.State.value) {
// *Here you can check if the value is right or just continue with the state_dog part*
}
else {
// *Here you can prepare the callback params for 'empty slot'*
}
希望这对您有所帮助,祝您认证顺利。