Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 会话技巧错误_Amazon Web Services_Aws Lambda_Alexa Skills Kit_Alexa Slot - Fatal编程技术网

Amazon web services 会话技巧错误

Amazon web services 会话技巧错误,amazon-web-services,aws-lambda,alexa-skills-kit,alexa-slot,Amazon Web Services,Aws Lambda,Alexa Skills Kit,Alexa Slot,我在Alexa中创造了一项技能,可以做到以下几点 用户:你好 Alexa你好请告诉我你的名字 用户:约翰 嗨,约翰,很高兴认识你。你多大了 用户:25 以下是我的意图 { "intents": [ { "intent": "StartTheFlow", "slots": [ { "name": "custName", "type": "list_of_userNames" },

我在Alexa中创造了一项技能,可以做到以下几点

  • 用户:你好
  • Alexa你好请告诉我你的名字
  • 用户:约翰
  • 嗨,约翰,很高兴认识你。你多大了
  • 用户:25
  • 以下是我的意图

    {
      "intents": [
        {
          "intent": "StartTheFlow",
          "slots": [
            {
              "name": "custName",
              "type": "list_of_userNames"
            },
            {
              "name": "age",
              "type": "AMAZON.NUMBER"
            }
          ]
        },
        {
          "intent": "AMAZON.HelpIntent"
        },{
          "intent": "Welcome"
        },
        {
          "intent": "AMAZON.StopIntent"
        },
        {
          "intent": "AMAZON.CancelIntent"
        }
      ]
    }
    
    下面是我的发言

    StartTheFlow Hi
    StartTheFlow {custName}
    StartTheFlow {age}
    
    下面是我的内容

    我试着如下处理这个问题

    private SpeechletResponse getTheFlow(Intent intent, Session session) {
    
            boolean isAskResponse = true;
            String responseText = "";
            String nameFromSession = (String) session.getAttribute("name");
            if (StringUtils.isNullOrEmpty(nameFromSession)) {
                responseText = "please give me your name";
                getTheNameText(intent, session);
            } else {
                System.out.println(session.getAttribute("nameFromSession"));
                responseText = "please give me your date of birth";
            }
    
            return getSpeechletResponse(responseText, "", isAskResponse);
    
        }
    
        private String getTheNameText(Intent intent, Session session) {
            String userNameFrmIntent = getNameFromSlot(intent).toString();
            session.setAttribute("nameFromSession", userNameFrmIntent);
            return getNameFromSlot(intent).toString();
    
        }
    
        private String getNameFromSlot(Intent intent) {
            Slot userName = intent.getSlot(Slot_Name);
            return userName.getValue();
        }
    
    另外,我在顶部定义了一个槽,如下所示

    private static final String Slot_Name = "custName";
    
    {
      "session": {
        "sessionId": "SessionId.a2740ca4-73ff-4a15-856d-6461b3c7b2e1",
        "application": {
          "applicationId": "amzn1.ask.skill.e3dfb30e-0089-423c-a325-30ad28dd2e2b"
        },
        "attributes": {},
        "user": {
          "userId": "amzn1.ask.account.AEQYTT5HFHEGGDSUCT3NW45HKR7O3FBL5YCBSZIS7P5LNP5BXFEMUR7AUYOZVKC2FT5V6RKJC7RNA5VMZVREBAXAQP3NFNTQSFSSKSEXIYT4FQYMS5JCI2CCAOPUF4FN4C6DHEU6ONNY3D6GN5AWK75KOQNJH2IWROIIXTPNXSNI6FLQYRBBMP7TRSOWVNCY73WJUT2VLHDACWA"
        },
        "new": true
      },
      "request": {
        "type": "IntentRequest",
        "requestId": "EdwRequestId.cf686fc0-cbfd-4496-bb09-c41714563507",
        "locale": "en-US",
        "timestamp": "2017-02-15T20:12:44Z",
        "intent": {
          "name": "StartTheFlow",
          "slots": {
            "custName": {
              "name": "custName",
              "value": "hi"
            }
          }
        }
      },
      "version": "1.0"
    }
    
    但在这里,当我键入
    Hi
    时,它没有询问我的名字,而是在日志中给了我一个错误,它显示了Java NullPointer异常。我键入
    Hi
    时得到的响应如下所示

    private static final String Slot_Name = "custName";
    
    {
      "session": {
        "sessionId": "SessionId.a2740ca4-73ff-4a15-856d-6461b3c7b2e1",
        "application": {
          "applicationId": "amzn1.ask.skill.e3dfb30e-0089-423c-a325-30ad28dd2e2b"
        },
        "attributes": {},
        "user": {
          "userId": "amzn1.ask.account.AEQYTT5HFHEGGDSUCT3NW45HKR7O3FBL5YCBSZIS7P5LNP5BXFEMUR7AUYOZVKC2FT5V6RKJC7RNA5VMZVREBAXAQP3NFNTQSFSSKSEXIYT4FQYMS5JCI2CCAOPUF4FN4C6DHEU6ONNY3D6GN5AWK75KOQNJH2IWROIIXTPNXSNI6FLQYRBBMP7TRSOWVNCY73WJUT2VLHDACWA"
        },
        "new": true
      },
      "request": {
        "type": "IntentRequest",
        "requestId": "EdwRequestId.cf686fc0-cbfd-4496-bb09-c41714563507",
        "locale": "en-US",
        "timestamp": "2017-02-15T20:12:44Z",
        "intent": {
          "name": "StartTheFlow",
          "slots": {
            "custName": {
              "name": "custName",
              "value": "hi"
            }
          }
        }
      },
      "version": "1.0"
    }
    
    有人能告诉我哪里出了问题,我如何解决这个问题,我有很多问题需要联系,比如25个,有人能告诉我是否有更好的方法在java中实现这一点吗


    谢谢

    我建议为用户所说的每件事创建一个单独的意图。例如,HelloIntent、NameIntent和AgeIntent

    然后确保将这些信息转发给会话中的所有后续意图。因此,每个意图可以在开始时使用一个公共函数从会话中读取每个字符串(如果存在),向其中添加新的插槽数据,然后在完成之前将所有字符串写回响应会话

    由于您将有单独的意图,用户可能会说它们不符合顺序,因此您可能需要检查是否输入了所有需要的字符串,或者提示用户输入任何缺少的字符串

    在会话中保存数据的问题是,在用户下次启动技能时,数据将消失。为了解决这个问题,您可以使用一个数据库来保存用户数据,并将其保存到userId中。关于如何做到这一点,有很多例子。请注意,有些数据库基本上是免费的,但其他数据库将根据每月使用的次数向您收费