最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

处理Alexa中的Null

运维笔记admin21浏览0评论

处理Alexa中的Null

处理Alexa中的Null

我为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"

换句话说,我不处理slot为null的情况。我尝试了几个不同的东西来解决我的代码中的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函数发送请求。看起来像这样。

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

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

所以要测试一下。你只需要放一个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'*
}

我希望这对您的认证有所帮助并祝您好运。

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论