Alexa的技能回应很抱歉,我无法按您的要求去做请重试

问题描述

const FactIntentHandler = {
        canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return (request.type === 'IntentRequest' && request.intent.name === 'GetFactIntent');
        //&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetFactIntent';
},handle(handlerInput) {
    var newFact = pitFile.facts[Math.floor(Math.random() * pitFile.fact.length)];//search for fact to return in random order 000561
    var factResult = newFact.text; // store fact 000561
    //speakoutput is a var and not a const because we want it to change 000561
    var speakOutput = "Here's why we love pits:" + factResult;

    return handlerInput.responseBuilder
        .speak(speakOutput)
        //.reprompt(speakOutput)
        .getResponse();
  }
};

这是我的代码,我正在使用hello world模板。我编辑了内置的helloworld意图,但是当我调用getfactintent时会收到错误消息。

解决方法

您是怎么问的?是真实的还是通过技能控制台中的“测试”标签?

如果是真实的:请尝试在技能控制台中执行相同操作并测试您的技能。您将在右侧的JSON响应中看到响应,并且可能还会有更详细的错误说明。

,

如果这是Alexa托管的技能,请尝试代码面板左下方的CloudWatch链接。日志中应该包含一条错误消息。

当您抓住随机事实时,可以使用数组“ pitFile.fact”,但是在随机数生成中获得“ pitFile.facts”的长度。有人会认为这些应该是相同的。

由于它们不是,所以您可能会收到一个错误,提示它“无法读取未定义的属性长度”或pitFile.fact不是数组。这将显示在CloudWatch日志中。

,

我在第8行的代码中发现了错误 var newFact = pitFile.facts [Math.floor(Math.random()* pitFile.fact.length)]; //搜索事实以随机顺序返回000561

“ pitFile.facts.length”实际上应该是“ pitFile.facts.length”