来自Alexa的CanfulFillIntentRequest没有响应

时间:2018-10-12 05:29:02

标签: node.js alexa alexa-skills-kit alexa-sdk-nodejs

const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'

  },
  handle(handlerInput) {
    if(handlerInput.requestEnvelope.request.intent.name === 'Myname'){
    return MynameHandler.handle(handlerInput);
      
  }

const MynameHandler = {
  
    handle(handlerInput) {
    
    const speechText = 'ALex';
    const repromtText = 'Please respond';
 return handlerInput.responseBuilder 
 .speak(speechText)
.withCanFulfillIntent( 
    {
        "canFulfill":"YES",
 
    })
.getResponse();

}

};

{
  "session":{
    "new": true,
    "sessionId":"SessionId.<My Session id>",
    "application":{
      "applicationId":"amzn1.ask.skill.<Application id>"
    },
    "attributes":{
      "key": "string value"
    },
    "user":{
      "userId":"amzn1.ask.account.<user id>
    }
  },
  "request":{
    "type":"CanFulfillIntentRequest",
    "requestId":"EdwRequestId.<request id>",
    "intent":{
      "name":"Myname"
    },
    "locale":"en-US",
    "timestamp":"2018-10-12T09:36:31Z"
  },
  "context":{
    "AudioPlayer":{
      "playerActivity":"IDLE"
    },
    "System":{
      "application":{
        "applicationId":"amzn1.ask.skill.<application id>"
      },
      "user":{
        "userId":"amzn1.ask.account.<user id>"
      },
      "device":{
        "supportedInterfaces":{

        }
      }
    }
  },
  "version":"1.0"
}

我已经实施CanfulFillIntentRequest很多天了,但是到目前为止还没有运气。我正在使用alexa-sdk-nodejs v2。我无法为CanfulFillIntent建立响应。我尝试按照这些文件中所述的确切方式实施它。 https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html
https://developer.amazon.com/docs/custom-skills/implement-canfulfillintentrequest-for-name-free-interaction.html

这是我的响应处理程序。

return handlerInput.responseBuilder
      .withCanFulfillIntent(
        {
          'canFulfill': 'MAYBE',
          'slots':{

              }
        })
        .getResponse();
    }

const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
    //return handlerInput.requestEnvelope.request.type === 'IntentRequest' || 'CanFulfillIntentRequest'
return handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'
     // && handlerInput.requestEnvelope.request.intent.name === 'Myname' || 'HotelIntent';
  },
  handle(handlerInput) {
    if(handlerInput.requestEnvelope.request.intent.name === 'Myname'){
    return MynameHandler.handle(handlerInput);
      
  }
  };

当我在手动JSON中运行JSON代码时,它没有响应CanfulFillIntent请求,而是被重定向到错误处理程序代码。

1 个答案:

答案 0 :(得分:0)

extension Foo { func someJob() { if let barSelf = self as? Bar { barSelf.name = "..." } } } 响应构建器帮助器方法仅在ASK SDK for Node.js (Public Beta)

中可用

通过

安装公开测试版
withCanFulfillIntent()

或在package.json中使用它

npm install --save ask-sdk-model@beta
npm install --save ask-sdk-core@beta

我尝试使用Beta测试您的代码并获得了预期的结果:

"dependencies": {
    "ask-sdk-core": "^2.1.0-beta.1",
    "ask-sdk-model": "^1.4.0-beta.1"
  }