gpt4 book ai didi

javascript - 在 Alexa 中处理 Null

转载 作者:太空宇宙 更新时间:2023-11-04 01:55:09 24 4
gpt4 key购买 nike

我提交了 Alexa 的技能,但我从 Amazon 团队收到了以下错误:

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));

最佳答案

首先要做的事情。如果您尚未记录传入的请求,则应该这样做。它包括对请求有值(value)的信息(即 intent 、槽、ID...)。 Here您可以看到不同请求类型的结构。

好的,回到您的用户场景,用户将插槽留空。换句话说,Alexa 向您的 lambda 函数发送一个带有空槽的请求。看起来像这样。

{
"type": "IntentRequest",
"intent": {
"name": "StateIntent",
"confirmationStatus": "NONE",
"slots": {
"State": {
"name": "State",
"confirmationStatus": "NONE"
}
}
}
}

当 Alexa 发送带有空槽的请求时,它不会在您的“状态”对象中包含成员。

所以要对此进行测试。您只需添加一个 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'*
}

希望这对您有所帮助,并祝您获得认证好运。

关于javascript - 在 Alexa 中处理 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48250816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com